Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OliveTin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ message DashboardComponent {
string title = 1;
string type = 2;
repeated DashboardComponent contents = 3;
string icon = 4;
}

message StartActionRequest {
Expand Down
7 changes: 7 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type Config struct {
InsecureAllowDumpJwtClaims bool
Prometheus PrometheusConfig
SaveLogs SaveLogsConfig
DefaultIconForActions string
DefaultIconForDirectories string
DefaultIconForBack string

usedConfigDir string
}
Expand All @@ -141,6 +144,7 @@ type DashboardComponent struct {
Title string
Type string
Entity string
Icon string
Contents []DashboardComponent
}

Expand Down Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions internal/config/emoji.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

var emojis = map[string]string{
"": "😀", // default icon
"poop": "💩",
"smile": "😀",
"ping": "📡",
Expand All @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions internal/config/emoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion internal/config/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/grpcapi/grpcApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 13 additions & 4 deletions internal/grpcapi/grpcApiDashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions internal/httpservers/webuiServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type webUISettings struct {
CurrentVersion string
PageTitle string
SectionNavigationStyle string
DefaultIconForBack string
}

func findWebuiDir() string {
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions webui.dev/js/marshaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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('..')
Expand Down
2 changes: 2 additions & 0 deletions webui.dev/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ function processWebuiSettingsJson (settings) {
const titleElem = document.querySelector('#page-title')
if (titleElem) titleElem.innerText = window.pageTitle
}

window.settings = settings
}

function main () {
Expand Down
Loading