FIX: warnings

This commit is contained in:
bronku 2025-03-31 01:22:14 +02:00
parent 67807992bc
commit c32ecbff8f
57 changed files with 1898 additions and 21 deletions

View file

@ -0,0 +1,30 @@
{{define "title"}}
Cake {{.ID}}
{{end}}
{{define "main"}}
<main>
<form method="post">
<div>
<h2>Info</h2>
<input hidden="true" name="id" value="{{.ID}}">
<label>name</label>
<input type="text" name="name" value="{{.Name}}">
<label>price</label>
<input type="number" name="price" min="0" value="{{.Price}}">
<label>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>
<select name="availibility" id="availibility" >
<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,17 @@
{{define "layout"}}
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>{{template "title" .}}</title>
<script src="/static/htmx2.04.js" defer></script>
</head>
<body>
<header>
<h1>{{template "title" .}}</h1>
</header>
<nav>{{template "nav" .}}</nav>
{{template "main" .}}
</body>
</html>
{{end}}

View file

@ -0,0 +1,6 @@
{{define "nav"}}
<a href="/orders">All orders</a>
<a href="/order">New order</a>
<a href="/cakes">All Cakes</a>
<a href="/cake">New Cake</a>
{{end}}

View file

@ -0,0 +1,90 @@
{{define "title"}}
Order {{.Order.ID}}
{{end}}
{{define "main"}}
<main>
<form method="post">
{{with .Order}}
<div>
<h2>Info</h2>
<input hidden="true" name="id" value="{{.ID}}">
<label>name</label>
<input type="text" name="name" value="{{.Name}}">
<label>surname</label>
<input type="text" name="surname" value="{{.Surname}}">
<label>phone</label>
<input type="tel" name="phone" value="{{.Phone}}">
<label>location</label>
<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>date</label>
<input type="date" name="date" value="{{.Date.Format "2006-01-02"}}">
<label>status</label>
<select name="status" id="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>paid</label>
<input type="number" name="paid" min="0" value="{{.Paid}}">
</div>
<div>
<h2>Basket</h2>
<ul id="basket">
</ul>
</div>
{{end}}
{{with .Catalogue}}
<div>
<h2>Catalogue</h2>
<ul>
{{range .}}
<li>
{{.Name}} {{.Price}} <button type=button onClick="addCake({{.ID}},'{{.Name}} {{.Price}}', 1)">add</button>
</li>
{{end}}
</ul>
</div>
{{end}}
<button type="submit">submit</button>
</form>
</main>
<script>
function addCake(id, name, amount){
var cake = document.getElementById("cake["+id+"]")
if (cake != null){
var value = Number(cake.getAttribute("value"))
cake.setAttribute("value", value+1)
return;
}
var label = document.createElement("label")
label.innerText = name
var input = document.createElement("input")
input.setAttribute("id","cake["+id+"]")
input.setAttribute("type", "number")
input.setAttribute("min", "0")
input.setAttribute("name", "cake["+id+"]")
input.setAttribute("value", amount)
var button = document.createElement("button")
button.setAttribute("type", "button")
button.setAttribute("onClick", "removeCake("+id+")")
button.innerText= "delete"
var li = document.createElement("li")
li.appendChild(label)
li.appendChild(input)
li.appendChild(button)
li.setAttribute("id", "li["+id+"]")
var ul = document.getElementById("basket")
ul.appendChild(li)
}
function removeCake(id){
document.getElementById("li["+id+"]").remove()
}
{{range .Order.Cakes}}
addCake({{.ID}}, '{{.Name}} {{.Price}}', {{.Amount}})
{{end}}
</script>
{{end}}

View file

@ -0,0 +1,51 @@
{{define "title"}}
Orders
{{end}}
{{define "main"}}
<main>
<form class="search-container" hx-get="/orders/search" hx-target="#results-table", hx-trigger="keyup delay:500ms, change">
<input type="search" name="q" placeholder="Search orders...">
<label for="from">form</label>
<input type="date" value="{{.Today}}" id="from" name="from">
<label for="from">to</label>
<input type="date" value="{{.Today}}" id="to" name="to">
<div class="htmx-indicator">
Searching...
</div>
<div id="results-table">
{{template "orders-table" .Orders}}
</div>
</form>
</main>
{{end}}
{{define "orders-table"}}
<table id="orders_table">
<tr>
<th></th>
<th>Name</th>
<th>Surname</th>
<th>Phone</th>
<th>Location</th>
<th>Date</th>
<th>Status</th>
<th>Total</th>
</tr>
{{range .}}
<tr>
<th><a href="/order/{{.ID}}">edit</a></th>
<th>{{.Name}}</th>
<th>{{.Surname}}</th>
<th>{{.Phone}}</th>
<th>{{.Location}}</th>
<th>{{.Date.Format "2006-01-02"}}</th>
<th>{{.Status}}</th>
<th>{{.Total}}</th>
</tr>
{{end}}
</table>
{{end}}