added frame metadata to AmContext and used that to replace the amsterdam_genRefresh variable

This commit is contained in:
2026-02-10 21:36:12 -07:00
parent be5255b4e7
commit 2e7474168b
3 changed files with 34 additions and 3 deletions
+4 -1
View File
@@ -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"
}
+28
View File
@@ -31,8 +31,13 @@ import (
*----------------------------------------------------------------------------
*/
const (
FrameMetaHttpEquiv = 0 // <meta http-equiv="...">
)
// 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
+2 -2
View File
@@ -14,8 +14,8 @@
<title>{{ .FrameTitle() | raw }} - {{ GlobalConfig.Site.Title }}</title>
<link rel="icon" href="/img/builtin/AmsterdamIcon32.png" type="image/png" />
<link rel="shortcut icon" href="/img/builtin/AmsterdamIcon32.ico" />
{{ if isset(amsterdam_genRefresh) && GlobalConfig.Site.TopRefresh > 0 }}
<meta http-equiv="refresh" content="{{ GlobalConfig.Site.TopRefresh }}">
{{ range k, v := .FrameMetadata(0) }}
<meta http-equiv="{{ k }}" content="{{ v }}">
{{ end }}
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="/static/css/ams_style.css" />