From 049d82098fdcb2fd6dd56f02f78363d59efe09d0 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Mon, 20 May 2024 11:59:41 -0600 Subject: [PATCH] Adding environment banner --- core/templates.go | 13 +++++++++++++ static/css/style.css | 14 ++++++++++++++ templates/base.html | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/core/templates.go b/core/templates.go index dbf0ba9..6e54dd2 100644 --- a/core/templates.go +++ b/core/templates.go @@ -14,6 +14,11 @@ import ( "netlandish.com/x/gobwebs/server" ) +const ( + productionEnv = "production" + stagingEnv = "staging" +) + // AddGlobalTmpl provides global tmpl vars for templates func AddGlobalTmpl(c echo.Context) gobwebs.Map { gctx := c.(*server.Context) @@ -74,6 +79,14 @@ func AddGlobalTmpl(c echo.Context) gobwebs.Map { gmap["currentUser"] = user // To avoid nil pointer error gmap["currentUserID"] = user.ID + + // Display the environment name in the base template + if user.IsSuperUser() || user.IsStaff() { + switch gctx.Server.Config.Environment { + case productionEnv, stagingEnv: + gmap["env"] = gctx.Server.Config.Environment + } + } } gmap["currentOrg"] = links.GetOrgSelection(c) diff --git a/static/css/style.css b/static/css/style.css index b5ef736..5c30dc9 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -13,6 +13,20 @@ body { text-rendering: optimizeLegibility; } +#env-banner { + text-align: center; + color: white; + text-transform: uppercase; + z-index: 10000; + position: relative; +} +.env-production { + background-color: red; +} +.env-staging { + background-color: green; +} + .root-container { display: flex; flex-direction: row; diff --git a/templates/base.html b/templates/base.html index aa0fd4c..f7fe99d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -15,6 +15,11 @@ {{ block "extrahead" . }}{{ end }} + {{if .env }} +
+ {{ .env }} enviroment +
+ {{end}} {{ if .hideNav }}

{{.base_pd.Title}}

-- 2.45.2