JJJJJ
This commit is contained in:
parent
5410413ffb
commit
c3ae311666
@ -206,15 +206,55 @@ func AdminConversationPage(db *gorm.DB) http.HandlerFunc {
|
||||
|
||||
func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// 1. Récupérer SSOID depuis le contexte
|
||||
val := r.Context().Value("ssoid")
|
||||
ssoid, ok := val.(string)
|
||||
if !ok || ssoid == "" {
|
||||
http.Error(w, "Non authentifié", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// 2. Trouver l'utilisateur
|
||||
var currentUser models.User
|
||||
if err := db.Where("sso_id = ?", ssoid).First(¤tUser).Error; err != nil {
|
||||
http.Error(w, "Utilisateur introuvable", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// 3. Récupération des filtres
|
||||
idStr := mux.Vars(r)["id"]
|
||||
id, _ := strconv.Atoi(idStr)
|
||||
typeFilter := r.URL.Query().Get("type")
|
||||
dateFilter := r.URL.Query().Get("filter")
|
||||
|
||||
var fromDate time.Time
|
||||
now := time.Now()
|
||||
switch dateFilter {
|
||||
case "today":
|
||||
fromDate = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
case "week":
|
||||
fromDate = now.AddDate(0, 0, -7)
|
||||
default:
|
||||
fromDate = time.Time{}
|
||||
}
|
||||
|
||||
var convs []models.Conversation
|
||||
query := db.Where("user_id = ?", id)
|
||||
query := db.Model(&models.Conversation{})
|
||||
|
||||
// 4. ADMIN → tout ou par utilisateur ciblé
|
||||
if currentUser.Role != models.ROLE_ADMIN {
|
||||
query = query.Where("user_id = ?", currentUser.ID)
|
||||
} else if id > 0 {
|
||||
query = query.Where("user_id = ?", id)
|
||||
}
|
||||
|
||||
if !fromDate.IsZero() {
|
||||
query = query.Where("created_at >= ?", fromDate)
|
||||
}
|
||||
if typeFilter != "" {
|
||||
query = query.Where("type = ?", typeFilter)
|
||||
}
|
||||
|
||||
query.Order("created_at desc").Find(&convs)
|
||||
|
||||
data := map[string]interface{}{
|
||||
@ -225,6 +265,8 @@ func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func AdminConversationThread(db *gorm.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
idStr := mux.Vars(r)["id"]
|
||||
|
||||
@ -1,41 +1,69 @@
|
||||
{{ define "adminconversations.pages.tmpl" }}
|
||||
{{ template "head" . }}
|
||||
|
||||
<div class="columns">
|
||||
{{ template "sidebar" . }}
|
||||
|
||||
<div class="column is-10">
|
||||
<h2>Historique des messages de l'utilisateur #{{ .UserID }}</h2>
|
||||
<section class="section">
|
||||
<h1 class="title is-4">💬 Historique des messages — Utilisateur #{{ .UserID }}</h1>
|
||||
|
||||
<div class="filters mb-3">
|
||||
<input type="text" class="input is-small" placeholder="📅 Filtrer par date" onkeyup="filterTable(0, this.value)">
|
||||
<input type="text" class="input is-small" placeholder="➡️ Direction" onkeyup="filterTable(1, this.value)">
|
||||
<input type="text" class="input is-small" placeholder="📨 Expéditeur" onkeyup="filterTable(2, this.value)">
|
||||
<input type="text" class="input is-small" placeholder="📦 Type" onkeyup="filterTable(3, this.value)">
|
||||
<input type="text" class="input is-small" placeholder="💬 Contenu" onkeyup="filterTable(4, this.value)">
|
||||
<input type="text" class="input is-small" placeholder="✅ Statut" onkeyup="filterTable(5, this.value)">
|
||||
</div>
|
||||
<!-- Filtres JS -->
|
||||
<div class="box mb-4">
|
||||
<h2 class="subtitle is-6">🔍 Filtres personnalisés</h2>
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-2">
|
||||
<input type="text" class="input is-small" placeholder="📅 Date"
|
||||
onkeyup="filterTable(0, this.value)">
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<input type="text" class="input is-small" placeholder="➡️ Direction"
|
||||
onkeyup="filterTable(1, this.value)">
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<input type="text" class="input is-small" placeholder="📨 Expéditeur"
|
||||
onkeyup="filterTable(2, this.value)">
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<input type="text" class="input is-small" placeholder="📦 Type"
|
||||
onkeyup="filterTable(3, this.value)">
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<input type="text" class="input is-small" placeholder="💬 Contenu"
|
||||
onkeyup="filterTable(4, this.value)">
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<input type="text" class="input is-small" placeholder="✅ Statut"
|
||||
onkeyup="filterTable(5, this.value)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="table is-fullwidth is-striped is-hoverable" id="conversationTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Direction</th>
|
||||
<th>Expéditeur</th>
|
||||
<th>Type</th>
|
||||
<th>Contenu</th>
|
||||
<th>Statut</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="conversationRows"
|
||||
hx-get="/api/user/{{ .UserID }}/conversations"
|
||||
hx-trigger="load"
|
||||
hx-target="this"
|
||||
hx-swap="innerHTML">
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Tableau HTMX -->
|
||||
<table class="table is-fullwidth is-striped is-hoverable" id="conversationTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Direction</th>
|
||||
<th>Expéditeur</th>
|
||||
<th>Type</th>
|
||||
<th>Contenu</th>
|
||||
<th>Statut</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="conversationRows"
|
||||
hx-get="/api/user/{{ .UserID }}/conversations"
|
||||
hx-trigger="load"
|
||||
hx-target="this"
|
||||
hx-swap="innerHTML">
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr>
|
||||
<h3>Conversation complète</h3>
|
||||
<div id="threadViewer" class="mt-3"></div>
|
||||
<hr>
|
||||
|
||||
<h2 class="title is-5 mt-5">🧵 Conversation complète</h2>
|
||||
<div id="threadViewer" class="box mt-3"></div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -54,4 +82,5 @@ function filterTable(colIndex, filterValue) {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ end }}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user