From ca271e2ac6c3fa836e74a202653a458522d723c1 Mon Sep 17 00:00:00 2001 From: kilo Date: Mon, 6 Nov 2017 09:17:14 +0100 Subject: [PATCH] Username search for admin comment list, inputs for userid & username search in said comment list (#1713) * Update comments.go * Update commentlist.jet.html * Update comments.go When you search a username and you have a userid in the url, the conditions string doesn't have "AND" in it. I made the username search a priority and if there is not username provided, it falls back to userid in url. --- controllers/moderator/comments.go | 21 +++++++++++++++++---- templates/admin/commentlist.jet.html | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/controllers/moderator/comments.go b/controllers/moderator/comments.go index 8208182c..26952c8e 100644 --- a/controllers/moderator/comments.go +++ b/controllers/moderator/comments.go @@ -21,6 +21,7 @@ func CommentsListPanel(c *gin.Context) { pagenum := 1 offset := 100 userid := c.Query("userid") + username := c.Query("user") var err error messages := msg.GetMessages(c) deleted := c.Request.URL.Query()["deleted"] @@ -36,14 +37,26 @@ func CommentsListPanel(c *gin.Context) { } var conditions string var values []interface{} - if userid != "" { - conditions = "user_id = ?" - values = append(values, userid) + searchForm := templates.NewSearchForm(c) + // if there is a username in url + if username != "" { + conditions = "user = ?" + values = append(values, username) + searchForm.UserName = username + // else we look if there is a userid + } else if userid != "" { + id, err := strconv.Atoi(userid) + if err == nil { + conditions = "user_id = ?" + values = append(values, id) + searchForm.UserID = uint32(id) + } } + comments, nbComments := comments.FindAll(offset, (pagenum-1)*offset, conditions, values...) nav := templates.Navigation{nbComments, offset, pagenum, "mod/comments/p"} - templates.ModelList(c, "admin/commentlist.jet.html", comments, nav, templates.NewSearchForm(c)) + templates.ModelList(c, "admin/commentlist.jet.html", comments, nav, searchForm) } // CommentDeleteModPanel : Controller for deleting a comment diff --git a/templates/admin/commentlist.jet.html b/templates/admin/commentlist.jet.html index 2b195b1f..11da0aff 100644 --- a/templates/admin/commentlist.jet.html +++ b/templates/admin/commentlist.jet.html @@ -2,7 +2,22 @@ {{block title()}}{{ T("comments_list") }}{{end}} {{block content_body()}}
-

{{ T("comments_list") }}

+

{{ T("comments_list") }}

+ +
+ + + + + + + +
{{T("user_id")}} +
{{T("username")}} +
+ +
+