diff --git a/top.go b/top.go index 5f9d464..9af3396 100644 --- a/top.go +++ b/top.go @@ -14,6 +14,7 @@ import ( "net/http" "reflect" + "git.erbosoft.com/amy/amsterdam/config" "git.erbosoft.com/amy/amsterdam/database" "git.erbosoft.com/amy/amsterdam/ui" "github.com/CloudyKit/jet/v6" @@ -268,7 +269,9 @@ func TopPage(ctxt ui.AmContext) (string, any) { // Final data set. ctxt.SetLeftMenu("top") - ctxt.VarMap().Set("amsterdam_genRefresh", true) + if config.GlobalConfig.Site.TopRefresh > 0 { + ctxt.AddFrameMetadata(ui.FrameMetaHttpEquiv, "refresh", fmt.Sprintf("%d", config.GlobalConfig.Site.TopRefresh)) + } return "framed", "top.jet" } diff --git a/ui/amcontext.go b/ui/amcontext.go index 9cc3a03..cf1bad0 100644 --- a/ui/amcontext.go +++ b/ui/amcontext.go @@ -31,8 +31,13 @@ import ( *---------------------------------------------------------------------------- */ +const ( + FrameMetaHttpEquiv = 0 // +) + // AmContext is the interface for Amsterdam's wrapper context that exposes the required functionality. type AmContext interface { + AddFrameMetadata(int, string, string) AddHeader(string, string) ClearCommunityContext() ClearLoginCookie() @@ -47,6 +52,7 @@ type AmContext interface { FormFieldIsSet(string) bool FormFile(string) (*multipart.FileHeader, error) FrameTitle() string + FrameMetadata(int) map[string]string Globals() *database.Globals GlobalFlags() *util.OptionSet HasParameter(string) bool @@ -88,6 +94,7 @@ type amContext struct { echoContext echo.Context rendervars jet.VarMap frameTitle string + frameMeta map[int]map[string]string outputType string session AmSession globals *database.Globals @@ -99,6 +106,16 @@ type amContext struct { isMemberLocked bool } +// AddFrameMetadata adds frame metadata of specified types. +func (c *amContext) AddFrameMetadata(selector int, name string, value string) { + mv, ok := c.frameMeta[selector] + if !ok { + mv = make(map[string]string) + c.frameMeta[selector] = mv + } + mv[name] = value +} + // AddHeader adds a header to the response. func (c *amContext) AddHeader(key, value string) { c.echoContext.Response().Header().Add(key, value) @@ -222,6 +239,15 @@ func (c *amContext) FormFile(name string) (*multipart.FileHeader, error) { return c.echoContext.FormFile(name) } +// FrameMetadata returns the frame metadata for a specified type. +func (c *amContext) FrameMetadata(selector int) map[string]string { + rmap, ok := c.frameMeta[selector] + if !ok { + rmap = make(map[string]string) + } + return rmap +} + // FrameTitle returns the frame title. func (c *amContext) FrameTitle() string { return c.frameTitle @@ -471,6 +497,7 @@ func newContext(ctxt echo.Context) (*amContext, error) { rc = &amContext{ rendervars: make(jet.VarMap), frameTitle: "", + frameMeta: make(map[int]map[string]string), outputType: "", } } @@ -546,6 +573,7 @@ func contextRecycler(incoming chan *amContext, done chan bool) { c.echoContext = nil c.rendervars = make(jet.VarMap) c.frameTitle = "" + c.frameMeta = make(map[int]map[string]string) c.outputType = "" c.session = nil c.globals = nil diff --git a/ui/views/frame.jet b/ui/views/frame.jet index 9de1df6..18df768 100644 --- a/ui/views/frame.jet +++ b/ui/views/frame.jet @@ -14,8 +14,8 @@ {{ .FrameTitle() | raw }} - {{ GlobalConfig.Site.Title }} - {{ if isset(amsterdam_genRefresh) && GlobalConfig.Site.TopRefresh > 0 }} - + {{ range k, v := .FrameMetadata(0) }} + {{ end }}