removed 'internal' directory

This commit is contained in:
Bronku 2025-06-19 21:48:06 +02:00
parent 8c200a5a6c
commit 65709049d7
42 changed files with 35 additions and 44 deletions

5
server/fetcher.go Normal file
View file

@ -0,0 +1,5 @@
package server
import "net/http"
type fetcher func(r *http.Request) (any, int, error)

104
server/get.go Normal file
View file

@ -0,0 +1,104 @@
package server
import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
"github.com/Bronku/iroon/models"
)
func monthInterval(y int, m time.Month) (firstDay, lastDay time.Time) {
firstDay = time.Date(y, m, 1, 0, 0, 0, 0, time.UTC)
lastDay = time.Date(y, m+1, 1, 0, 0, 0, -1, time.UTC)
return firstDay, lastDay
}
func (h *Server) orders(_ *http.Request) (any, int, error) {
var (
y int
m time.Month
)
y, m, _ = time.Now().Date()
first, last := monthInterval(y, m)
fmt.Println(first, last)
orders, err := h.s.GetFilteredOrder("", first, last)
data := struct {
First string
Last string
Orders []models.Order
}{first.Format("2006-01-02"), last.Format("2006-01-02"), orders}
return data, http.StatusOK, err
}
func (h *Server) ordersSearch(r *http.Request) (any, int, error) {
q := r.URL.Query().Get("q")
from, err := time.Parse("2006-01-02", r.URL.Query().Get("from"))
if err != nil {
from = time.Time{}
}
to, err := time.Parse("2006-01-02", r.URL.Query().Get("to"))
if err != nil {
to = time.Time{}
}
fmt.Println(from, to)
data, err := h.s.GetFilteredOrder(q, from, to)
return data, http.StatusOK, err
}
func (h *Server) cakes(_ *http.Request) (any, int, error) {
data, err := h.s.GetCakes()
return data, http.StatusOK, err
}
func (h *Server) cake(r *http.Request) (any, int, error) {
url := strings.Split(r.URL.String(), "/")
if len(url) < 3 || url[2] == "" {
return models.Cake{}, http.StatusOK, nil
}
id, err := strconv.Atoi(url[2])
if err != nil {
return nil, http.StatusBadRequest, err
}
data, err := h.s.GetCake(id)
if err != nil {
return nil, http.StatusNotFound, err
}
return data, http.StatusOK, nil
}
func (h *Server) order(r *http.Request) (any, int, error) {
type formData struct {
Order models.Order
Catalogue []models.Cake
}
var err error
var data formData
data.Catalogue, err = h.s.GetCakes()
if err != nil {
return nil, http.StatusInternalServerError, err
}
url := strings.Split(r.URL.String(), "/")
if len(url) < 3 || url[2] == "" {
return data, http.StatusOK, nil
}
id, err := strconv.Atoi(url[2])
if err != nil {
return nil, http.StatusBadRequest, err
}
data.Order, err = h.s.GetOrder(id)
if err != nil {
return nil, http.StatusNotFound, err
}
return data, http.StatusOK, nil
}

9
server/http.go Normal file
View file

@ -0,0 +1,9 @@
package server
import "net/http"
func (h *Server) redirect(path string, code int) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path, code)
}
}

81
server/post.go Normal file
View file

