left menus now dynamically generated

This commit is contained in:
2025-09-22 17:01:39 -06:00
parent 93aa6bd0ba
commit 46838e8f21
5 changed files with 66 additions and 15 deletions
+1 -1
View File
@@ -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
+52
View File
@@ -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)
}
+1
View File
@@ -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)
+11 -14
View File
@@ -75,21 +75,18 @@
<div class="flex">
<!-- LEFT SIDEBAR -->
<div class="w-32 bg-blue-400 p-2">
<div class="mb-4">
<div class="text-black text-sm">
<div class="font-bold mb-1">Front Page</div>
<div class="text-gray-500 mb-1">Calendar</div>
<div class="text-gray-500">Chat</div>
{{ range amsterdam_leftMenus }}
<div class="mb-2 mt-2">
<div class="font-bold mb-1">{{ .Title }}</div>
{{ range .Items }}
{{ if .Link != "" }}
<a href="{{ .Link }}" class="text-blue-700 hover:text-blue-900">{{ .Text }}</a>
{{ else }}
<div class="text-gray-500 mb-1">{{ .Text }}</div>
{{ end }}
{{ end }}
</div>
</div>
<div class="mt-4">
<div class="text-black text-sm">
<div class="font-bold mb-1">About This Site</div>
<div class="text-gray-500 mb-1">Documentation</div>
<a href="/about" class="text-blue-700 hover:text-blue-900">About Amsterdam</a>
</div>
</div>
{{ end }}
</div>
<!-- MAIN CONTENT -->