From 533d5b173fd6862802ecf3ad770a64f787564932 Mon Sep 17 00:00:00 2001 From: Robert Janetzko Date: Tue, 26 Apr 2022 18:06:21 +0000 Subject: [PATCH] fix context --- backend/model/context.go | 2 +- backend/model/eventList.go | 5 ++++- backend/server/resource.go | 9 +-------- backend/server/server.go | 3 +-- backend/server/templates.go | 1 - backend/templates/events.html | 5 +---- backend/templates/templates.go | 11 +---------- 7 files changed, 9 insertions(+), 27 deletions(-) diff --git a/backend/model/context.go b/backend/model/context.go index eae8af1..5d82517 100644 --- a/backend/model/context.go +++ b/backend/model/context.go @@ -35,7 +35,7 @@ func (c *Context) hfShort(id int) string { } func (c *Context) hfRelated(id, to int) string { - if c.HfId != -1 { + if c.HfId != -1 && to != c.HfId { if c.HfId == id { return c.hfShort(id) } else { diff --git a/backend/model/eventList.go b/backend/model/eventList.go index 0ba0d0f..1d46c1d 100644 --- a/backend/model/eventList.go +++ b/backend/model/eventList.go @@ -24,7 +24,10 @@ type EventList struct { func NewEventList(world *DfWorld, obj any) *EventList { el := EventList{ - Context: &Context{HfId: -1}, + Context: &Context{ + World: world, + HfId: -1, + }, } switch x := obj.(type) { diff --git a/backend/server/resource.go b/backend/server/resource.go index 6ec2cbc..a4d7c41 100644 --- a/backend/server/resource.go +++ b/backend/server/resource.go @@ -7,8 +7,6 @@ import ( "strconv" "github.com/gorilla/mux" - "github.com/robertjanetzko/LegendsBrowser2/backend/model" - "github.com/robertjanetzko/LegendsBrowser2/backend/templates" ) type Parms map[string]string @@ -32,12 +30,7 @@ func (srv *DfServer) RegisterWorldPage(path string, template string, accessor fu return } - td := &templates.TemplateData{ - Context: &model.Context{World: srv.context.world}, - Data: accessor(mux.Vars(r)), - } - - err := srv.templates.Render(w, template, td) + err := srv.templates.Render(w, template, accessor(mux.Vars(r))) if err != nil { fmt.Fprintln(w, err) fmt.Println(err) diff --git a/backend/server/server.go b/backend/server/server.go index ab92f71..512a4cc 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -72,7 +72,6 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // } // prepend the path with the path to the static directory path = h.staticPath + path - fmt.Println(r.URL, "->", path) _, err := h.staticFS.Open(path) if os.IsNotExist(err) { @@ -125,7 +124,7 @@ func (h loadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Println(err) } - err = h.server.templates.Render(w, "load.html", &templates.TemplateData{Data: p}) + err = h.server.templates.Render(w, "load.html", p) if err != nil { fmt.Fprintln(w, err) fmt.Println(err) diff --git a/backend/server/templates.go b/backend/server/templates.go index 796fa1c..15877dc 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -29,7 +29,6 @@ func (srv *DfServer) LoadTemplates() { "region": func(id int) template.HTML { return model.LinkRegion(srv.context.world, id) }, "getRegion": func(id int) *model.Region { return srv.context.world.Regions[id] }, "events": func(obj any) *model.EventList { - fmt.Println("W", srv.context.world) return model.NewEventList(srv.context.world, obj) }, "season": model.Season, diff --git a/backend/templates/events.html b/backend/templates/events.html index 8714faf..c2322b4 100644 --- a/backend/templates/events.html +++ b/backend/templates/events.html @@ -1,8 +1,5 @@ -Eventss -{{ json .Context }} -