diff --git a/main.go b/main.go index 0cc8850..e00132b 100644 --- a/main.go +++ b/main.go @@ -54,6 +54,7 @@ func main() { defer database.ClosedownDb() ui.SetupTemplates() ui.SetupSessionManager() + ui.SetupLeftMenus() // Set up Echo. e := setupEcho() diff --git a/ui/amcontext.go b/ui/amcontext.go index a4f3870..cd4263a 100644 --- a/ui/amcontext.go +++ b/ui/amcontext.go @@ -22,7 +22,7 @@ import ( log "github.com/sirupsen/logrus" ) -// AmContext is the interface for Amsterdam's wapper context that exposes the required functionality. +// AmContext is the interface for Amsterdam's wrapper context that exposes the required functionality. type AmContext interface { CurrentUser() *database.User RC() int diff --git a/ui/leftmenus.go b/ui/leftmenus.go new file mode 100644 index 0000000..b6b4264 --- /dev/null +++ b/ui/leftmenus.go @@ -0,0 +1,52 @@ +/* + * Amsterdam Web Communities System + * Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ +// Package ui holds the support for the Amsterdam user interface, wrapping Echo and Jet templates. +package ui + +// AmLeftMenuItem represents an item on a left menu. +type AmLeftMenuItem struct { + Text string + Link string +} + +// AmLeftMenu represents a left menu. +type AmLeftMenu struct { + Title string + Items []AmLeftMenuItem +} + +// leftMenusRepo holds the possible left menus. +var leftMenusRepo = map[string]AmLeftMenu{} + +// SetupLeftMenus parses the left menus into internal data structures. +func SetupLeftMenus() { + // "Front Page" menu (not community specific) + menu := AmLeftMenu{Title: "Front Page", Items: make([]AmLeftMenuItem, 2)} + menu.Items[0] = AmLeftMenuItem{Text: "Calendar", Link: ""} + menu.Items[1] = AmLeftMenuItem{Text: "Chat", Link: ""} + leftMenusRepo["fp"] = menu + + // "About" menu (global) + menu = AmLeftMenu{Title: "About This Site", Items: make([]AmLeftMenuItem, 2)} + menu.Items[0] = AmLeftMenuItem{Text: "Documentation", Link: ""} + menu.Items[1] = AmLeftMenuItem{Text: "About Amsterdam", Link: "/about"} + leftMenusRepo["about"] = menu +} + +/* augmentWithLeftMenus adds the left menus to the Amsterdam context. + * Parameters: + * ctxt - The context to add the menus to. + */ +func augmentWithLeftMenus(ctxt AmContext) { + mlist := make([]AmLeftMenu, 0, len(leftMenusRepo)) + // TODO: check for "in community" status and select menu + mlist = append(mlist, leftMenusRepo["fp"]) + mlist = append(mlist, leftMenusRepo["about"]) + ctxt.VarMap().Set("amsterdam_leftMenus", mlist) +} diff --git a/ui/render_wrap.go b/ui/render_wrap.go index 695eaa5..f026d0c 100644 --- a/ui/render_wrap.go +++ b/ui/render_wrap.go @@ -27,6 +27,7 @@ func sendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) err = amctxt.Render(fmt.Sprintf("%v", data)) case "framed_template": amctxt.VarMap().Set("amsterdam_innerPage", data) + augmentWithLeftMenus(amctxt) err = amctxt.Render("frame.jet") default: err = fmt.Errorf("unknown rendering type: %s", command) diff --git a/ui/views/frame.jet b/ui/views/frame.jet index 3f3397c..ac8ecd4 100644 --- a/ui/views/frame.jet +++ b/ui/views/frame.jet @@ -75,21 +75,18 @@
-
-
-
Front Page
-
Calendar
-
Chat
+ {{ range amsterdam_leftMenus }} +
+
{{ .Title }}
+ {{ range .Items }} + {{ if .Link != "" }} + {{ .Text }} + {{ else }} +
{{ .Text }}
+ {{ end }} + {{ end }}
-
- -
-
-
About This Site
-
Documentation
- About Amsterdam -
-
+ {{ end }}