@ -0,0 +1,81 @@
package server
import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
"github.com/Bronku/iroon/models"
)
func (h *Server) postCake(r *http.Request) (any, int, error) {
err := r.ParseForm()
if err != nil {
return nil, http.StatusInternalServerError, err
}
var n models.Cake
n.ID, err = strconv.Atoi(r.FormValue("id"))
if err != nil {
return nil, http.StatusBadRequest, err
}
n.Name = r.FormValue("name")
n.Price, err = strconv.Atoi(r.FormValue("price"))
if err != nil {
return nil, http.StatusBadRequest, err
}
n.Category = r.FormValue("category")
n.Availability = r.FormValue("availability")
n.ID, err = h.s.SaveCake(n)
fmt.Println(err)
return n, http.StatusAccepted, err
}
func (h *Server) postOrder(r *http.Request) (any, int, error) {
cakes, err := h.s.GetCakes()
if err != nil {
return nil, http.StatusInternalServerError, err
}
err = r.ParseForm()
fmt.Println(r.PostForm)
if err != nil {
return nil, http.StatusBadRequest, err
}
var n models.Order
n.ID, err = strconv.Atoi(r.FormValue("id"))
if err != nil {
return nil, http.StatusBadRequest, err
}
n.Paid, err = strconv.Atoi(r.FormValue("paid"))
if err != nil {
return nil, http.StatusBadRequest, err
}
n.Date, err = time.Parse("2006-01-02", r.FormValue("date"))
if err != nil {
return nil, http.StatusBadRequest, err
}
n.Cakes = make([]models.Cake, 0)
for _, e := range cakes {
e.Amount, err = strconv.Atoi(r.FormValue(fmt.Sprintf("cake[%d]", e.ID)))
if err != nil {
continue
}
n.Cakes = append(n.Cakes, e)
}
n.Accepted = time.Now()
n.Name = strings.TrimSpace(r.FormValue("name"))
n.Surname = strings.TrimSpace(r.FormValue("surname"))
n.Phone = strings.TrimSpace(r.FormValue("phone"))
n.Location = strings.TrimSpace(r.FormValue("location"))
n.Status = strings.TrimSpace(r.FormValue("status"))
n.ID, err = h.s.SaveOrder(n)
fmt.Println(n)
return n, http.StatusAccepted, err
}

63
server/server.go Normal file
View file

@ -0,0 +1,63 @@
package server
import (
"embed"
"html/template"
"net/http"
"github.com/Bronku/iroon/store"
)
type Server struct {
tmpl map[string]*template.Template
s *store.Store
routes map[string]route
http.Handler
}
type route struct {
function fetcher
template string
templateEntry string
}
func (h *Server) Close() {
}
//go:embed static/*
var static embed.FS
func (h *Server) loadHandler() {
mux := http.NewServeMux()
for i, e := range h.routes {
mux.HandleFunc(i, h.render(e.function, e.template, e.templateEntry))
}
mux.HandleFunc("GET /", h.redirect("/orders", http.StatusSeeOther))
fs := http.FileServerFS(static)
mux.Handle("GET /static/", fs)
h.Handler = mux
}
func New(store *store.Store) *Server {
var server Server
server.routes = map[string]route{
"GET /order/": {server.order, "order", "layout"},
"GET /orders": {server.orders, "orders", "layout"},
"GET /orders/search/": {server.ordersSearch, "orders", "orders-table"},
"GET /cake/": {server.cake, "cake", "layout"},
"GET /cakes": {server.cakes, "cakes", "layout"},
"POST /order/": {server.postOrder, "confirmation", "layout"},
"POST /cake/": {server.postCake, "confirmation", "layout"},
}
server.loadTemplates()
server.s = store
server.loadHandler()
return &server
}

File diff suppressed because one or more lines are too long

19
server/static/fontawesome/css/solid.css vendored Normal file
View file

@ -0,0 +1,19 @@
/*!
* Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
* Copyright 2024 Fonticons, Inc.
*/
:root, :host {
--fa-style-family-classic: 'Font Awesome 6 Free';
--fa-font-solid: normal 900 1em/1 'Font Awesome 6 Free'; }
@font-face {
font-family: 'Font Awesome 6 Free';
font-style: normal;
font-weight: 900;
font-display: block;
src: url("../webfonts/fa-solid-900.woff2") format("woff2"), url("../webfonts/fa-solid-900.ttf") format("truetype"); }
.fas,
.fa-solid {
font-weight: 900; }

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

55
server/static/order.js Normal file
View file

