added external references for menus and message boxes too
This commit is contained in:
+7
-5
@@ -105,11 +105,13 @@ type AmConfig struct {
|
||||
VeniceCompatibleImageURLs bool `yaml:"veniceCompatibleImageURLs"`
|
||||
} `yaml:"rendering"`
|
||||
Resources struct {
|
||||
ViewTemplateDir string `yaml:"viewTemplateDir"`
|
||||
DialogTemplateDir string `yaml:"dialogTemplateDir"`
|
||||
EmailTemplateDir string `yaml:"emailTemplateDir"`
|
||||
ExternalContentPath string `yaml:"externalContentPath"`
|
||||
ExternalResourcePath string `yaml:"externalResourcePath"`
|
||||
ViewTemplateDir string `yaml:"viewTemplateDir"`
|
||||
DialogTemplateDir string `yaml:"dialogTemplateDir"`
|
||||
EmailTemplateDir string `yaml:"emailTemplateDir"`
|
||||
ExternalContentPath string `yaml:"externalContentPath"`
|
||||
ExternalResourcePath string `yaml:"externalResourcePath"`
|
||||
ExternalMenuDefinitions string `yaml:"externalMenuDefinitions"`
|
||||
ExternalMessageDefinitions string `yaml:"externalMessageDefinitions"`
|
||||
} `yaml:"resources"`
|
||||
Posting struct {
|
||||
ExternalDictionary string `yaml:"externalDictionary"`
|
||||
|
||||
@@ -55,6 +55,8 @@ resources:
|
||||
emailTemplateDir: ""
|
||||
externalContentPath: ""
|
||||
externalResourcePath: ""
|
||||
externalMenuDefinitions: ""
|
||||
externalMessageDefinitions: ""
|
||||
posting:
|
||||
externalDictionary: ""
|
||||
uploads:
|
||||
|
||||
+23
-2
@@ -13,6 +13,7 @@ import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"git.erbosoft.com/amy/amsterdam/util"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -156,12 +158,31 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// setupMenuCache sets up the menu cache.
|
||||
func setupMenuCache() {
|
||||
// setupMenus sets up the menu cache and the external menus.
|
||||
func setupMenus() {
|
||||
var err error
|
||||
if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if config.GlobalConfig.Resources.ExternalMenuDefinitions != "" {
|
||||
b, err := os.ReadFile(config.GlobalConfig.Resources.ExternalMenuDefinitions)
|
||||
if err == nil {
|
||||
md := new(MenuDefs)
|
||||
err = yaml.Unmarshal(b, md)
|
||||
if err == nil {
|
||||
for i, d := range md.D {
|
||||
menuDefinitions.table[d.ID] = &(md.D[i])
|
||||
for j := range md.D[i].Items {
|
||||
md.D[i].Items[j].P = &(md.D[i])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Errorf("cannot parse external menu definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMenuDefinitions, err)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("cannot read external menu definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMenuDefinitions, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AmMenu returns a menu definition.
|
||||
|
||||
@@ -15,9 +15,12 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/util"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -80,6 +83,33 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// setupMessageBoxes loads external message box definitions.
|
||||
func setupMessageBoxes() {
|
||||
if config.GlobalConfig.Resources.ExternalMessageDefinitions != "" {
|
||||
b, err := os.ReadFile(config.GlobalConfig.Resources.ExternalMessageDefinitions)
|
||||
if err == nil {
|
||||
mb := new(MessageBoxDefs)
|
||||
err = yaml.Unmarshal(b, mb)
|
||||
if err == nil {
|
||||
for i, def := range mb.D {
|
||||
messageBoxDefs.table[def.Id] = &(mb.D[i])
|
||||
mb.D[i].useConfirm = false
|
||||
for _, b := range mb.D[i].Buttons {
|
||||
if b.Confirm {
|
||||
mb.D[i].useConfirm = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Errorf("cannot parse external message definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMessageDefinitions, err)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("cannot read external message definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMessageDefinitions, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MessageBox is the structure for a working message box.
|
||||
type MessageBox struct {
|
||||
def *MessageBoxDefinition
|
||||
|
||||
+2
-1
@@ -17,7 +17,8 @@ func SetupUILayer() func() {
|
||||
exitfuncs := make([]func(), 0, 2)
|
||||
setupTemplates()
|
||||
setupDialogs()
|
||||
setupMenuCache()
|
||||
setupMenus()
|
||||
setupMessageBoxes()
|
||||
setupResources()
|
||||
exitfuncs = append(exitfuncs, setupSessionManager())
|
||||
exitfuncs = append(exitfuncs, setupContext())
|
||||
|
||||
Reference in New Issue
Block a user