broke out the generation of the sideboxes
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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/.
|
||||||
|
*/
|
||||||
|
// The database package contains database management and storage logic.
|
||||||
|
package database
|
||||||
|
|
||||||
|
type Sidebox struct {
|
||||||
|
Uid int32 `db:"uid"`
|
||||||
|
Boxid int32 `db:"boxid"`
|
||||||
|
Sequence int32 `db:"sequence"`
|
||||||
|
Param *string `db:"param"`
|
||||||
|
}
|
||||||
|
|
||||||
|
/* AmGetSideboxes returns all the configured sideboxes for a user.
|
||||||
|
* Parameters:
|
||||||
|
* uid = The ID of the user to retrieve sideboxes for.
|
||||||
|
* Returns:
|
||||||
|
* Array of Sidebox structures for the user, or nil
|
||||||
|
* Standard Go error status
|
||||||
|
*/
|
||||||
|
func AmGetSideboxes(uid int32) ([]*Sidebox, error) {
|
||||||
|
stmt, err := amdb.Preparex("SELECT * FROM sideboxes WHERE uid = ? ORDER BY SEQUENCE")
|
||||||
|
if err == nil {
|
||||||
|
defer stmt.Close()
|
||||||
|
rows, err := stmt.Queryx(uid)
|
||||||
|
if err == nil {
|
||||||
|
defer rows.Close()
|
||||||
|
sboxes := make([]*Sidebox, 0, 3)
|
||||||
|
for i := 0; rows.Next(); i++ {
|
||||||
|
box := Sidebox{}
|
||||||
|
rows.StructScan(&box)
|
||||||
|
sboxes = append(sboxes, &box)
|
||||||
|
}
|
||||||
|
if rows.Err() == nil {
|
||||||
|
return sboxes, nil
|
||||||
|
}
|
||||||
|
return nil, rows.Err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
@@ -9,9 +9,73 @@
|
|||||||
// Package main contains the high-level Amsterdam logic.
|
// Package main contains the high-level Amsterdam logic.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "git.erbosoft.com/amy/amsterdam/ui"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/database"
|
||||||
|
"git.erbosoft.com/amy/amsterdam/ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RenderedSideboxItem struct {
|
||||||
|
Text string
|
||||||
|
Link *string
|
||||||
|
Flags []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type RenderedSidebox struct {
|
||||||
|
TemplateName string
|
||||||
|
Title string
|
||||||
|
Subtext *string
|
||||||
|
Items []RenderedSideboxItem
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildFeaturedCommunities(uid int32, out *RenderedSidebox, in *database.Sidebox) error {
|
||||||
|
out.TemplateName = "sb_ftrcomm.jet"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildFeaturedConferences(uid int32, out *RenderedSidebox, in *database.Sidebox) error {
|
||||||
|
out.TemplateName = "sb_ftrconf.jet"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildUsersOnline(uid int32, out *RenderedSidebox, in *database.Sidebox) error {
|
||||||
|
out.TemplateName = "sb_online.jet"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildRenderedSidebox(uid int32, out *RenderedSidebox, in *database.Sidebox) error {
|
||||||
|
switch in.Boxid {
|
||||||
|
case 1:
|
||||||
|
return buildFeaturedCommunities(uid, out, in)
|
||||||
|
case 2:
|
||||||
|
return buildFeaturedConferences(uid, out, in)
|
||||||
|
case 3:
|
||||||
|
return buildUsersOnline(uid, out, in)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown sidebox boxid: %d", in.Boxid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TopPage(ctxt ui.AmContext) (string, any, error) {
|
func TopPage(ctxt ui.AmContext) (string, any, error) {
|
||||||
|
// Set the page title.
|
||||||
ctxt.VarMap().Set("amsterdam_pageTitle", "My Front Page")
|
ctxt.VarMap().Set("amsterdam_pageTitle", "My Front Page")
|
||||||
|
|
||||||
|
// Retrieve the sideboxes and create the data to be presented.
|
||||||
|
uid := ctxt.Session().Values["user_id"].(int32)
|
||||||
|
sboxes, err := database.AmGetSideboxes(uid)
|
||||||
|
if err != nil {
|
||||||
|
return "string", "Unable to retrieve sideboxes", err
|
||||||
|
}
|
||||||
|
|
||||||
|
rc := make([]RenderedSidebox, len(sboxes))
|
||||||
|
for i, sb := range sboxes {
|
||||||
|
err = buildRenderedSidebox(uid, &(rc[i]), sb)
|
||||||
|
if err != nil {
|
||||||
|
return "string", "Unable to render sideboxes", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt.VarMap().Set("sideboxes", rc)
|
||||||
return "framed_template", "top.jet", nil
|
return "framed_template", "top.jet", nil
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-4
@@ -28,11 +28,12 @@ type AmContext interface {
|
|||||||
RC() int
|
RC() int
|
||||||
OutputType() string
|
OutputType() string
|
||||||
Render(string) error
|
Render(string) error
|
||||||
Scratchpad() map[any]any
|
Scratchpad() map[string]any
|
||||||
SubRender(string) ([]byte, error)
|
SubRender(string) ([]byte, error)
|
||||||
Session() *sessions.Session
|
Session() *sessions.Session
|
||||||
SetOutputType(string)
|
SetOutputType(string)
|
||||||
SetRC(int)
|
SetRC(int)
|
||||||
|
SetScratch(string, any)
|
||||||
URLPath() string
|
URLPath() string
|
||||||
VarMap() jet.VarMap
|
VarMap() jet.VarMap
|
||||||
}
|
}
|
||||||
@@ -43,7 +44,7 @@ type amContext struct {
|
|||||||
httprc int
|
httprc int
|
||||||
rendervars jet.VarMap
|
rendervars jet.VarMap
|
||||||
outputType string
|
outputType string
|
||||||
scratchpad map[any]any
|
scratchpad map[string]any
|
||||||
session *sessions.Session
|
session *sessions.Session
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +78,9 @@ func (c *amContext) Render(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scratchpad returns the per-request scratchpad for values.
|
// Scratchpad returns the per-request scratchpad for values.
|
||||||
func (c *amContext) Scratchpad() map[any]any {
|
func (c *amContext) Scratchpad() map[string]any {
|
||||||
if c.scratchpad == nil {
|
if c.scratchpad == nil {
|
||||||
c.scratchpad = make(map[any]any)
|
c.scratchpad = make(map[string]any)
|
||||||
}
|
}
|
||||||
return c.scratchpad
|
return c.scratchpad
|
||||||
}
|
}
|
||||||
@@ -116,6 +117,13 @@ func (c *amContext) SetRC(rc int) {
|
|||||||
c.httprc = rc
|
c.httprc = rc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *amContext) SetScratch(name string, val any) {
|
||||||
|
if c.scratchpad == nil {
|
||||||
|
c.scratchpad = make(map[string]any)
|
||||||
|
}
|
||||||
|
c.scratchpad[name] = val
|
||||||
|
}
|
||||||
|
|
||||||
// URLPath returns the path component of the request URL.
|
// URLPath returns the path component of the request URL.
|
||||||
func (c *amContext) URLPath() string {
|
func (c *amContext) URLPath() string {
|
||||||
return c.echoContext.Request().URL.Path
|
return c.echoContext.Request().URL.Path
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{*
|
||||||
|
* 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/.
|
||||||
|
*}
|
||||||
|
<!-- Featured Communities -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<div class="bg-blue-600 px-2 py-1 rounded-t">
|
||||||
|
<h3 class="text-white font-bold text-base">Featured Communities:</h3>
|
||||||
|
</div>
|
||||||
|
<div class="bg-blue-400 px-2 py-2 rounded-b">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<span class="mr-2">🟣</span>
|
||||||
|
<a href="http://necrovenice:8080/venice/community/Piazza"
|
||||||
|
class="text-blue-700 hover:text-blue-900 font-bold text-sm">La Piazza</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{*
|
||||||
|
* 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/.
|
||||||
|
*}
|
||||||
|
<!-- Featured Conferences -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<div class="bg-blue-600 px-2 py-1 rounded-t">
|
||||||
|
<h3 class="text-white font-bold text-base">Featured Conferences:</h3>
|
||||||
|
</div>
|
||||||
|
<div class="bg-blue-400 px-2 py-2 rounded-b">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<span class="mr-2">🟣</span>
|
||||||
|
<div class="text-sm">
|
||||||
|
<a href="http://necrovenice:8080/venice/conf/topics.js.vs?sig=2&conf=2"
|
||||||
|
class="text-blue-700 hover:text-blue-900 font-bold">General Discussion</a>
|
||||||
|
<span class="text-black"> (La Piazza)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{*
|
||||||
|
* 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/.
|
||||||
|
*}
|
||||||
|
<!-- Users Online -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<div class="bg-blue-600 px-2 py-1 rounded-t">
|
||||||
|
<h3 class="text-white font-bold text-base">Users Online:</h3>
|
||||||
|
</div>
|
||||||
|
<div class="bg-blue-400 px-2 py-2 rounded-b">
|
||||||
|
<div class="text-black text-sm font-bold mb-2">1 total (max 1)</div>
|
||||||
|
<div class="flex items-center">
|
||||||
|
<span class="mr-2">🟣</span>
|
||||||
|
<span class="text-black text-sm">Not logged in (1)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+15
-52
@@ -8,14 +8,16 @@
|
|||||||
*}
|
*}
|
||||||
<!-- Content Area -->
|
<!-- Content Area -->
|
||||||
<div class="flex-1 p-4">
|
<div class="flex-1 p-4">
|
||||||
<!-- Welcome Section -->
|
{{ if .CurrentUser().IsAnon }}
|
||||||
<div class="mb-8">
|
<!-- Welcome Section -->
|
||||||
<h1 class="text-blue-800 text-4xl font-bold mb-2">Welcome to Venice</h1>
|
<div class="mb-8">
|
||||||
<hr class="border-2 border-gray-400 w-4/5 mb-4">
|
<h1 class="text-blue-800 text-4xl font-bold mb-2">Welcome to Amsterdam</h1>
|
||||||
<p class="text-black text-sm mb-4">
|
<hr class="border-2 border-gray-400 w-4/5 mb-4">
|
||||||
Welcome to the <strong>Venice Web Communities System</strong>. To get the most out of this site, you should log in or create an account, using one of the links above.
|
<p class="text-black text-sm mb-4">
|
||||||
</p>
|
Welcome to the <strong>Amsterdam Web Communities System</strong>. To get the most out of this site, you should log in or create an account, using one of the links above.
|
||||||
</div>
|
</p>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<!-- Venice Currents Section -->
|
<!-- Venice Currents Section -->
|
||||||
<div>
|
<div>
|
||||||
@@ -46,48 +48,9 @@ dead by now.</pre>
|
|||||||
|
|
||||||
<!-- RIGHT SIDEBAR -->
|
<!-- RIGHT SIDEBAR -->
|
||||||
<div class="w-52 p-4">
|
<div class="w-52 p-4">
|
||||||
<!-- Featured Communities -->
|
{{ ctxt := . }}
|
||||||
<div class="mb-4">
|
{{ range sideboxes }}
|
||||||
<div class="bg-blue-600 px-2 py-1 rounded-t">
|
{{ ctxt.SetScratch("__sidebox", .) }}
|
||||||
<h3 class="text-white font-bold text-base">Featured Communities:</h3>
|
{{ ctxt.SubRender(.TemplateName) | raw }}
|
||||||
</div>
|
{{ end }}
|
||||||
<div class="bg-blue-400 px-2 py-2 rounded-b">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<span class="mr-2">🟣</span>
|
|
||||||
<a href="http://necrovenice:8080/venice/community/Piazza"
|
|
||||||
class="text-blue-700 hover:text-blue-900 font-bold text-sm">La Piazza</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Featured Conferences -->
|
|
||||||
<div class="mb-4">
|
|
||||||
<div class="bg-blue-600 px-2 py-1 rounded-t">
|
|
||||||
<h3 class="text-white font-bold text-base">Featured Conferences:</h3>
|
|
||||||
</div>
|
|
||||||
<div class="bg-blue-400 px-2 py-2 rounded-b">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<span class="mr-2">🟣</span>
|
|
||||||
<div class="text-sm">
|
|
||||||
<a href="http://necrovenice:8080/venice/conf/topics.js.vs?sig=2&conf=2"
|
|
||||||
class="text-blue-700 hover:text-blue-900 font-bold">General Discussion</a>
|
|
||||||
<span class="text-black"> (La Piazza)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Users Online -->
|
|
||||||
<div class="mb-4">
|
|
||||||
<div class="bg-blue-600 px-2 py-1 rounded-t">
|
|
||||||
<h3 class="text-white font-bold text-base">Users Online:</h3>
|
|
||||||
</div>
|
|
||||||
<div class="bg-blue-400 px-2 py-2 rounded-b">
|
|
||||||
<div class="text-black text-sm font-bold mb-2">1 total (max 1)</div>
|
|
||||||
<div class="flex items-center">
|
|
||||||
<span class="mr-2">🟣</span>
|
|
||||||
<span class="text-black text-sm">Not logged in (1)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user