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 {
|
func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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"]
|
idStr := mux.Vars(r)["id"]
|
||||||
id, _ := strconv.Atoi(idStr)
|
id, _ := strconv.Atoi(idStr)
|
||||||
typeFilter := r.URL.Query().Get("type")
|
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
|
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 != "" {
|
if typeFilter != "" {
|
||||||
query = query.Where("type = ?", typeFilter)
|
query = query.Where("type = ?", typeFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Order("created_at desc").Find(&convs)
|
query.Order("created_at desc").Find(&convs)
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
@ -225,6 +265,8 @@ func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func AdminConversationThread(db *gorm.DB) http.HandlerFunc {
|
func AdminConversationThread(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
idStr := mux.Vars(r)["id"]
|
idStr := mux.Vars(r)["id"]
|
||||||
|
|||||||
@ -1,41 +1,69 @@
|
|||||||
{{ define "adminconversations.pages.tmpl" }}
|
{{ define "adminconversations.pages.tmpl" }}
|
||||||
{{ template "head" . }}
|
{{ template "head" . }}
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
{{ template "sidebar" . }}
|
{{ template "sidebar" . }}
|
||||||
|
|
||||||
<div class="column is-10">
|
<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">
|
<!-- Filtres JS -->
|
||||||
<input type="text" class="input is-small" placeholder="📅 Filtrer par date" onkeyup="filterTable(0, this.value)">
|
<div class="box mb-4">
|
||||||
<input type="text" class="input is-small" placeholder="➡️ Direction" onkeyup="filterTable(1, this.value)">
|
<h2 class="subtitle is-6">🔍 Filtres personnalisés</h2>
|
||||||
<input type="text" class="input is-small" placeholder="📨 Expéditeur" onkeyup="filterTable(2, this.value)">
|
<div class="columns is-multiline">
|
||||||
<input type="text" class="input is-small" placeholder="📦 Type" onkeyup="filterTable(3, this.value)">
|
<div class="column is-2">
|
||||||
<input type="text" class="input is-small" placeholder="💬 Contenu" onkeyup="filterTable(4, this.value)">
|
<input type="text" class="input is-small" placeholder="📅 Date"
|
||||||
<input type="text" class="input is-small" placeholder="✅ Statut" onkeyup="filterTable(5, this.value)">
|
onkeyup="filterTable(0, this.value)">
|
||||||
</div>
|
</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">
|
<!-- Tableau HTMX -->
|
||||||
<thead>
|
<table class="table is-fullwidth is-striped is-hoverable" id="conversationTable">
|
||||||
<tr>
|
<thead>
|
||||||
<th>Date</th>
|
<tr>
|
||||||
<th>Direction</th>
|
<th>Date</th>
|
||||||
<th>Expéditeur</th>
|
<th>Direction</th>
|
||||||
<th>Type</th>
|
<th>Expéditeur</th>
|
||||||
<th>Contenu</th>
|
<th>Type</th>
|
||||||
<th>Statut</th>
|
<th>Contenu</th>
|
||||||
</tr>
|
<th>Statut</th>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody id="conversationRows"
|
</thead>
|
||||||
hx-get="/api/user/{{ .UserID }}/conversations"
|
<tbody id="conversationRows"
|
||||||
hx-trigger="load"
|
hx-get="/api/user/{{ .UserID }}/conversations"
|
||||||
hx-target="this"
|
hx-trigger="load"
|
||||||
hx-swap="innerHTML">
|
hx-target="this"
|
||||||
</tbody>
|
hx-swap="innerHTML">
|
||||||
</table>
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<h3>Conversation complète</h3>
|
|
||||||
<div id="threadViewer" class="mt-3"></div>
|
<h2 class="title is-5 mt-5">🧵 Conversation complète</h2>
|
||||||
|
<div id="threadViewer" class="box mt-3"></div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -54,4 +82,5 @@ function filterTable(colIndex, filterValue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user