diff --git a/find.go b/find.go new file mode 100644 index 0000000..1735e26 --- /dev/null +++ b/find.go @@ -0,0 +1,57 @@ +/* + * 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 main contains the high-level Amsterdam logic. +package main + +import "git.erbosoft.com/amy/amsterdam/ui" + +/* FindPage renders the Amsterdam "Find" page. + * Parameters: + * ctxt - The AmContext for the request. + * Returns: + * Command string dictating what to be rendered. + * Data as a parameter for the command string. + * Standard Go error status. + */ +func FindPage(ctxt ui.AmContext) (string, any, error) { + mode := "" + p := ctxt.Parameter("mode") + if p != "" { + mode = p + } else if ctxt.IsSession("find.mode") { + x := ctxt.GetSession("find.mode") + if xx, ok := x.(string); ok { + mode = xx + } + } + if mode == "" { + mode = "COM" + } + switch mode { + case "COM": + ctxt.VarMap().Set("field", "name") + ctxt.VarMap().Set("oper", "st") + ctxt.VarMap().Set("term", "") + case "USR": + ctxt.VarMap().Set("field", "name") + ctxt.VarMap().Set("oper", "st") + ctxt.VarMap().Set("term", "") + case "CAT": + ctxt.VarMap().Set("oper", "st") + ctxt.VarMap().Set("term", "") + case "PST": + ctxt.VarMap().Set("term", "") + } + + ctxt.VarMap().Set("mode", mode) + ctxt.VarMap().Set("amsterdam_pageTitle", "Find") + ctxt.SetLeftMenu("top") + ctxt.SetSession("find.mode", mode) + return "framed_template", "find.jet", nil +} diff --git a/main.go b/main.go index b139d17..c3a7c3d 100644 --- a/main.go +++ b/main.go @@ -64,6 +64,7 @@ func setupEcho() *echo.Echo { e.POST("/profile", ui.AmWrap(EditProfile)) e.GET("/profile_photo", ui.AmWrap(ProfilePhotoForm)) e.POST("/profile_photo", ui.AmWrap(ProfilePhoto)) + e.GET("/find", ui.AmWrap(FindPage)) e.GET("/user/:uname", ui.AmWrap(ShowProfile)) e.POST("/quick_email", ui.AmWrap(QuickEMail)) e.GET("/sysadmin", ui.AmWrap(SysAdminMenu)) diff --git a/ui/amcontext.go b/ui/amcontext.go index d22525f..ee2f2ae 100644 --- a/ui/amcontext.go +++ b/ui/amcontext.go @@ -61,6 +61,9 @@ type AmContext interface { SetRC(int) GetScratch(string) any SetScratch(string, any) + GetSession(string) any + SetSession(string, any) + IsSession(string) bool TestPermission(string) bool URLParam(string) string URLParamInt(string) (int, error) @@ -357,6 +360,22 @@ func (c *amContext) SetScratch(name string, val any) { c.scratchpad[name] = val } +// GetSession returns a session variable. +func (c *amContext) GetSession(name string) any { + return c.session.Values["x."+name] +} + +// SetSession sets a session variable. +func (c *amContext) SetSession(name string, value any) { + c.session.Values["x."+name] = value +} + +// IsSession tests to see whether a session value is set. +func (c *amContext) IsSession(name string) bool { + _, ok := c.session.Values["x."+name] + return ok +} + // TestPermission tests the current user against permissions. func (c *amContext) TestPermission(perm string) bool { return database.AmTestPermission(perm, c.effectiveLevel) diff --git a/ui/views/find.jet b/ui/views/find.jet new file mode 100644 index 0000000..d97c958 --- /dev/null +++ b/ui/views/find.jet @@ -0,0 +1,233 @@ +{* + * 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/. + *} +