refactor: change template generation from go-elem to templ and clean up the repository

This commit is contained in:
Patryk Hegenberg 2024-11-27 09:38:26 +01:00
parent f6b6f81826
commit a3dc4eddfa
19 changed files with 842 additions and 874 deletions

147
templates/templates.templ Normal file
View file

@ -0,0 +1,147 @@
package templates
import (
"strconv"
"fmt"
"echoTest/models"
)
templ layout(title string) {
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{title}</title>
<script src="https://unpkg.com/htmx.org@1.9.6"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css" />
</head>
<body>
<nav class="navbar" role="navigation" aria-label="main navigation">
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">Home</a>
</div>
<div class="navbar-end">
<span class="navbar-item">
<button class="button is-primary" hx-get="/end">Beenden</button>
</span>
</div>
</div>
</nav>
<div class="container is-widescreen">
{children...}
</div>
<footer class="footer">
<div class="content has-text-centered">
<p>&copy; 2023 Alle Rechte vorbehalten.</p>
</div>
</footer>
</body>
</html>
}
templ BewertungenForm(maxPunkte models.MaxPunkte) {
<form method="post" action="/add">
<div class="tile is-ancestor">
<div class="tile field is-parent">
<input class="input is-child" type="text" name="hv_max" placeholder="HV-Max-Punkte" value={fmt.Sprintf("%.2f",
maxPunkte.HvMax)} />
</div>
<div class="tile field is-parent">
<input class="input is-child" type="text" name="hv_gewichtung" placeholder="HV-Gewichtung in %"
value={fmt.Sprintf("%.2f", maxPunkte.HvGewichtung)} />
</div>
<div class="tile field is-parent">
<input class="input is-child" type="text" name="lv_max" placeholder="LV-Max-Punkte" value={fmt.Sprintf("%.2f",
maxPunkte.LvMax)} />
</div>
<div class="tile field is-parent">
<input class="input is-child" type="text" name="lv_gewichtung" placeholder="LV-Gewichtung in %"
value={fmt.Sprintf("%.2f", maxPunkte.LvGewichtung)} />
</div>
</div>
<div class="tile is-ancestor">
<div class="tile field is-parent">
<input type="text" name="vorname" class="input is-child" placeholder="Vorname" />
</div>
<div class="tile field is-parent">
<input type="text" name="nachname" class="input is-child" placeholder="Nachname" />
</div>
<div class="tile field is-parent">
<input type="text" name="hv_punkte" class="input is-child" placeholder="HV-Punkte" />
</div>
<div class="tile field is-parent">
<input type="text" name="lv_punkte" class="input is-child" placeholder="LV-Punkte" />
</div>
<div class="tile field is-parent">
<button type="submit" class="button tile is-child">Add</button>
</div>
</div>
</form>
}
templ BewertungenTable(bewertungen []models.Bewertung) {
<div class="table-container">
<table class="table is-hoverable">
<thead>
<tr>
<th>Gewertet</th>
<th>Vorname</th>
<th>Nachname</th>
<th>HV-Punkte</th>
<th>HV-Prozent</th>
<th>HV-Note</th>
<th>LV-Punkte</th>
<th>LV-Prozent</th>
<th>LV-Note</th>
<th>Gesamt-Prozent</th>
<th>Gesamt-Note</th>
</tr>
</thead>
<tbody>
for _, b := range bewertungen {
<tr id={"bewertung-" + strconv.Itoa(b.ID)}>
<td>
<input type="checkbox" checked?={b.Gewertet} hx-post={"/toggle/" + strconv.Itoa(b.ID)}
hx-target={"#bewertung-" + strconv.Itoa(b.ID)} hx-swap="outerHTML" />
</td>
<td>{b.Vorname}</td>
<td>{b.Nachname}</td>
<td>{fmt.Sprintf("%.2f", b.HvPunkte)}</td>
<td>{fmt.Sprintf("%.2f", b.HvProzent)}</td>
<td>{strconv.Itoa(b.HvNote)}</td>
<td>{fmt.Sprintf("%.2f", b.LvPunkte)}</td>
<td>{fmt.Sprintf("%.2f", b.LvProzent)}</td>
<td>{strconv.Itoa(b.LvNote)}</td>
<td>{fmt.Sprintf("%.2f", b.GesamtProzent)}</td>
<td>{strconv.Itoa(b.GesamtNote)}</td>
</tr>
}
</tbody>
</table>
</div>
}
templ BewertungenPage(bewertungen []models.Bewertung, maxPunkte models.MaxPunkte) {
@layout("Englischarbeit") {
<div class="card tile is-vertical is-ancestor">
<header class="card-header">
<p class="card-header-title">Englischarbeit</p>
</header>
<div class="card-content">
<div class="content tile is-parent is-vertical gap">
<h1 class="title">Bewertungen</h1>
@BewertungenForm(maxPunkte)
@BewertungenTable(bewertungen)
<div>
<button hx-get="/export" class="button">export</button>
</div>
</div>
</div>
</div>
}
}