@ -0,0 +1,55 @@
function addCake(id, name, price, amount) {
const cake = document.querySelector(`[name="cake[${id}]"]`);
if (cake != null) {
cake.value = Number(cake.value) + 1;
let tr = cake.parentElement.parentElement.parentElement;
console.log(tr);
tr.querySelector(".cake-total").innerText =
`${price * Number(cake.value)}PLN`;
updateTotalPrice();
return;
}
let template = document.getElementById("basket_element_template");
let tr = template.content.querySelector("tr").cloneNode(true);
tr.querySelector(".cake-name").innerText = name;
tr.querySelector(".cake-price").innerText = `${price}PLN`;
tr.querySelector(".cake-total").innerText = `${price * amount}PLN`;
tr.querySelector("button").onclick = () => {
tr.remove();
};
let input = tr.querySelector("input");
input.onchange = () => {
if (input.value == 0) {
tr.remove();
}
tr.querySelector(".cake-total").innerText = `${price * input.value}PLN`;
updateTotalPrice();
};
input.value = amount;
input.name = `cake[${id}]`;
document.querySelector("#basket_table").appendChild(tr);
updateTotalPrice();
}
function updateTotalPrice() {
document.querySelector("#total-price").innerText = `${totalPrice()}PLN`;
}
function totalPrice() {
let out = 0;
const cakes = document.querySelectorAll("#basket_table>tr");
cakes.forEach((e) => {
let priceString = e.querySelector(".cake-price").innerText;
let price = Number(priceString.substring(0, priceString.length - 3));
let amount = Number(e.querySelector("input").value);
out += price * amount;
console.log(out);
});
return out;
}
function toggleDetails(row) {
const detailsRow = row.nextElementSibling;
if (detailsRow.classList.contains("hidden")) {
detailsRow.classList.remove("hidden");
return;
}
detailsRow.classList.add("hidden");
}

368
server/static/style.css Normal file
View file

