diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-09-18 21:00:28 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-09-18 21:00:28 +0100 |
| commit | 9e779891fa91f44a9734b79ccb4f6aef48a0de3f (patch) | |
| tree | 7b60a2129966461ed56532768c847595fd371377 /api | |
| parent | 39a926cd521806aedc298ddd671d1a118794fcec (diff) | |
Add filters on html page
Diffstat (limited to 'api')
| -rw-r--r-- | api/handlers/html.go | 42 | ||||
| -rw-r--r-- | api/router.go | 4 |
2 files changed, 39 insertions, 7 deletions
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 = `<style> @@ -49,32 +50,61 @@ body { } </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 = `<!DOCTYPE html> <html> <head> -<title>stash</title> +<title>Stash</title> ` + style + ` </head> -<body>` + html + `</body> -</html>` +<body>` + + // gross + html += "<p>Show: " + if kind == "" { + html += `<b>` + } + html += `<a href="/html">all</a> ` + if kind == "" { + html += `</b>` + } + for _, k := range kinds { + if kind == k.Name { + html += `<b>` + } + html += `<a href="/html?kind=` + k.Name + `">` + k.Emoji + " " + k.Name + "</a> " + if kind == k.Name { + html += `</b>` + } + } + html += "</p>" + page + "</body></html>" send: w.Header().Set("Content-Type", "text/html;charset=UTF-8") diff --git a/api/router.go b/api/router.go index 89abbc0..94ec88d 100644 --- a/api/router.go +++ b/api/router.go @@ -8,10 +8,12 @@ import ( "git.leonardobishop.net/stash/internal/config" "git.leonardobishop.net/stash/pkg/entries" "git.leonardobishop.net/stash/pkg/html" + "git.leonardobishop.net/stash/pkg/kinds" ) type ApiServices struct { EntiresService entries.Service + KindsService kinds.Service HtmlService html.Service Config *config.Config @@ -28,7 +30,7 @@ func NewServer(api ApiServices) *http.ServeMux { mux.HandleFunc("DELETE /record", cors(auth(handlers.DeleteEntry(api.EntiresService)))) mux.HandleFunc("GET /entry", cors(auth(handlers.GetEntryURLs(api.EntiresService)))) mux.HandleFunc("POST /entry", cors(auth(handlers.GetEntry(api.EntiresService)))) - mux.HandleFunc("GET /html", handlers.GetEntriesHtml(api.EntiresService, api.HtmlService)) + mux.HandleFunc("GET /html", handlers.GetEntriesHtml(api.EntiresService, api.KindsService, api.HtmlService)) mux.HandleFunc("GET /", handlers.Pong()) return mux |
