Add basic sorting to management interface

This commit is contained in:
2022-06-07 16:25:45 +09:30
parent 42fd1973b8
commit 6cf327226d
4 changed files with 21 additions and 7 deletions

View File

@@ -13,8 +13,9 @@
</div>
</div>
{{ template "tags_widget.html" . }}
{{ template "manage_results.html" . }}
</form>
{{ template "manage_results.html" . }}
</div>
</div>

View File

@@ -2,10 +2,10 @@
<table id="manage-results">
<tr>
<th>&nbsp;</th>
<th>title/url</th>
<th hx-post="/manage/results?sort=title" hx-target="#manage-results">title/url</th>
<th>tags</th>
<th class="show-for-large">created</th>
<th class="show-for-large">scraped</th>
<th hx-post="/manage/results?sort=created" hx-target="#manage-results" class="show-for-large">created</th>
<th hx-post="/manage/results?sort=scraped" hx-target="#manage-results" class="show-for-large">scraped</th>
</tr>
{{ range .bookmarks }}
<tr>

View File

@@ -92,14 +92,14 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
r.POST("/manage/results", func(c *gin.Context) {
query := c.PostForm("query")
tags := []string{}
sort := c.Query("sort")
if c.PostForm("tags_hidden") != "" {
tags = strings.Split(c.PostForm("tags_hidden"), "|")
}
allBookmarks, _ := bmm.Search(db.SearchOptions{Query: query, Tags: tags})
allBookmarks, _ := bmm.Search(db.SearchOptions{Query: query, Tags: tags, Sort: sort})
meta := gin.H{"config": config, "bookmarks": allBookmarks}
log.Printf("query is %s, tags %v", query, tags)
c.HTML(http.StatusOK,
"manage_results.html", meta,
)