@ -0,0 +1,368 @@
:root {
--primary-color: #ff6b6b;
--primary-light: #ffeded;
--primary-dark: #e64c4c;
--text-color: #333333;
--text-light: #666666;
--background-color: #f8f9fa;
--white: #ffffff;
--border-color: #e4e9ec;
--hover-color: #f5f5f5;
--shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
--bottom-shadow: 0 4px 2px -2px rgba(0, 0, 0, 0.1);
--font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
--transition: 0.2s ease;
--radius: 6px;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: var(--font-main);
color: var(--text-color);
background-color: var(--background-color);
display: flex;
width: 100%;
line-height: 1.6;
}
/* Sidebar */
aside {
min-width: 4.5rem;
max-width: 4.5rem;
background-color: var(--primary-color);
height: 100vh;
position: fixed;
left: 0;
top: 0;
border-right: 1px solid var(--border-color);
box-shadow: var(--shadow);
z-index: 10;
}
nav {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 2rem;
gap: 1.5rem;
height: 100%;
}
nav>a {
color: var(--white);
text-decoration: none;
font-size: 1.5rem;
width: 3rem;
height: 3rem;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
transition: background-color var(--transition);
position: relative;
}
nav>a:hover {
background-color: var(--primary-dark);
}
nav>a:last-child {
margin-top: auto;
margin-bottom: 2rem;
}
nav>a>i {
text-decoration: none;
color: var(--white);
}
/* Tooltip for sidebar icons */
nav>a::after {
content: attr(data-title);
position: absolute;
left: 120%;
top: 50%;
transform: translateY(-50%);
background-color: var(--text-color);
color: var(--white);
padding: 0.3rem 0.8rem;
border-radius: var(--radius);
font-size: 0.8rem;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity var(--transition);
z-index: 1;
}
nav>a:hover::after {
opacity: 1;
}
/* Main content area */
.app-body {
flex: 1;
margin-left: 4.5rem;
padding: 0;
display: flex;
flex-direction: column;
height: 100dvh;
overflow-x: hidden;
}
header {
background-color: var(--white);
border-bottom: 1px solid var(--border-color);
padding: 1rem 2rem;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
position: sticky;
top: 0;
z-index: 5;
}
h1 {
font-size: 1.8rem;
font-weight: 600;
color: var(--primary-color);
}
main {
flex: 1;
padding: 2rem;
display: flex;
flex-direction: column;
height: 100%;
gap: 1.5rem;
overflow: hidden;
}
/* Search form */
.search-container {
background-color: var(--white);
border-radius: var(--radius);
padding: 1.25rem;
display: flex;
flex-wrap: wrap;
gap: 1rem;
align-items: flex-end;
box-shadow: var(--shadow);
}
.search-box {
flex: 1;
min-width: 250px;
position: relative;
}
.search-box input {
width: 100%;
padding: 0.75rem 1rem 0.75rem 2.5rem;
border: 1px solid var(--border-color);
border-radius: var(--radius);
font-size: 1rem;
transition: border-color var(--transition);
}
.search-box::before {
content: "🔍";
position: absolute;
left: 1rem;
top: 50%;
transform: translateY(-50%);
color: var(--text-light);
}
.search-container label:not(.search-box) {
display: flex;
flex-direction: column;
gap: 0.5rem;
font-size: 0.9rem;
color: var(--text-light);
}
.search-container input[type="date"] {
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: var(--radius);
min-width: 160px;
}
.search-container input:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
}
/* Table styling */
#results-table {
background-color: var(--white);
border-radius: var(--radius);
box-shadow: var(--shadow);
/* overflow: hidden; */
margin-top: 1rem;
}
table {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
font-size: 0.95rem;
}
thead {
border-bottom: 1px solid var(--border-color);
background-color: var(--white);
position: sticky;
top: 0;
z-index: 1;
box-shadow: 0 2px 0 var(--border-color);
}
tbody th {
font-weight: 300;
color: var(--text-color);
}
thead th {
color: var(--text-light);
font-weight: 100;
font-size: rem;
font-size: 0.8rem;
/* box-shadow: var(--bottom-shadow); */
}
th {
text-align: left;
padding: 1rem;
/* color: var(--primary-dark); */
}
td {
padding: 1rem;
}
th:first-child,
td:first-child {
padding-left: 1.5rem;
}
th:last-child,
td:last-child {
padding-right: 1.5rem;
}
tr.clickable {
cursor: pointer;
transition: background-color var(--transition);
}
tr.clickable:hover {
background-color: var(--hover-color);
}
tr.active {
background-color: var(--primary-light);
}
/* Order details */
.details-content {
background-color: var(--hover-color);
padding: 0 !important;
}
.details-content table {
margin: 0;
box-shadow: none;
}
.details-content th {
background-color: transparent;
font-weight: normal;
}
/* Links */
a {
text-decoration: none;
color: var(--text-light);
}
tr a {
text-decoration: underline;
color: var(--primary-color);
}
.order {
flex-grow: 1;
display: flex;
flex-direction: row;
width: 100%;
padding: 1.5rem;
background-color: var(--white);
border-radius: var(--radius);
box-shadow: var(--shadow);
height: 100%;
}
.order div {
flex-grow: 1;
display: flex;
flex-direction: column;
}
.order>div {
flex-basis: 0;
flex-shrink: 0;
}
.order-contents>*:first-child,
.order-contents>*:last-child {
flex-grow: 0;
}
.order label {
display: flex;
justify-content: space-between;
flex-direction: row;
align-items: center;
}
.scrollable {
overflow-y: auto;
min-height: 0;
}
/* Responsive adjustments */
@media (max-width: 768px) {
.search-container {
flex-direction: column;
align-items: stretch;
}
.search-container>* {
width: 100%;
}
aside {
min-width: 3.5rem;
max-width: 3.5rem;
}
.app-body {
margin-left: 3.5rem;
}
nav a {
width: 2.5rem;
height: 2.5rem;
font-size: 1.2rem;
}
}

43
server/template.go Normal file
View file

@ -0,0 +1,43 @@
package server
import (
"embed"
"html/template"
"log"
"net/http"
"github.com/Bronku/iroon/logging"
)
//go:embed templates/*
var templates embed.FS
func (h *Server) loadTemplates() {
h.tmpl = make(map[string]*template.Template)
for _, page := range h.routes {
tmpl, err := template.ParseFS(templates,
"templates/layout/*.gohtml",
"templates/"+page.template+".gohtml",
)
if err != nil {
log.Fatal(err)
}
h.tmpl[page.template] = tmpl
}
}
func (h *Server) render(fetch fetcher, templateFile string, templateEntry string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
data, code, err := fetch(r)
if err != nil {
logging.ErrorPage(err, code).ServeHTTP(w, r)
return
}
err = h.tmpl[templateFile].ExecuteTemplate(w, templateEntry, data)
if err != nil {
logging.ErrorPage(err, http.StatusInternalServerError).ServeHTTP(w, r)
return
}
w.Header().Set("content-type", "text/html")
}
}

