cake-order-tracker/server/templates/helpers.go
bronkuu 5f156ab6a0 blocked dates page and warning for special-cake orders
Add blocked_date table (migration 5), model, and store CRUD methods.
Add management page at /blocked with add/delete functionality.
Add nav link 'Terminy zablokowane' with event_busy icon.
Pass blocked dates to order form as JSON data attribute.
On form submit, if the order has special cakes and the date is
blocked, show a confirm() dialog warning the user.
2026-06-15 18:54:48 +02:00

96 lines
1.8 KiB
Go

package templates
import (
"encoding/json"
"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 blockedDatesJSON(dates []models.BlockedDate) string {
names := make([]string, len(dates))
for i, d := range dates {
names[i] = d.Date
}
b, _ := json.Marshal(names)
return string(b)
}
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()
}