left menus now dynamically generated
This commit is contained in:
@@ -54,6 +54,7 @@ func main() {
|
|||||||
defer database.ClosedownDb()
|
defer database.ClosedownDb()
|
||||||
ui.SetupTemplates()
|
ui.SetupTemplates()
|
||||||
ui.SetupSessionManager()
|
ui.SetupSessionManager()
|
||||||
|
ui.SetupLeftMenus()
|
||||||
|
|
||||||
// Set up Echo.
|
// Set up Echo.
|
||||||
e := setupEcho()
|
e := setupEcho()
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
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 {
|
type AmContext interface {
|
||||||
CurrentUser() *database.User
|
CurrentUser() *database.User
|
||||||
RC() int
|
RC() int
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ func sendPageData(ctxt echo.Context, amctxt AmContext, command string, data any)
|
|||||||
err = amctxt.Render(fmt.Sprintf("%v", data))
|
err = amctxt.Render(fmt.Sprintf("%v", data))
|
||||||
case "framed_template":
|
case "framed_template":
|
||||||
amctxt.VarMap().Set("amsterdam_innerPage", data)
|
amctxt.VarMap().Set("amsterdam_innerPage", data)
|
||||||
|
augmentWithLeftMenus(amctxt)
|
||||||
err = amctxt.Render("frame.jet")
|
err = amctxt.Render("frame.jet")
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("unknown rendering type: %s", command)
|
err = fmt.Errorf("unknown rendering type: %s", command)
|
||||||
|
|||||||
+11
-14
@@ -75,21 +75,18 @@
|
|||||||
<div class="flex">
|
<div class="flex">
|
||||||
<!-- LEFT SIDEBAR -->
|
<!-- LEFT SIDEBAR -->
|
||||||
<div class="w-32 bg-blue-400 p-2">
|
<div class="w-32 bg-blue-400 p-2">
|
||||||
<div class="mb-4">
|
{{ range amsterdam_leftMenus }}
|
||||||
<div class="text-black text-sm">
|
<div class="mb-2 mt-2">
|
||||||
<div class="font-bold mb-1">Front Page</div>
|
<div class="font-bold mb-1">{{ .Title }}</div>
|
||||||
<div class="text-gray-500 mb-1">Calendar</div>
|
{{ range .Items }}
|
||||||
<div class="text-gray-500">Chat</div>
|
{{ 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>
|
{{ end }}
|
||||||
|
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- MAIN CONTENT -->
|
<!-- MAIN CONTENT -->
|
||||||
|
|||||||
Reference in New Issue
Block a user