View file

@ -0,0 +1,36 @@
{{define "title"}}
Cake {{.ID}}
{{end}}
{{define "main"}}
<main>
<form method="post">
<div>
<h2>Info</h2>
<label>
<input hidden="hidden" name="id" value="{{.ID}}">
</label>
<label>name</label>
<label>
<input type="text" name="name" value="{{.Name}}">
</label>
<label>price</label>
<label>
<input type="number" name="price" min="0" value="{{.Price}}">
</label>
<label>category</label>
<label for="category"></label><select name="category" id="category" >
<option {{ if eq .Category "common" }}selected{{ end }} value="common">common</option>
<option {{ if eq .Category "christmas" }}selected{{ end }} value="christmas">christmas</option>
<option {{ if eq .Category "easter" }}selected{{ end }} value="easter">easter</option>
<option {{ if eq .Category "donuts" }}selected{{ end }} value="donuts">donuts</option>
</select>
<label>availability</label>
<label for="availability"></label><select name="availability" id="availability" >
<option {{ if eq .Availability "available" }}selected{{ end }} value="available">available</option>
<option {{ if eq .Availability "unavailable" }}selected{{ end }} value="unavailable">unavailable</option>
</select>
</div>
<button type="submit">submit</button>
</form>
</main>
{{end}}

View file

@ -0,0 +1,25 @@
{{define "title"}}
Cakes
{{end}}
{{define "main"}}
<main>
<table>
<tr>
<th></th>
<th>Name</th>
<th>Price</th>
<th>Category</th>
<th>Availability</th>
</tr>
{{range .}}
<tr>
<th><a href="/cake/{{.ID}}">edit</a></th>
<th>{{.Name}}</th>
<th>{{.Price}}</th>
<th>{{.Category}}</th>
<th>{{.Availability}}</th>
</tr>
{{end}}
</table>
</main>
{{end}}

View file

@ -0,0 +1,8 @@
{{define "title"}}
Confirmed
{{end}}
{{define "main"}}
<main>
<h2>{{.ID}} confirmed</h2>
</main>
{{end}}

View file

@ -0,0 +1,28 @@
{{define "layout"}}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>{{template "title" .}}</title>
<script src="/static/htmx2.04.js" defer></script>
<script src="/static/order.js" ></script>
<link rel="stylesheet" href="/static/style.css">
<link rel="stylesheet" href="/static/fontawesome/css/fontawesome.min.css">
<link rel="stylesheet" href="/static/fontawesome/css/solid.css">
</head>
<body>
<aside>
<nav>{{template "nav" .}}</nav>
</aside>
<div class="app-body">
<header>
<h1>{{template "title" .}}</h1>
</header>
{{template "main" .}}
</div>
</body>
</html>
{{end}}

View file

@ -0,0 +1,7 @@
{{define "nav"}}
<a href="/orders" data-title="Zamówienia"><i class="fa-solid fa-list-ul"></i></a>
<a href="/order" data-title="Nowe zamówienie"><i class="fa-solid fa-plus-circle"></i></a>
<a href="/cakes" data-title="Wszystkie ciasta"><i class="fa-solid fa-birthday-cake"></i></a>
<a href="/cake" data-title="Nowe ciasto"><i class="fa-solid fa-plus"></i></a>
<a href="/logout" data-title="Wyloguj"><i class="fa-solid fa-sign-out-alt"></i></a>
{{end}}

View file

