Fixed the templating system

This commit is contained in:
Gregory Ballantine 2022-12-07 21:51:49 -05:00
parent d56d0ba19a
commit e1b64766b6
6 changed files with 102 additions and 15 deletions

View File

@ -14,4 +14,13 @@ func RegisterRoutes(f *flamego.Flame) {
})
// item list route - lists all of the items in the database
f.Group("/item", func() {
f.Get("/list", func(t template.Template, data template.Data) {
t.HTML(http.StatusOK, "item/list")
})
f.Get("/create", func(t template.Template, data template.Data) {
t.HTML(http.StatusOK, "item/create")
})
})
}

View File

@ -1,11 +1,9 @@
{{ template "layout" . }}
{{ template "layout_header" . }}
{{ define "title" }}Dashboard{{ end }}
{{ define "content" }}
<div class="row">
<div class="row">
<div class="twelve columns">
<p>This is a test.</p>
</div>
</div>
{{ end }}
</div>
{{ template "layout_footer" . }}

68
views/item/create.html Normal file
View File

@ -0,0 +1,68 @@
{{ template "layout_header" . }}
<div class="row">
<div class="twelve columns">
<h1>Create new item</h1>
</div>
</div>
<div class="row">
<div class="twelve columns">
<form action="/item/create" method="POST" class="u-full-width">
<div class="row">
<div class="columns twelve">
<label for="item_name">Item name:</label>
<input class="u-full-width" type="text" placeholder="My new item" id="item_name" name="item_name" required>
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_serial">Serial number:</label>
<input class="u-full-width" type="text" placeholder="0123456789" id="item_serial" name="item_serial">
</div>
<div class="six columns">
<label for="item_sku">SKU number:</label>
<input class="u-full-width" type="text" placeholder="ABC12345678" id="item_sku" name="item_sku">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="item_purchase_from" name="item_purchase_from">
</div>
<div class="six columns">
<label for="item_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="item_purchase_date" name="item_purchase_date">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="item_manufacturer" name="item_manufacturer">
</div>
<div class="six columns">
<label for="item_type">Item type</label>
<select class="u-full-width" id="item_type" name="item_type">
<option value="cpu">Processor</option>
<option value="motherboard">Motherboard</option>
<option value="memory">Memory (RAM)</option>
<option value="psu">Power Supply</option>
<option value="case">Case</option>
<option value="storage">Storage Device</option>
<option value="gpu">Graphics Card</option>
</select>
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</div>
{{ template "layout_footer" . }}

11
views/item/list.html Normal file
View File

@ -0,0 +1,11 @@
{{ template "layout_header" . }}
<p><a href="/item/create">Create new item</a></p>
<ul>
{{ range .inventory }}
<li>{{ .name }}</li>
{{ end }}
</ul>
{{ template "layout_footer" . }}

5
views/layout/footer.html Normal file
View File

@ -0,0 +1,5 @@
{{ define "layout_footer" }}
</div>
</body>
</html>
{{ end }}

View File

@ -1,11 +1,11 @@
{{ define "layout" }}
{{ define "layout_header" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ block "title" . }}{{ end }} | Raven</title>
<title>{{ .title }} | Raven</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="/css/kraken.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
@ -14,8 +14,4 @@
{{ template "navbar" . }}
<div id="main-wrapper" class="container">
{{ block "content" . }}{{ end }}
</div>
</body>
</html>
{{ end }}