templates, handlers, CSS, JS: special cakes UI, HTMX nav, dashboard overhaul

Special cakes UI: overlay drawer, basket integration, catalogue tag
filter, form parsing, JS save/edit/remove.
HTMX navigation: MainContent component, nav links with hx-get,
handlers return partial on HX-Request.
Dashboard: metrics grid, CakeBreakdown, OrderRow with status select,
CakeCounts/OrderCounts, torty filter, tort badge, results-pane.
Collapsible sidebar: toggle button, localStorage, CSS transitions.
Location field: dropdown replaced with pill toggle.
Inline style cleanup: moved to CSS classes (tag-grid, grow, icon.sm,
header-actions, toggle-group, success-icon, etc.).
Dead CSS removal: pagination, status-chip, badge-pill, login-page.
Helpers: exported CakeTitle/OrderTitle, added tagNames, tagIDsComma,
orderItemsDesc, specialCakeDetail, removed unused helpers.
This commit is contained in:
bronkuu 2026-06-15 18:50:21 +02:00
parent 17b92a706a
commit 5a5372b831
18 changed files with 1153 additions and 422 deletions

View file

@ -29,6 +29,22 @@ func (h *Server) postCake(r *http.Request) (templ.Component, int, error) {
if err != nil {
return nil, http.StatusBadRequest, err
}
for _, idStr := range r.Form["tag"] {
tagID, err := strconv.Atoi(idStr)
if err != nil {
continue
}
n.Tags = append(n.Tags, models.Tag{ID: tagID})
}
if newTag := strings.TrimSpace(r.FormValue("new_tag")); newTag != "" {
tagID, err := h.s.CreateTag(newTag)
if err != nil {
return nil, http.StatusInternalServerError, err
}
n.Tags = append(n.Tags, models.Tag{ID: tagID, Name: newTag})
}
n.ID, err = h.s.SaveCake(n)
return templates.Confirmation("Potwierdzone", n.ID), http.StatusAccepted, err
}
@ -67,6 +83,47 @@ func (h *Server) postOrder(r *http.Request) (templ.Component, int, error) {
n.Cakes = append(n.Cakes, e)
}
specialNames := r.Form["special_name[]"]
specialPrices := r.Form["special_price[]"]
specialSizes := r.Form["special_size[]"]
specialShapes := r.Form["special_shape[]"]
specialFlavours := r.Form["special_flavour[]"]
specialNotes := r.Form["special_notes[]"]
specialTags := r.Form["special_tags[]"]
specialNewTags := r.Form["special_new_tag[]"]
for i := range specialNames {
price, err := models.ParsePrice(specialPrices[i])
if err != nil {
continue
}
var tags []models.Tag
if i < len(specialTags) && specialTags[i] != "" {
for _, idStr := range strings.Split(specialTags[i], ",") {
id, err := strconv.Atoi(strings.TrimSpace(idStr))
if err == nil {
tags = append(tags, models.Tag{ID: id})
}
}
}
if newTag := strings.TrimSpace(safeStr(specialNewTags, i)); newTag != "" {
tagID, err := h.s.CreateTag(newTag)
if err == nil {
tags = append(tags, models.Tag{ID: tagID, Name: newTag})
}
}
n.SpecialCakes = append(n.SpecialCakes, models.SpecialCake{
Name: specialNames[i],
Price: price,
Size: safeStr(specialSizes, i),
Shape: safeStr(specialShapes, i),
Flavour: safeStr(specialFlavours, i),
Notes: safeStr(specialNotes, i),
Tags: tags,
})
}
n.Accepted = time.Now()
n.Name = strings.TrimSpace(r.FormValue("name"))
n.Surname = strings.TrimSpace(r.FormValue("surname"))
@ -77,3 +134,26 @@ func (h *Server) postOrder(r *http.Request) (templ.Component, int, error) {
n.ID, err = h.s.SaveOrder(n)
return templates.Confirmation("Potwierdzone", n.ID), http.StatusAccepted, err
}
func safeStr(s []string, i int) string {
if i < len(s) {
return s[i]
}
return ""
}
func (h *Server) updateStatus(r *http.Request) (templ.Component, int, error) {
id, err := strconv.Atoi(r.PathValue("id"))
if err != nil {
return nil, http.StatusBadRequest, err
}
order, err := h.s.GetOrder(id)
if err != nil {
return nil, http.StatusNotFound, err
}
order.Status = r.FormValue("status")
if _, err := h.s.SaveOrder(order); err != nil {
return nil, http.StatusInternalServerError, err
}
return templates.OrderRow(order), http.StatusOK, nil
}