@ -0,0 +1,109 @@
{{define "title"}}
{{if .Order.ID}}
Edytuj zamówienie #{{.Order.ID}}
{{else}}
Nowe zamówienie
{{end}}
{{end}}
{{define "main"}}
<main>
<form method="post" class="order">
{{with .Order}}
<div class="order-contents">
<div>
<h2>Dane zamówienia</h2>
<label>
<input hidden="hidden" name="id" value="{{.ID}}">
</label>
<label>Imię
<input type="text" name="name" value="{{.Name}}">
</label>
<label>Nazwisko
<input type="text" name="surname" value="{{.Surname}}">
</label>
<label>Numer telefonu
<input type="tel" name="phone" value="{{.Phone}}">
</label>
<label>Lokalizacja
<select name="location">
<option {{ if eq .Location "Kartuzy" }}selected{{ end }} value="Kartuzy">Kartuzy</option>
<option {{ if eq .Location "Somonino" }}selected{{ end }} value="Somonino">Somonino</option>
</select>
</label>
<label>Data dostawy
<input type="date" name="date" value="{{.Date.Format "2006-01-02"}}">
</label>
<label>Status
<select name="status">
<option {{ if eq .Status "accepted" }}selected{{ end }} value="accepted">accepted</option>
<option {{ if eq .Status "done" }}selected{{ end }} value="done">done</option>
</select>
</label>
<label>Zaliczka
<input type="number" name="paid" min="0" value="{{.Paid}}">
</label>
</div>
<div>
<h2>Dodane Ciasta</h2>
<div class="scrollable">
<table id="basket_table" >
</table>
</div>
<ul id="basket" class="scrollable">
</ul>
</div>
<div>
<label>
<small>Total:</small><br>
<p id="total-price">100PLN</p>
</label>
<button type="submit">Zapisz</button>
</div>
</div>
{{end}}
{{with .Catalogue}}
<div>
<h2>Katalog</h2>
<div class="scrollable">
<table>
{{range .}}
<tr>
<th>{{.Name}}<br><small>{{.Category}} (#{{.ID}})</small></th>
<th>{{.Price}}PLN</th>
<th>
<button type=button onClick="addCake({{.ID}},{{.Name}}, {{.Price}}, 1)">
<i class="fa-solid fa-plus"></i>
</button>
</th>
</tr>
{{end}}
</table>
</div>
</div>
{{end}}
</form>
</main>
<template id="basket_element_template">
<tr>
<th class="cake-name">Name</th>
<th class="cake-price">Price</th>
<th>
<label>
<input type="number" min="0">
</label>
</th>
<th class="cake-total">Total</th>
<th>
<button type=button>
<i class="fa-solid fa-minus"></i>
</button>
</th>
</tr>
</template>
<script>
{{range .Order.Cakes}}
addCake({{.ID}},{{.Name}}, {{.Price}}, {{.Amount}})
{{end}}
</script>
{{end}}

View file

@ -0,0 +1,74 @@
{{define "title"}}
Zamówienia
{{end}}
{{define "main"}}
<main>
<form class="search-container" hx-get="/orders/search" hx-target="#results-table"
hx-trigger="keyup delay:500ms, change">
<label class="search-box">
<input type="search" name="q" placeholder="Wyszukaj po numerze zamówienia">
</label>
<label>Data początkowa
<input type="date" value="{{.First}}" name="from">
</label>
<label>Data końcowa
<input type="date" value="{{.Last}}" name="to">
</label>
</form>
<div id="results-table" class="scrollable">
{{template "orders-table" .Orders}}
</div>
</main>
<style>
.hidden {
display: none;
}
.active {
background-color: #e6f2ff;
}
</style>
{{end}}
{{define "orders-table"}}
<table id="orders_table">
<thead>
<tr>
<th>Numer zamówienia</th>
<th>Klient</th>
<th>Lokalizacja</th>
<th>Data zamówienia</th>
<th>Pozostało do zapłaty</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{{range .}}
<tr class="clickable" onclick="toggleDetails(this)">
<th><a href="/order/{{.ID}}">#{{.ID}}</a></th>
<th>{{.Surname}} {{.Name}} {{.Phone}}</th>
<th>{{.Location}}</th>
<th>{{.Date.Format "2006-01-02"}}</th>
<th>{{.Total}} PLN</th>
<th>{{.Status}}</th>
</tr>
<tr class="hidden">
<td colspan="6" class="details-content">
{{template "order_info" .}}
</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
{{define "order_info"}}
<table>
{{range .Cakes}}
<tr>
<th>{{.Name}}<br><small>ID: {{.ID}}</small></th>
<th><small>Cena:</small><br>{{.Price}} PLN</th>
<th><small>Ilość:</small><br>{{.Amount}}</th>
<th><small>Razem:</small><br>{{.Total}} PLN</th>
</tr>
{{end}}
</table>
{{end}}