Export - GET /l/<list>/export?format=csv|txt downloads a list's titles in rank order, one per line, with no header or other fields (CSV gets a UTF-8 BOM for Excel) - Export menu in the list editor and, for the owner, on the public list page; hidden lists stay owner-only Custom lists - New "Custom" category for anything not built in (sports teams, drinks…): owner-named, slug from the title, entries added by hand or from an unfiltered Wikipedia search - Per-list artwork shape (square or tall), stored in a new lists.art column (migration 2) - Art can be uploaded while adding an entry, not only after Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"html/template"
|
|
"net/http"
|
|
|
|
"github.com/cdnutter/topdeck/internal/store"
|
|
)
|
|
|
|
// adminPage carries a JSON blob the page script boots from.
|
|
type adminPage struct {
|
|
Boot template.JS
|
|
List *store.List
|
|
}
|
|
|
|
func bootJSON(v any) template.JS {
|
|
b, _ := json.Marshal(v)
|
|
return template.JS(b)
|
|
}
|
|
|
|
type sizeLimits struct {
|
|
Max int `json:"max"`
|
|
Recommended int `json:"recommended"`
|
|
Warn int `json:"warn"`
|
|
}
|
|
|
|
var limits = sizeLimits{store.MaxListSize, store.RecommendedListSize, store.SoftListSizeWarning}
|
|
|
|
func (s *Server) handleAdminLists(w http.ResponseWriter, r *http.Request) {
|
|
lists, err := s.store.Lists(r.Context(), true)
|
|
if err != nil {
|
|
s.serverError(w, r, err)
|
|
return
|
|
}
|
|
if lists == nil {
|
|
lists = []store.List{}
|
|
}
|
|
covers, err := s.store.ListCovers(r.Context(), 3)
|
|
if err != nil {
|
|
s.serverError(w, r, err)
|
|
return
|
|
}
|
|
s.render(w, r, http.StatusOK, "admin_lists", "Your lists", adminPage{Boot: bootJSON(map[string]any{
|
|
"lists": lists,
|
|
"covers": covers,
|
|
"categories": store.Categories,
|
|
"limits": limits,
|
|
})})
|
|
}
|
|
|
|
func (s *Server) handleAdminList(w http.ResponseWriter, r *http.Request) {
|
|
id, err := pathID(r)
|
|
if err != nil {
|
|
s.notFound(w, r)
|
|
return
|
|
}
|
|
l, err := s.store.ListByID(r.Context(), id)
|
|
if err != nil {
|
|
s.notFound(w, r)
|
|
return
|
|
}
|
|
cat := listCategory(l)
|
|
provider := ""
|
|
if p, err := s.providers.For(r.Context(), l.Category); err == nil {
|
|
provider = p.Label()
|
|
}
|
|
s.render(w, r, http.StatusOK, "admin_list", l.Title, adminPage{List: &l, Boot: bootJSON(map[string]any{
|
|
"list": l,
|
|
"category": cat,
|
|
"categories": store.Categories,
|
|
"limits": limits,
|
|
"provider": provider,
|
|
"productions": store.TheaterProductions,
|
|
"pageSize": listPageSize,
|
|
})})
|
|
}
|
|
|
|
func (s *Server) handleAdminSettings(w http.ResponseWriter, r *http.Request) {
|
|
s.render(w, r, http.StatusOK, "admin_settings", "Settings", adminPage{Boot: bootJSON(map[string]any{
|
|
"categories": store.Categories,
|
|
})})
|
|
}
|