added external references for menus and message boxes too
This commit is contained in:
@@ -110,6 +110,8 @@ type AmConfig struct {
|
|||||||
EmailTemplateDir string `yaml:"emailTemplateDir"`
|
EmailTemplateDir string `yaml:"emailTemplateDir"`
|
||||||
ExternalContentPath string `yaml:"externalContentPath"`
|
ExternalContentPath string `yaml:"externalContentPath"`
|
||||||
ExternalResourcePath string `yaml:"externalResourcePath"`
|
ExternalResourcePath string `yaml:"externalResourcePath"`
|
||||||
|
ExternalMenuDefinitions string `yaml:"externalMenuDefinitions"`
|
||||||
|
ExternalMessageDefinitions string `yaml:"externalMessageDefinitions"`
|
||||||
} `yaml:"resources"`
|
} `yaml:"resources"`
|
||||||
Posting struct {
|
Posting struct {
|
||||||
ExternalDictionary string `yaml:"externalDictionary"`
|
ExternalDictionary string `yaml:"externalDictionary"`
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ resources:
|
|||||||
emailTemplateDir: ""
|
emailTemplateDir: ""
|
||||||
externalContentPath: ""
|
externalContentPath: ""
|
||||||
externalResourcePath: ""
|
externalResourcePath: ""
|
||||||
|
externalMenuDefinitions: ""
|
||||||
|
externalMessageDefinitions: ""
|
||||||
posting:
|
posting:
|
||||||
externalDictionary: ""
|
externalDictionary: ""
|
||||||
uploads:
|
uploads:
|
||||||
|
|||||||
+23
-2
@@ -13,6 +13,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -22,6 +23,7 @@ import (
|
|||||||
"git.erbosoft.com/amy/amsterdam/database"
|
"git.erbosoft.com/amy/amsterdam/database"
|
||||||
"git.erbosoft.com/amy/amsterdam/util"
|
"git.erbosoft.com/amy/amsterdam/util"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -156,12 +158,31 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupMenuCache sets up the menu cache.
|
// setupMenus sets up the menu cache and the external menus.
|
||||||
func setupMenuCache() {
|
func setupMenus() {
|
||||||
var err error
|
var err error
|
||||||
if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil {
|
if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil {
|
||||||
panic(err)
|
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.
|
// AmMenu returns a menu definition.
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"git.erbosoft.com/amy/amsterdam/util"
|
"git.erbosoft.com/amy/amsterdam/util"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v3"
|
"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.
|
// MessageBox is the structure for a working message box.
|
||||||
type MessageBox struct {
|
type MessageBox struct {
|
||||||
def *MessageBoxDefinition
|
def *MessageBoxDefinition
|
||||||
|
|||||||
+2
-1
@@ -17,7 +17,8 @@ func SetupUILayer() func() {
|
|||||||
exitfuncs := make([]func(), 0, 2)
|
exitfuncs := make([]func(), 0, 2)
|
||||||
setupTemplates()
|
setupTemplates()
|
||||||
setupDialogs()
|
setupDialogs()
|
||||||
setupMenuCache()
|
setupMenus()
|
||||||
|
setupMessageBoxes()
|
||||||
setupResources()
|
setupResources()
|
||||||
exitfuncs = append(exitfuncs, setupSessionManager())
|
exitfuncs = append(exitfuncs, setupSessionManager())
|
||||||
exitfuncs = append(exitfuncs, setupContext())
|
exitfuncs = append(exitfuncs, setupContext())
|
||||||
|
|||||||
Reference in New Issue
Block a user