cake-order-tracker/server/templates/helpers.go
bronkuu 5a5372b831 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.
2026-06-15 18:50:21 +02:00

86 lines
1.6 KiB
Go

package templates
import (
"fmt"
"strconv"
"strings"
"git.bronku.xyz/bronku/cake-order-tracker/models"
)
func CakeTitle(cake models.Cake) string {
if cake.ID != 0 {
return "Ciasto #" + strconv.Itoa(cake.ID)
}
return "Ciasto nowe"
}
func OrderTitle(order models.Order) string {
if order.ID != 0 {
return "Edytuj zamówienie #" + strconv.Itoa(order.ID)
}
return "Nowe zamówienie"
}
func specialCakeDetail(sc models.SpecialCake) string {
return sc.Detail()
}
func cakeItemsDesc(cakes []models.Cake) string {
desc := ""
for i, c := range cakes {
if i > 0 {
desc += ", "
}
desc += c.Name + " (x" + strconv.Itoa(c.Amount) + ")"
}
return desc
}
func cakeHasTag(tags []models.Tag, id int) bool {
for _, t := range tags {
if t.ID == id {
return true
}
}
return false
}
func tagIDsComma(tags []models.Tag) string {
ids := make([]string, len(tags))
for i, t := range tags {
ids[i] = strconv.Itoa(t.ID)
}
return strings.Join(ids, ",")
}
func tagNames(tags []models.Tag) string {
names := make([]string, len(tags))
for i, t := range tags {
names[i] = t.Name
}
return strings.Join(names, ",")
}
func orderItemsDesc(order models.Order) string {
desc := cakeItemsDesc(order.Cakes)
for _, s := range order.SpecialCakes {
if desc != "" {
desc += ", "
}
desc += s.Name + " *"
}
return desc
}
func orderScript(order models.Order) string {
var b strings.Builder
b.WriteString("<script>")
if order.ID != 0 {
for _, c := range order.Cakes {
b.WriteString(fmt.Sprintf("updateCatalogueQty(%d,%d);", c.ID, c.Amount))
}
}
b.WriteString("updateTotals();</script>")
return b.String()
}