From 2674f2a769c5fa1d186f558bbcaaeca5c654cca6 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Wed, 19 Jul 2023 07:51:04 +0200 Subject: [PATCH 1/3] Add message banner to template --- web/templates/home.tmpl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/templates/home.tmpl b/web/templates/home.tmpl index fbe1237..c0ad661 100644 --- a/web/templates/home.tmpl +++ b/web/templates/home.tmpl @@ -1,4 +1,14 @@ {{define "content"}} +{{if .Message }} +
+
+ +
+
+{{end}}

Clusters

From c6a0d442cc1449a4c0db07ca4d4cf4236206d888 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Wed, 19 Jul 2023 08:25:14 +0200 Subject: [PATCH 2/3] feat: Add optional notification banner on homepage Fixes #185 --- internal/routerConfig/routes.go | 12 ++++++++++++ web/templates/home.tmpl | 4 ++-- web/web.go | 8 ++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/internal/routerConfig/routes.go b/internal/routerConfig/routes.go index 351941a..d58c3ed 100644 --- a/internal/routerConfig/routes.go +++ b/internal/routerConfig/routes.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" "net/url" + "os" "strconv" "strings" "time" @@ -15,6 +16,7 @@ import ( "github.com/ClusterCockpit/cc-backend/internal/auth" "github.com/ClusterCockpit/cc-backend/internal/graph/model" "github.com/ClusterCockpit/cc-backend/internal/repository" + "github.com/ClusterCockpit/cc-backend/internal/util" "github.com/ClusterCockpit/cc-backend/pkg/log" "github.com/ClusterCockpit/cc-backend/web" "github.com/gorilla/mux" @@ -60,6 +62,16 @@ func setupHomeRoute(i InfoType, r *http.Request) InfoType { } i["clusters"] = stats + + if util.CheckFileExists("./var/notice.txt") { + msg, err := os.ReadFile("./var/notice.txt") + if err != nil { + log.Warnf("failed to read notice.txt file: %s", err.Error()) + } else { + i["message"] = string(msg) + } + } + return i } diff --git a/web/templates/home.tmpl b/web/templates/home.tmpl index c0ad661..090cd1c 100644 --- a/web/templates/home.tmpl +++ b/web/templates/home.tmpl @@ -1,10 +1,10 @@ {{define "content"}} -{{if .Message }} +{{if .Infos.message }}
diff --git a/web/web.go b/web/web.go index bba6c8d..c94c2b1 100644 --- a/web/web.go +++ b/web/web.go @@ -9,11 +9,11 @@ import ( "html/template" "io/fs" "net/http" - "os" "strings" "github.com/ClusterCockpit/cc-backend/internal/auth" "github.com/ClusterCockpit/cc-backend/internal/config" + "github.com/ClusterCockpit/cc-backend/internal/util" "github.com/ClusterCockpit/cc-backend/pkg/log" "github.com/ClusterCockpit/cc-backend/pkg/schema" ) @@ -48,7 +48,7 @@ func init() { } if path == "templates/login.tmpl" { - if _, err := os.Stat("./var/login.tmpl"); err == nil { + if util.CheckFileExists("./var/login.tmpl") { log.Info("overwrite login.tmpl with local file") templates[strings.TrimPrefix(path, "templates/")] = template.Must(template.Must(base.Clone()).ParseFiles("./var/login.tmpl")) @@ -56,7 +56,7 @@ func init() { } } if path == "templates/imprint.tmpl" { - if _, err := os.Stat("./var/imprint.tmpl"); err == nil { + if util.CheckFileExists("./var/imprint.tmpl") { log.Info("overwrite imprint.tmpl with local file") templates[strings.TrimPrefix(path, "templates/")] = template.Must(template.Must(base.Clone()).ParseFiles("./var/imprint.tmpl")) @@ -64,7 +64,7 @@ func init() { } } if path == "templates/privacy.tmpl" { - if _, err := os.Stat("./var/privacy.tmpl"); err == nil { + if util.CheckFileExists("./var/privacy.tmpl") { log.Info("overwrite privacy.tmpl with local file") templates[strings.TrimPrefix(path, "templates/")] = template.Must(template.Must(base.Clone()).ParseFiles("./var/privacy.tmpl")) From aab50775d80868348cd4e0a4bc505c2807837b6a Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Wed, 19 Jul 2023 08:47:42 +0200 Subject: [PATCH 3/3] Improve message layout and styling --- web/templates/home.tmpl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web/templates/home.tmpl b/web/templates/home.tmpl index 090cd1c..0705d56 100644 --- a/web/templates/home.tmpl +++ b/web/templates/home.tmpl @@ -1,10 +1,16 @@ {{define "content"}} {{if .Infos.message }}
-
-