Inject cluster config in header variable

This commit is contained in:
Jan Eitzinger
2022-09-12 13:35:42 +02:00
parent 10c6b366a5
commit 9a4d279c5a
3 changed files with 11 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/ClusterCockpit/cc-backend/internal/config"
"github.com/ClusterCockpit/cc-backend/pkg/log"
"github.com/ClusterCockpit/cc-backend/pkg/schema"
)
/// Go's embed is only allowed to embed files in a subdirectory of the embedding package ([see here](https://github.com/golang/go/issues/46056)).
@@ -62,7 +63,7 @@ type Page struct {
Error string // For generic use (e.g. the exact error message on /login)
Info string // For generic use (e.g. "Logout successfull" on /login)
User User // Information about the currently logged in user
Clusters []string // List of all clusters for use in the Header
Clusters []schema.ClusterConfig // List of all clusters for use in the Header
FilterPresets map[string]interface{} // For pages with the Filter component, this can be used to set initial filters.
Infos map[string]interface{} // For generic use (e.g. username for /monitoring/user/<id>, job id for /monitoring/job/<id>)
Config map[string]interface{} // UI settings for the currently logged in user (e.g. line width, ...)
@@ -76,10 +77,11 @@ func RenderTemplate(rw http.ResponseWriter, r *http.Request, file string, page *
if page.Clusters == nil {
for _, c := range config.Keys.Clusters {
page.Clusters = append(page.Clusters, c.Name)
page.Clusters = append(page.Clusters, schema.ClusterConfig{Name: c.Name, FilterRanges: c.FilterRanges, MetricDataRepository: nil})
}
}
log.Infof("%v\n", page.Config)
if err := t.Execute(rw, page); err != nil {
log.Errorf("template error: %s", err.Error())
}