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
|
||||
|
||||
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) {
|
||||
// Set the page title.
|
||||
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
|
||||
}
|
||||
|
||||
+12
-4
@@ -28,11 +28,12 @@ type AmContext interface {
|
||||
RC() int
|
||||
OutputType() string
|
||||
Render(string) error
|
||||
Scratchpad() map[any]any
|
||||
Scratchpad() map[string]any
|
||||
SubRender(string) ([]byte, error)
|
||||
Session() *sessions.Session
|
||||
SetOutputType(string)
|
||||
SetRC(int)
|
||||
SetScratch(string, any)
|
||||
URLPath() string
|
||||
VarMap() jet.VarMap
|
||||
}
|
||||
@@ -43,7 +44,7 @@ type amContext struct {
|
||||
httprc int
|
||||
rendervars jet.VarMap
|
||||
outputType string
|
||||
scratchpad map[any]any
|
||||
scratchpad map[string]any
|
||||
session *sessions.Session
|
||||
}
|
||||
|
||||
@@ -77,9 +78,9 @@ func (c *amContext) Render(name string) error {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
c.scratchpad = make(map[any]any)
|
||||
c.scratchpad = make(map[string]any)
|
||||
}
|
||||
return c.scratchpad
|
||||
}
|
||||
@@ -116,6 +117,13 @@ func (c *amContext) SetRC(rc int) {
|
||||
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.
|
||||
func (c *amContext) URLPath() string {
|
||||
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 -->
|
||||
<div class="flex-1 p-4">
|
||||
<!-- Welcome Section -->
|
||||
<div class="mb-8">
|
||||
<h1 class="text-blue-800 text-4xl font-bold mb-2">Welcome to Venice</h1>
|
||||
<hr class="border-2 border-gray-400 w-4/5 mb-4">
|
||||
<p class="text-black text-sm 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>
|
||||
</div>
|
||||
{{ if .CurrentUser().IsAnon }}
|
||||
<!-- Welcome Section -->
|
||||
<div class="mb-8">
|
||||
<h1 class="text-blue-800 text-4xl font-bold mb-2">Welcome to Amsterdam</h1>
|
||||
<hr class="border-2 border-gray-400 w-4/5 mb-4">
|
||||
<p class="text-black text-sm mb-4">
|
||||
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.
|
||||
</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<!-- Venice Currents Section -->
|
||||
<div>
|
||||
@@ -46,48 +48,9 @@ dead by now.</pre>
|
||||
|
||||
<!-- RIGHT SIDEBAR -->
|
||||
<div class="w-52 p-4">
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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>
|
||||
{{ ctxt := . }}
|
||||
{{ range sideboxes }}
|
||||
{{ ctxt.SetScratch("__sidebox", .) }}
|
||||
{{ ctxt.SubRender(.TemplateName) | raw }}
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user