add configuration: top nav order and settings

This commit is contained in:
Anya Tokugawa committed 2026-05-31 21:10:01 +09:00
1 parent d300354725
commit 12decb7862
9 files changed
+386 -71

No files matched your search

+97 -18
View File
@@ -1,7 +1,9 @@
package server
import (
"encoding/json"
"net/http"
"strings"
)
func (s *Server) handleConfig(
@@ -11,22 +13,102 @@ func (s *Server) handleConfig(
if r.Method == http.MethodPost {
homePath := r.FormValue("home_path")
err := s.store.SetConfig(
"home_path",
homePath,
)
err := r.ParseForm()
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
section :=
r.FormValue("section")
switch section {
case "home":
err = s.store.SetConfig(
"home_path",
r.FormValue("home_path"),
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
case "nav":
labels :=
r.Form["nav_label"]
hrefs :=
r.Form["nav_href"]
var items []NavItem
for i := range labels {
label :=
strings.TrimSpace(labels[i])
if label == "" {
continue
}
if i >= len(hrefs) {
continue
}
href :=
strings.TrimSpace(hrefs[i])
if href == "" {
continue
}
items = append(
items,
NavItem{
Label: label,
Href: href,
},
)
}
raw, err :=
json.Marshal(items)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = s.store.SetConfig(
"nav_items",
string(raw),
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
default:
http.Error(
w,
"unknown config section",
http.StatusBadRequest,
)
return
}
http.Redirect(
w,
r,
"/-/sys/config",
"/-/sys/config?panel="+section,
http.StatusFound,
)
@@ -34,22 +116,18 @@ func (s *Server) handleConfig(
}
homePath, err :=
s.store.GetConfig(
"home_path",
)
s.store.GetConfig("home_path")
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
recent, err :=
s.store.ListRecentObjects(
50,
)
s.store.ListRecentObjects(50)
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -57,8 +135,9 @@ func (s *Server) handleConfig(
w,
"config.gohtml",
map[string]any{
"HomePath": homePath,
"Objects": recent,
"HomePath": homePath,
"Objects": recent,
"NavItemsConfig": s.getNavItems(),
},
)
}