From 9e779891fa91f44a9734b79ccb4f6aef48a0de3f Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Thu, 18 Sep 2025 21:00:28 +0100 Subject: Add filters on html page --- api/handlers/html.go | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'api/handlers') diff --git a/api/handlers/html.go b/api/handlers/html.go index 88407bf..57adb12 100644 --- a/api/handlers/html.go +++ b/api/handlers/html.go @@ -5,6 +5,7 @@ import ( "git.leonardobishop.net/stash/pkg/entries" "git.leonardobishop.net/stash/pkg/html" + "git.leonardobishop.net/stash/pkg/kinds" ) const style = `` -func GetEntriesHtml(entriesService entries.Service, htmlService html.Service) http.HandlerFunc { +func GetEntriesHtml(entriesService entries.Service, kindsService kinds.Service, htmlService html.Service) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - entries, err := entriesService.GetEntries() + var entries []entries.EntryRow + kinds, err := kindsService.GetKinds() + + kind := r.URL.Query().Get("kind") + if kind != "" { + entries, err = entriesService.GetEntriesByKind(kind) + } else { + entries, err = entriesService.GetEntries() + } if err != nil { w.WriteHeader(http.StatusInternalServerError) return } - html, err := htmlService.GenerateHtml(entries) + var html string + page, err := htmlService.GenerateHtml(entries) if err != nil { w.WriteHeader(http.StatusInternalServerError) return } if r.URL.Query().Get("css") == "no" { + html = page goto send } html = ` -stash +Stash ` + style + ` -` + html + ` -` +` + + // gross + html += "

Show: " + if kind == "" { + html += `` + } + html += `all ` + if kind == "" { + html += `` + } + for _, k := range kinds { + if kind == k.Name { + html += `` + } + html += `` + k.Emoji + " " + k.Name + " " + if kind == k.Name { + html += `` + } + } + html += "

" + page + "" send: w.Header().Set("Content-Type", "text/html;charset=UTF-8") -- cgit v1.2.3-70-g09d2