From aff4790d22728d89e7e2dac8af262c92087b5b39 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 11 Sep 2021 12:27:59 +0200 Subject: Piece evry last week changes together in a big rewrite of the webui --- internal/webui/root.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'internal/webui/root.go') diff --git a/internal/webui/root.go b/internal/webui/root.go index 94f2169..423ba93 100644 --- a/internal/webui/root.go +++ b/internal/webui/root.go @@ -3,18 +3,16 @@ package webui import ( "fmt" "html/template" - "log" "net/http" "git.adyxax.org/adyxax/trains/pkg/model" ) -var rootTemplate = template.Must(template.ParseFS(templatesFS, "html/base.html", "html/root.html")) +var rootTemplate = template.Must(template.New("root").Funcs(funcMap).ParseFS(templatesFS, "html/base.html", "html/root.html")) // The page template variable -type Page struct { - User *model.User - Departures []model.Departure +type RootPage struct { + User *model.User } // The root handler of the webui @@ -25,16 +23,9 @@ func rootHandler(e *env, w http.ResponseWriter, r *http.Request) error { http.Redirect(w, r, "/login", http.StatusFound) return nil } - var departures []model.Departure - if departures, err := e.navitia.GetDepartures(e.conf.TrainStop); err != nil { - log.Printf("%s; data returned: %+v\n", err, departures) - return newStatusError(http.StatusInternalServerError, fmt.Errorf("Could not get departures")) - } else { - w.Header().Set("Cache-Control", "no-store, no-cache") - } - p := Page{ - User: user, - Departures: departures, + w.Header().Set("Cache-Control", "no-store, no-cache") + p := RootPage{ + User: user, } err = rootTemplate.ExecuteTemplate(w, "root.html", p) if err != nil { -- cgit v1.2.3