feature: Customizable default directory, back and action icons (#326)

This commit is contained in:
James Read
2024-05-31 23:43:05 +01:00
committed by GitHub
parent ac0f3ab6f8
commit 238abc95ad
10 changed files with 38 additions and 12 deletions

View File

@@ -54,6 +54,7 @@ message DashboardComponent {
string title = 1;
string type = 2;
repeated DashboardComponent contents = 3;
string icon = 4;
}
message StartActionRequest {

View File

@@ -121,6 +121,9 @@ type Config struct {
InsecureAllowDumpJwtClaims bool
Prometheus PrometheusConfig
SaveLogs SaveLogsConfig
DefaultIconForActions string
DefaultIconForDirectories string
DefaultIconForBack string
usedConfigDir string
}
@@ -141,6 +144,7 @@ type DashboardComponent struct {
Title string
Type string
Entity string
Icon string
Contents []DashboardComponent
}
@@ -175,6 +179,9 @@ func DefaultConfig() *Config {
config.InsecureAllowDumpJwtClaims = false
config.Prometheus.Enabled = false
config.Prometheus.DefaultGoMetrics = false
config.DefaultIconForActions = "😀"
config.DefaultIconForDirectories = "&#128193"
config.DefaultIconForBack = "«"
return &config
}

View File

@@ -1,7 +1,6 @@
package config
var emojis = map[string]string{
"": "😀", // default icon
"poop": "💩",
"smile": "😀",
"ping": "📡",
@@ -17,7 +16,11 @@ var emojis = map[string]string{
"robot": "🤖",
}
func lookupHTMLIcon(keyToLookup string) string {
func lookupHTMLIcon(keyToLookup string, defaultIcon string) string {
if keyToLookup == "" {
return defaultIcon
}
if emoji, found := emojis[keyToLookup]; found {
return emoji
}

View File

@@ -6,7 +6,9 @@ import (
)
func TestGetEmojiByShortName(t *testing.T) {
assert.Equal(t, "😀", lookupHTMLIcon("smile"), "Find an eomji by short name")
assert.Equal(t, "😀", lookupHTMLIcon("smile", "empty"), "Find an eomji by short name")
assert.Equal(t, "notfound", lookupHTMLIcon("notfound"), "Find an eomji by undefined short name")
assert.Equal(t, "empty", lookupHTMLIcon("", "empty"), "Find an eomji when the value is empty")
assert.Equal(t, "notfound", lookupHTMLIcon("notfound", "empty"), "Find an eomji by undefined short name")
}

View File

@@ -31,7 +31,7 @@ func (action *Action) sanitize(cfg *Config) {
}
action.ID = getActionID(action)
action.Icon = lookupHTMLIcon(action.Icon)
action.Icon = lookupHTMLIcon(action.Icon, cfg.DefaultIconForActions)
action.PopupOnStart = sanitizePopupOnStart(action.PopupOnStart, cfg)
if action.MaxConcurrent < 1 {

View File

@@ -242,7 +242,7 @@ func (api *oliveTinAPI) GetDashboardComponents(ctx ctx.Context, req *pb.GetDashb
log.Tracef("GetDashboardComponents: %v", res)
dashboardCfgToPb(res, cfg.Dashboards)
dashboardCfgToPb(res, cfg.Dashboards, cfg)
res.AuthenticatedUser = user.Username

View File

@@ -6,17 +6,17 @@ import (
"golang.org/x/exp/slices"
)
func dashboardCfgToPb(res *pb.GetDashboardComponentsResponse, dashboards []*config.DashboardComponent) {
func dashboardCfgToPb(res *pb.GetDashboardComponentsResponse, dashboards []*config.DashboardComponent, cfg *config.Config) {
for _, dashboard := range dashboards {
res.Dashboards = append(res.Dashboards, &pb.DashboardComponent{
Type: "dashboard",
Title: dashboard.Title,
Contents: getDashboardComponentContents(dashboard),
Contents: getDashboardComponentContents(dashboard, cfg),
})
}
}
func getDashboardComponentContents(dashboard *config.DashboardComponent) []*pb.DashboardComponent {
func getDashboardComponentContents(dashboard *config.DashboardComponent, cfg *config.Config) []*pb.DashboardComponent {
ret := make([]*pb.DashboardComponent, 0)
for _, subitem := range dashboard.Contents {
@@ -28,7 +28,8 @@ func getDashboardComponentContents(dashboard *config.DashboardComponent) []*pb.D
newitem := &pb.DashboardComponent{
Title: subitem.Title,
Type: getDashboardComponentType(&subitem),
Contents: getDashboardComponentContents(&subitem),
Contents: getDashboardComponentContents(&subitem, cfg),
Icon: getDashboardComponentIcon(&subitem, cfg),
}
ret = append(ret, newitem)
@@ -37,6 +38,14 @@ func getDashboardComponentContents(dashboard *config.DashboardComponent) []*pb.D
return ret
}
func getDashboardComponentIcon(item *config.DashboardComponent, cfg *config.Config) string {
if item.Icon == "" {
return cfg.DefaultIconForDirectories
}
return item.Icon
}
func getDashboardComponentType(item *config.DashboardComponent) string {
allowedTypes := []string{
"stdout-most-recent-execution",

View File

@@ -28,6 +28,7 @@ type webUISettings struct {
CurrentVersion string
PageTitle string
SectionNavigationStyle string
DefaultIconForBack string
}
func findWebuiDir() string {
@@ -109,6 +110,7 @@ func generateWebUISettings(w http.ResponseWriter, r *http.Request) {
CurrentVersion: updatecheck.CurrentVersion,
PageTitle: cfg.PageTitle,
SectionNavigationStyle: cfg.SectionNavigationStyle,
DefaultIconForBack: cfg.DefaultIconForBack,
})
_, err := w.Write([]byte(jsonRet))

View File

@@ -453,7 +453,7 @@ function marshalDisplay (item, fieldset) {
function marshalDirectoryButton (item, fieldset) {
const directoryButton = document.createElement('button')
directoryButton.innerHTML = '<span class = "icon">&#128193;</span> ' + item.title
directoryButton.innerHTML = '<span class = "icon">' + item.icon + '</span> ' + item.title
directoryButton.onclick = () => {
changeDirectory(item.title)
}
@@ -466,7 +466,7 @@ function marshalDirectory (item, section) {
fs.style.display = 'none'
const directoryBackButton = document.createElement('button')
directoryBackButton.innerHTML = '&laquo;'
directoryBackButton.innerHTML = window.settings.DefaultIconForBack
directoryBackButton.title = 'Go back one directory'
directoryBackButton.onclick = () => {
changeDirectory('..')

View File

@@ -115,6 +115,8 @@ function processWebuiSettingsJson (settings) {
const titleElem = document.querySelector('#page-title')
if (titleElem) titleElem.innerText = window.pageTitle
}
window.settings = settings
}
function main () {