summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/web/handlers.go20
-rw-r--r--cmd/web/templates.go5
-rw-r--r--ui/html/pages/organisations_list.tmpl.html2
3 files changed, 13 insertions, 14 deletions
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go
index 4d90469..b487eca 100644
--- a/cmd/web/handlers.go
+++ b/cmd/web/handlers.go
@@ -3,7 +3,6 @@ package main
import (
"errors"
"fmt"
- "html/template"
"net/http"
"strconv"
@@ -40,22 +39,19 @@ func (app *application) listOperations(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",
- "./ui/html/partials/nav.tmpl.html",
- }
- ts, err := template.ParseFiles(files...)
+ latest, err := app.organisations.Latest()
if err != nil {
- app.serverError(w, r, err) // Use the serverError() helper
+ app.serverError(w, r, err)
return
}
- err = ts.ExecuteTemplate(w, "base", nil)
- if err != nil {
- app.serverError(w, r, err) // Use the serverError() helper
- }
+ // We are putting latest in the Organisations field of templateData and leaving
+ // templateData.Operations as the nil value because we don't need Operations in this
+ // page, of course.
+ app.render(w, r, http.StatusOK, "organisations_list.tmpl.html", templateData{
+ Organisations: latest,
+ })
}
func (app *application) home(w http.ResponseWriter, r *http.Request) {
diff --git a/cmd/web/templates.go b/cmd/web/templates.go
index 2457053..8cfa424 100644
--- a/cmd/web/templates.go
+++ b/cmd/web/templates.go
@@ -7,8 +7,11 @@ import (
"github.com/yulqen/ded-go-core/internal/models"
)
+// TODO: At the moment we are using a struct will have fields for all the data
+// we will need. Not sure whether this is good or bad at the moment.
type templateData struct {
- Operations []models.Operation
+ Operations []models.Operation
+ Organisations []models.Organisation
}
func newTemplateCache() (map[string]*template.Template, error) {
diff --git a/ui/html/pages/organisations_list.tmpl.html b/ui/html/pages/organisations_list.tmpl.html
index 1b0e3a9..edf1f89 100644
--- a/ui/html/pages/organisations_list.tmpl.html
+++ b/ui/html/pages/organisations_list.tmpl.html
@@ -2,7 +2,7 @@
{{ define "main" }}
<h3>Organisations <span><a href="#" class="admin-link">[Admin]</a></span></h3>
-<p>There is nothing to see here yet.</p>
+{{.Organisations}}
<table id="home-summary-table">
<thead>
<tr id="header-row">