Attempt to implement checkbox shitter

This commit is contained in:
Maximilian Friedersdorff 2025-07-25 13:44:21 +01:00
parent 0f2400435f
commit 4aa09ce502
6 changed files with 143 additions and 13 deletions

View file

@ -5,6 +5,7 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
urls "forgejo.gwairfelin.com/max/gispatcho"
@ -19,13 +20,14 @@ func GetRoutes(prefix string) *http.ServeMux {
myurls = urls.URLs{
Prefix: prefix,
URLs: map[string]urls.URL{
"list": {Path: "/", Protocol: "GET", Handler: list},
"new": {Path: "/new", Protocol: "GET", Handler: new},
"view_": {Path: "/{note}", Protocol: "GET", Handler: view},
"view": {Path: "/{note}/", Protocol: "GET", Handler: view},
"delete": {Path: "/{note}/delete/", Protocol: "GET", Handler: delete},
"edit": {Path: "/{note}/edit/", Protocol: "GET", Handler: edit},
"save": {Path: "/{note}/edit/save/", Protocol: "POST", Handler: save},
"list": {Path: "/", Protocol: "GET", Handler: list},
"new": {Path: "/new", Protocol: "GET", Handler: new},
"view_": {Path: "/{note}", Protocol: "GET", Handler: view},
"view": {Path: "/{note}/", Protocol: "GET", Handler: view},
"delete": {Path: "/{note}/delete/", Protocol: "GET", Handler: delete},
"edit": {Path: "/{note}/edit/", Protocol: "GET", Handler: edit},
"save": {Path: "/{note}/edit/save/", Protocol: "POST", Handler: save},
"togglebox": {Path: "/{note}/togglebox/", Protocol: "POST", Handler: togglebox},
},
}
return myurls.GetRouter()
@ -109,9 +111,28 @@ func save(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": note.EncodedTitle()}), http.StatusFound)
}
type titleAndUrl struct {
func togglebox(w http.ResponseWriter, r *http.Request) {
title := r.PathValue("note")
nthBox, err := strconv.Atoi(r.FormValue("box"))
if err != nil {
log.Fatal("You fucked up boy")
return
}
note, err := notes.LoadNote(title)
if err != nil {
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": title}), http.StatusFound)
return
}
note.ToggleBox(nthBox)
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": note.EncodedTitle()}), http.StatusFound)
}
type titleAndURL struct {
Title string
Url string
URL string
}
func list(w http.ResponseWriter, r *http.Request) {
@ -122,7 +143,7 @@ func list(w http.ResponseWriter, r *http.Request) {
return
}
titlesAndUrls := make([]titleAndUrl, 0)
titlesAndUrls := make([]titleAndURL, 0)
for _, f := range files {
if !f.IsDir() {
@ -133,7 +154,7 @@ func list(w http.ResponseWriter, r *http.Request) {
titlesAndUrls = append(
titlesAndUrls,
titleAndUrl{Title: title, Url: myurls.Reverse("view", urls.Repl{"note": encodedTitle})},
titleAndURL{Title: title, URL: myurls.Reverse("view", urls.Repl{"note": encodedTitle})},
)
log.Print(titlesAndUrls)
}