diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..235a67e --- /dev/null +++ b/errors.go @@ -0,0 +1,26 @@ +/* + * 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" + +/* NotImplPage is used for all TODO links, to show that something hasn't yet been implemented. + * 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 NotImplPage(ctxt ui.AmContext) (string, any, error) { + ctxt.VarMap().Set("amsterdam_pageTitle", "Function Not Implemented") + ctxt.VarMap().Set("path", ctxt.URLPath()) + return "framed_template", "notimpl.jet", nil +} diff --git a/main.go b/main.go index 56d7ac8..0cc8850 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ func setupEcho() *echo.Echo { e.Use(LogrusMiddleware) e.Use(session.Middleware(ui.SessionStore)) + e.GET("/TODO/*", ui.AmWrap(NotImplPage)) e.GET("/img/*", ui.AmWrap(ui.AmServeImage)) e.GET("/about", ui.AmWrap(AboutPage)) e.GET("/", ui.AmWrap(TopPage)) diff --git a/ui/render_wrap.go b/ui/render_wrap.go index a67b010..695eaa5 100644 --- a/ui/render_wrap.go +++ b/ui/render_wrap.go @@ -16,6 +16,39 @@ import ( "github.com/labstack/echo/v4" ) +func sendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error { + var err error + switch command { + case "bytes": + err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), data.([]byte)) + case "string": + err = ctxt.String(amctxt.RC(), fmt.Sprintf("%v", data)) + case "template": + err = amctxt.Render(fmt.Sprintf("%v", data)) + case "framed_template": + amctxt.VarMap().Set("amsterdam_innerPage", data) + err = amctxt.Render("frame.jet") + default: + err = fmt.Errorf("unknown rendering type: %s", command) + } + return err +} + +/* ErrorPage renders the Amsterdam page with a server error message. + * Parameters: + * ctxt - The AmContext for the request. + * input_err - The error to be rendered on the page. + * Returns: + * Command string dictating what to be rendered. + * Data as a parameter for the command string. + * Standard Go error status. + */ +func ErrorPage(ctxt AmContext, input_err error) (string, any, error) { + ctxt.VarMap().Set("amsterdam_pageTitle", "Internal Server Error") + ctxt.VarMap().Set("error", input_err.Error()) + return "framed_template", "error.jet", nil +} + /* AmWrap wraps the Amsterdam handler function in a wrapper that implements the spec for * Echo handler functions. * Parameters: @@ -36,24 +69,15 @@ func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc { ctxt.Logger().Errorf("Session save error: %v", err) return err } - switch what { - case "bytes": - err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), rc.([]byte)) - case "string": - err = ctxt.String(amctxt.RC(), fmt.Sprintf("%v", rc)) - case "template": - err = amctxt.Render(fmt.Sprintf("%v", rc)) - case "framed_template": - amctxt.VarMap().Set("amsterdam_innerPage", rc) - err = amctxt.Render("frame.jet") - default: - err = fmt.Errorf("unknown rendering type: %s", what) - } + err = sendPageData(ctxt, amctxt, what, rc) if err != nil { ctxt.Logger().Errorf("Rendering error: %v", err) } } else { ctxt.Logger().Errorf("Page function error: %v", err) + _, rc, _ = ErrorPage(amctxt, err) + newerr := sendPageData(ctxt, amctxt, "framed_template", rc) + err = newerr } return err } diff --git a/ui/static_images/placeholder_ad.gif b/ui/static_images/placeholder_ad.gif new file mode 100644 index 0000000..f7d8482 Binary files /dev/null and b/ui/static_images/placeholder_ad.gif differ diff --git a/ui/views/about.jet b/ui/views/about.jet index a85984c..4b85c50 100644 --- a/ui/views/about.jet +++ b/ui/views/about.jet @@ -1,3 +1,12 @@ +{* + * 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/. + *} +
-
+ \ No newline at end of file diff --git a/ui/views/error.jet b/ui/views/error.jet new file mode 100644 index 0000000..d165483 --- /dev/null +++ b/ui/views/error.jet @@ -0,0 +1,22 @@ +{* + * 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/. + *} +
+
+
+

Amsterdam Internal Server Error

+
+

+ The Amsterdam server encountered an error: {{ error }} +

+

+ Click here to return to the home page. +

+
+
+
diff --git a/ui/views/frame.jet b/ui/views/frame.jet index 6684019..849b309 100644 --- a/ui/views/frame.jet +++ b/ui/views/frame.jet @@ -47,9 +47,7 @@
- +
diff --git a/ui/views/notimpl.jet b/ui/views/notimpl.jet new file mode 100644 index 0000000..80c8103 --- /dev/null +++ b/ui/views/notimpl.jet @@ -0,0 +1,22 @@ +{* + * 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/. + *} +
+
+
+

Amsterdam: Function Not Implemented

+
+

+ You've stumbled into a function that's not implemented yet. The function path is {{ path }}. +

+

+ Click here to return to the home page. +

+
+
+