Implement UI config handling

This commit is contained in:
2025-09-27 09:26:42 +02:00
parent ad500c4bef
commit 50d000e7e2
2 changed files with 292 additions and 5 deletions

View File

@@ -1,15 +1,19 @@
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
// All rights reserved.
// All rights reserved. This file is part of cc-backend.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Package web implements the HTML templating and web frontend configuration
package web
import (
"embed"
"encoding/json"
"html/template"
"io/fs"
"net/http"
"strings"
"sync"
"github.com/ClusterCockpit/cc-backend/internal/config"
"github.com/ClusterCockpit/cc-backend/pkg/archive"
@@ -18,8 +22,114 @@ import (
"github.com/ClusterCockpit/cc-lib/util"
)
/// 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)).
type WebConfig struct {
JobList JobListConfig `json:"jobList"`
NodeList NodeListConfig `json:"nodeList"`
JobView JobViewConfig `json:"jobView"`
MetricConfig MetricConfig `json:"metricConfig"`
PlotConfiguration PlotConfiguration `json:"plotConfiguration"`
}
type JobListConfig struct {
UsePaging bool `json:"usePaging"`
ShowFootprint bool `json:"showFootprint"`
}
type NodeListConfig struct {
UsePaging bool `json:"usePaging"`
}
type JobViewConfig struct {
ShowPolarPlot bool `json:"showPolarPlot"`
ShowFootprint bool `json:"showFootprint"`
ShowRoofline bool `json:"showRoofline"`
ShowStatTable bool `json:"showStatTable"`
}
type MetricConfig struct {
JobListMetrics []string `json:"jobListMetrics"`
JobViewPlotMetrics []string `json:"jobViewPlotMetrics"`
JobViewTableMetrics []string `json:"jobViewTableMetrics"`
Clusters []ClusterConfig `json:"clusters"`
}
type ClusterConfig struct {
Name string `json:"name"`
SubClusters []SubClusterConfig `json:"subClusters"`
}
type SubClusterConfig struct {
Name string `json:"name"`
JobListMetrics []string `json:"jobListMetrics"`
JobViewPlotMetrics []string `json:"jobViewPlotMetrics"`
JobViewTableMetrics []string `json:"jobViewTableMetrics"`
}
type PlotConfiguration struct {
ColorBackground bool `json:"colorBackground"`
PlotsPerRow int `json:"plotsPerRow"`
LineWidth int `json:"lineWidth"`
ColorScheme []string `json:"colorScheme"`
}
var initOnce sync.Once
var Keys = WebConfig{
JobList: JobListConfig{
UsePaging: false,
ShowFootprint: true,
},
NodeList: NodeListConfig{
UsePaging: true,
},
JobView: JobViewConfig{
ShowPolarPlot: true,
ShowFootprint: true,
ShowRoofline: true,
ShowStatTable: true,
},
MetricConfig: MetricConfig{
JobListMetrics: []string{"flops_any", "mem_bw", "mem_used"},
JobViewPlotMetrics: []string{"flops_any", "mem_bw", "mem_used"},
JobViewTableMetrics: []string{"flops_any", "mem_bw", "mem_used"},
},
PlotConfiguration: PlotConfiguration{
ColorBackground: true,
PlotsPerRow: 3,
LineWidth: 3,
ColorScheme: []string{"#00bfff", "#0000ff", "#ff00ff", "#ff0000", "#ff8000", "#ffff00", "#80ff00"},
},
}
//
// map[string]any{
// "analysis_view_histogramMetrics": []string{"flops_any", "mem_bw", "mem_used"},
// "analysis_view_scatterPlotMetrics": [][]string{{"flops_any", "mem_bw"}, {"flops_any", "cpu_load"}, {"cpu_load", "mem_bw"}},
// "job_view_nodestats_selectedMetrics": []string{"flops_any", "mem_bw", "mem_used"},
// "plot_list_jobsPerPage": 50,
// "system_view_selectedMetric": "cpu_load",
// "analysis_view_selectedTopEntity": "user",
// "analysis_view_selectedTopCategory": "totalWalltime",
// "status_view_selectedTopUserCategory": "totalJobs",
// "status_view_selectedTopProjectCategory": "totalJobs",
// }
func Init(rawConfig json.RawMessage, disableArchive bool) error {
var err error
initOnce.Do(func() {
config.Validate(configSchema, rawConfig)
if err = json.Unmarshal(rawConfig, &Keys); err != nil {
cclog.Warn("Error while unmarshaling raw config json")
return
}
})
return err
}
// / 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)).
//
//go:embed frontend/public/*
var frontendFiles embed.FS
@@ -92,9 +202,9 @@ type Page struct {
Build Build // Latest information about the application
Clusters []config.ClusterConfig // List of all clusters for use in the Header
SubClusters map[string][]string // Map per cluster of all subClusters 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, ...)
FilterPresets map[string]any // For pages with the Filter component, this can be used to set initial filters.
Infos map[string]any // For generic use (e.g. username for /monitoring/user/<id>, job id for /monitoring/job/<id>)
Config map[string]any // UI settings for the currently logged in user (e.g. line width, ...)
Resampling *config.ResampleConfig // If not nil, defines resampling trigger and resolutions
Redirect string // The originally requested URL, for intermediate login handling
}