Merge pull request #186 from ClusterCockpit/185-add-notification-banner

185 add notification banner
This commit is contained in:
Jan Eitzinger 2023-07-19 09:13:15 +02:00 committed by GitHub
commit 536a51b93f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -15,6 +16,7 @@ import (
"github.com/ClusterCockpit/cc-backend/internal/auth" "github.com/ClusterCockpit/cc-backend/internal/auth"
"github.com/ClusterCockpit/cc-backend/internal/graph/model" "github.com/ClusterCockpit/cc-backend/internal/graph/model"
"github.com/ClusterCockpit/cc-backend/internal/repository" "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/pkg/log"
"github.com/ClusterCockpit/cc-backend/web" "github.com/ClusterCockpit/cc-backend/web"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -60,6 +62,16 @@ func setupHomeRoute(i InfoType, r *http.Request) InfoType {
} }
i["clusters"] = stats 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 return i
} }

View File

@ -1,4 +1,20 @@
{{define "content"}} {{define "content"}}
{{if .Infos.message }}
<div class="row justify-content-center">
<div class="col-6">
<div class="alert alert-info p-3" role="alert">
<div class="row align-items-center">
<div class="col-2">
<h2><i class="bi-info-circle-fill m-3"></i></h2>
</div>
<div class="col-10">
{{.Infos.message}}
</div>
</div>
</div>
</div>
</div>
{{end}}
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h2>Clusters</h2> <h2>Clusters</h2>

View File

@ -9,11 +9,11 @@ import (
"html/template" "html/template"
"io/fs" "io/fs"
"net/http" "net/http"
"os"
"strings" "strings"
"github.com/ClusterCockpit/cc-backend/internal/auth" "github.com/ClusterCockpit/cc-backend/internal/auth"
"github.com/ClusterCockpit/cc-backend/internal/config" "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/log"
"github.com/ClusterCockpit/cc-backend/pkg/schema" "github.com/ClusterCockpit/cc-backend/pkg/schema"
) )
@ -48,7 +48,7 @@ func init() {
} }
if path == "templates/login.tmpl" { 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") log.Info("overwrite login.tmpl with local file")
templates[strings.TrimPrefix(path, "templates/")] = templates[strings.TrimPrefix(path, "templates/")] =
template.Must(template.Must(base.Clone()).ParseFiles("./var/login.tmpl")) template.Must(template.Must(base.Clone()).ParseFiles("./var/login.tmpl"))
@ -56,7 +56,7 @@ func init() {
} }
} }
if path == "templates/imprint.tmpl" { 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") log.Info("overwrite imprint.tmpl with local file")
templates[strings.TrimPrefix(path, "templates/")] = templates[strings.TrimPrefix(path, "templates/")] =
template.Must(template.Must(base.Clone()).ParseFiles("./var/imprint.tmpl")) template.Must(template.Must(base.Clone()).ParseFiles("./var/imprint.tmpl"))
@ -64,7 +64,7 @@ func init() {
} }
} }
if path == "templates/privacy.tmpl" { 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") log.Info("overwrite privacy.tmpl with local file")
templates[strings.TrimPrefix(path, "templates/")] = templates[strings.TrimPrefix(path, "templates/")] =
template.Must(template.Must(base.Clone()).ParseFiles("./var/privacy.tmpl")) template.Must(template.Must(base.Clone()).ParseFiles("./var/privacy.tmpl"))