taggart

Simple golang tagging filesystem webapp
Log | Files | Refs

commit ff6671be2053de92d58339a9773b8b203ead82fa
parent 235fb84d7d52d2f69336716f9de0ee8833091ace
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Mon, 22 Sep 2025 19:07:08 +0100

Add unassigned value for files with no tag

Diffstat:
Mmain.go | 34++++++++++++++++++++++++----------
Mtemplates/search.html | 2+-
Mtemplates/tags.html | 1+
3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/main.go b/main.go @@ -762,15 +762,29 @@ func tagFilterHandler(w http.ResponseWriter, r *http.Request) { query := `SELECT f.id, f.filename, f.path FROM files f WHERE 1=1` args := []interface{}{} for _, f := range filters { - query += ` - AND EXISTS ( - SELECT 1 - FROM file_tags ft - JOIN tags t ON ft.tag_id = t.id - JOIN categories c ON c.id = t.category_id - WHERE ft.file_id = f.id AND c.name = ? AND t.value = ? - )` - args = append(args, f.Category, f.Value) + if f.Value == "unassigned" { + // Files without any tag in this category + query += ` + AND NOT EXISTS ( + SELECT 1 + FROM file_tags ft + JOIN tags t ON ft.tag_id = t.id + JOIN categories c ON c.id = t.category_id + WHERE ft.file_id = f.id AND c.name = ? + )` + args = append(args, f.Category) + } else { + // Files with this specific tag value + query += ` + AND EXISTS ( + SELECT 1 + FROM file_tags ft + JOIN tags t ON ft.tag_id = t.id + JOIN categories c ON c.id = t.category_id + WHERE ft.file_id = f.id AND c.name = ? AND t.value = ? + )` + args = append(args, f.Category, f.Value) + } } rows, _ := db.Query(query, args...) @@ -780,10 +794,10 @@ func tagFilterHandler(w http.ResponseWriter, r *http.Request) { for rows.Next() { var f File rows.Scan(&f.ID, &f.Filename, &f.Path) + f.EscapedFilename = url.PathEscape(f.Filename) files = append(files, f) } - // Create title from filters var titleParts []string for _, f := range filters { titleParts = append(titleParts, fmt.Sprintf("%s: %s", f.Category, f.Value)) diff --git a/templates/search.html b/templates/search.html @@ -8,7 +8,7 @@ <div class="file-item"> <a href="/file/{{.ID}}">{{.Filename}}</a> {{if hasAnySuffix .Filename ".jpg" ".jpeg" ".png" ".gif" ".webp"}} - <br><img src="/uploads/{{.Filename}}" style="max-width: 100%; height: auto;" /> + <br><img src="/uploads/{{.EscapedFilename}}" style="max-width: 100%; height: auto;" /> {{end}} </div> {{end}} diff --git a/templates/tags.html b/templates/tags.html @@ -9,6 +9,7 @@ {{range $tags}} <li><a href="/tag/{{$cat}}/{{.Value}}">{{.Value}} ({{.Count}})</a></li> {{end}} + <li><a href="/tag/{{$cat}}/unassigned">Unassigned</a></li> </ul> </li> {{end}}