mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-13 01:25:45 +00:00
feature: Customizable default directory, back and action icons (#326)
This commit is contained in:
@@ -54,6 +54,7 @@ message DashboardComponent {
|
||||
string title = 1;
|
||||
string type = 2;
|
||||
repeated DashboardComponent contents = 3;
|
||||
string icon = 4;
|
||||
}
|
||||
|
||||
message StartActionRequest {
|
||||
|
||||
@@ -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 = "📁"
|
||||
config.DefaultIconForBack = "«"
|
||||
|
||||
return &config
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -453,7 +453,7 @@ function marshalDisplay (item, fieldset) {
|
||||
|
||||
function marshalDirectoryButton (item, fieldset) {
|
||||
const directoryButton = document.createElement('button')
|
||||
directoryButton.innerHTML = '<span class = "icon">📁</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 = '«'
|
||||
directoryBackButton.innerHTML = window.settings.DefaultIconForBack
|
||||
directoryBackButton.title = 'Go back one directory'
|
||||
directoryBackButton.onclick = () => {
|
||||
changeDirectory('..')
|
||||
|
||||
@@ -115,6 +115,8 @@ function processWebuiSettingsJson (settings) {
|
||||
const titleElem = document.querySelector('#page-title')
|
||||
if (titleElem) titleElem.innerText = window.pageTitle
|
||||
}
|
||||
|
||||
window.settings = settings
|
||||
}
|
||||
|
||||
function main () {
|
||||
|
||||
Reference in New Issue
Block a user