added frame metadata to AmContext and used that to replace the amsterdam_genRefresh variable
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"git.erbosoft.com/amy/amsterdam/database"
|
"git.erbosoft.com/amy/amsterdam/database"
|
||||||
"git.erbosoft.com/amy/amsterdam/ui"
|
"git.erbosoft.com/amy/amsterdam/ui"
|
||||||
"github.com/CloudyKit/jet/v6"
|
"github.com/CloudyKit/jet/v6"
|
||||||
@@ -268,7 +269,9 @@ func TopPage(ctxt ui.AmContext) (string, any) {
|
|||||||
|
|
||||||
// Final data set.
|
// Final data set.
|
||||||
ctxt.SetLeftMenu("top")
|
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"
|
return "framed", "top.jet"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
// AmContext is the interface for Amsterdam's wrapper context that exposes the required functionality.
|
||||||
type AmContext interface {
|
type AmContext interface {
|
||||||
|
AddFrameMetadata(int, string, string)
|
||||||
AddHeader(string, string)
|
AddHeader(string, string)
|
||||||
ClearCommunityContext()
|
ClearCommunityContext()
|
||||||
ClearLoginCookie()
|
ClearLoginCookie()
|
||||||
@@ -47,6 +52,7 @@ type AmContext interface {
|
|||||||
FormFieldIsSet(string) bool
|
FormFieldIsSet(string) bool
|
||||||
FormFile(string) (*multipart.FileHeader, error)
|
FormFile(string) (*multipart.FileHeader, error)
|
||||||
FrameTitle() string
|
FrameTitle() string
|
||||||
|
FrameMetadata(int) map[string]string
|
||||||
Globals() *database.Globals
|
Globals() *database.Globals
|
||||||
GlobalFlags() *util.OptionSet
|
GlobalFlags() *util.OptionSet
|
||||||
HasParameter(string) bool
|
HasParameter(string) bool
|
||||||
@@ -88,6 +94,7 @@ type amContext struct {
|
|||||||
echoContext echo.Context
|
echoContext echo.Context
|
||||||
rendervars jet.VarMap
|
rendervars jet.VarMap
|
||||||
frameTitle string
|
frameTitle string
|
||||||
|
frameMeta map[int]map[string]string
|
||||||
outputType string
|
outputType string
|
||||||
session AmSession
|
session AmSession
|
||||||
globals *database.Globals
|
globals *database.Globals
|
||||||
@@ -99,6 +106,16 @@ type amContext struct {
|
|||||||
isMemberLocked bool
|
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.
|
// AddHeader adds a header to the response.
|
||||||
func (c *amContext) AddHeader(key, value string) {
|
func (c *amContext) AddHeader(key, value string) {
|
||||||
c.echoContext.Response().Header().Add(key, value)
|
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)
|
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.
|
// FrameTitle returns the frame title.
|
||||||
func (c *amContext) FrameTitle() string {
|
func (c *amContext) FrameTitle() string {
|
||||||
return c.frameTitle
|
return c.frameTitle
|
||||||
@@ -471,6 +497,7 @@ func newContext(ctxt echo.Context) (*amContext, error) {
|
|||||||
rc = &amContext{
|
rc = &amContext{
|
||||||
rendervars: make(jet.VarMap),
|
rendervars: make(jet.VarMap),
|
||||||
frameTitle: "",
|
frameTitle: "",
|
||||||
|
frameMeta: make(map[int]map[string]string),
|
||||||
outputType: "",
|
outputType: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -546,6 +573,7 @@ func contextRecycler(incoming chan *amContext, done chan bool) {
|
|||||||
c.echoContext = nil
|
c.echoContext = nil
|
||||||
c.rendervars = make(jet.VarMap)
|
c.rendervars = make(jet.VarMap)
|
||||||
c.frameTitle = ""
|
c.frameTitle = ""
|
||||||
|
c.frameMeta = make(map[int]map[string]string)
|
||||||
c.outputType = ""
|
c.outputType = ""
|
||||||
c.session = nil
|
c.session = nil
|
||||||
c.globals = nil
|
c.globals = nil
|
||||||
|
|||||||
+2
-2
@@ -14,8 +14,8 @@
|
|||||||
<title>{{ .FrameTitle() | raw }} - {{ GlobalConfig.Site.Title }}</title>
|
<title>{{ .FrameTitle() | raw }} - {{ GlobalConfig.Site.Title }}</title>
|
||||||
<link rel="icon" href="/img/builtin/AmsterdamIcon32.png" type="image/png" />
|
<link rel="icon" href="/img/builtin/AmsterdamIcon32.png" type="image/png" />
|
||||||
<link rel="shortcut icon" href="/img/builtin/AmsterdamIcon32.ico" />
|
<link rel="shortcut icon" href="/img/builtin/AmsterdamIcon32.ico" />
|
||||||
{{ if isset(amsterdam_genRefresh) && GlobalConfig.Site.TopRefresh > 0 }}
|
{{ range k, v := .FrameMetadata(0) }}
|
||||||
<meta http-equiv="refresh" content="{{ GlobalConfig.Site.TopRefresh }}">
|
<meta http-equiv="{{ k }}" content="{{ v }}">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<link rel="stylesheet" href="/static/css/ams_style.css" />
|
<link rel="stylesheet" href="/static/css/ams_style.css" />
|
||||||
|
|||||||
Reference in New Issue
Block a user