diff options
author | Matthew Lemon <y@yulqen.org> | 2024-02-12 04:50:44 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-02-12 04:50:44 +0000 |
commit | fbf0f6250dadf3fb3ba70b8b8f40b2c265b09939 (patch) | |
tree | 4b312e2d8e2e9dacaa4458dfce35a6c5ea699047 | |
parent | 7d131bea17205c314387700787286365cbd98d5a (diff) |
An Operations list page now renders data in table
The data is fetched from the database and uses html/template to render
the rows in a list.
A critical bug was not including the dot in {{ template "main" . }} in
the base template. THIS MEANT THAT NO DATA PASSED TO ExecuteTemplate
function rendered and took a long time to figure out.
-rw-r--r-- | cmd/web/handlers.go | 4 | ||||
-rw-r--r-- | cmd/web/routes.go | 2 | ||||
-rw-r--r-- | ui/html/base.tmpl.html | 2 | ||||
-rw-r--r-- | ui/html/pages/operations/list.tmpl.html | 35 | ||||
-rw-r--r-- | ui/static/css/main.css | 1 |
5 files changed, 15 insertions, 29 deletions
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 40ca509..e27b39b 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "html/template" - "log" "net/http" "strconv" @@ -34,7 +33,6 @@ func (app *application) listOperations(w http.ResponseWriter, r *http.Request) { data := operationsTemplateData{ Operations: ops, } - log.Println(data) err = ts.ExecuteTemplate(w, "base", data) if err != nil { @@ -42,7 +40,7 @@ func (app *application) listOperations(w http.ResponseWriter, r *http.Request) { } } -func (app *application) listOrganisation(w http.ResponseWriter, r *http.Request) { +func (app *application) listOrganisations(w http.ResponseWriter, r *http.Request) { files := []string{ "./ui/html/base.tmpl.html", "./ui/html/pages/organisations/list.tmpl.html", diff --git a/cmd/web/routes.go b/cmd/web/routes.go index e21b25d..d23855a 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -9,7 +9,7 @@ func (app *application) routes() *http.ServeMux { mux.Handle("/static/", http.StripPrefix("/static", fileServer)) mux.HandleFunc("/", app.home) - mux.HandleFunc("/organisation/list", app.listOrganisation) + mux.HandleFunc("/organisation/list", app.listOrganisations) mux.HandleFunc("/organisation/view", app.organisationView) mux.HandleFunc("/organisation/create", app.organisationCreate) mux.HandleFunc("/operation/list", app.listOperations) diff --git a/ui/html/base.tmpl.html b/ui/html/base.tmpl.html index 91bdbc2..58122a0 100644 --- a/ui/html/base.tmpl.html +++ b/ui/html/base.tmpl.html @@ -14,7 +14,7 @@ {{ template "nav" . }} </header> <main> - {{ template "main" }} + {{ template "main" . }} <!-- DONT FORGET THE DOT!!! --> </main> </body> </html> diff --git a/ui/html/pages/operations/list.tmpl.html b/ui/html/pages/operations/list.tmpl.html index 046ca29..a8685ce 100644 --- a/ui/html/pages/operations/list.tmpl.html +++ b/ui/html/pages/operations/list.tmpl.html @@ -3,44 +3,33 @@ {{ define "main" }} <h3>Operations <span><a href="#" class="admin-link">[Admin]</a></span></h3> - {{if .Operations}} - <ul> - {{range .Operations}} - <li>{{.Name}} - {{.Description}}</li> - {{end}} - </ul> - {{else}} - <p>There are no operations.</p> - {{end}} - +{{if .Operations}} <table id="home-summary-table"> <thead> <tr id="header-row"> <th>Operation</th> <th>RP</th> <th>Lead Inspector[s]</th> - <th>Another attribute</th> - <th>Another attribute</th> + <th>Description</th> + <th>Organisation</th> <th>SharePoint</th> </tr> </thead> <tbody> + {{range .Operations }} <tr> - <td><a href="#">First operation</a></td> + <td><a href="#">{{.Name}}</a></td> <td>Tim Gudgeon</td> <td>Tina McKinchey / Barbara Snelland</td> - <td>Bobbins</td> - <td>Bobbins</td> - <td><a href="#">Link</a></td> - </tr> - <tr> - <td>Second organisation</td> - <td>Seth Pring</td> - <td>Barbara Snelland</td> - <td>Bobbins</td> - <td>Bobbins</td> + <td>{{.Description}}</td> + <td>{{.OrganisationName}}</td> <td><a href="#">Link</a></td> </tr> + {{end}} </tbody> </table> +{{else}} + <p>There are no operations.</p> +{{end}} + {{ end }} diff --git a/ui/static/css/main.css b/ui/static/css/main.css index 1760fba..d8060bd 100644 --- a/ui/static/css/main.css +++ b/ui/static/css/main.css @@ -23,7 +23,6 @@ a:hover { a.admin-link { font-size: 0.65rem; - padding: 0em 0em 1.2em 0em; } |