From 706441799ff3158ecbc8627d9697ee6d4f5d6500 Mon Sep 17 00:00:00 2001 From: jamesread Date: Sun, 13 Oct 2024 00:17:38 +0100 Subject: [PATCH] feature: Custom navigation links in the nav (sidebar/topbar) --- internal/config/config.go | 10 ++++++++-- internal/httpservers/webuiServer.go | 2 ++ webui.dev/main.js | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 4d5959d..4993484 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -115,6 +115,8 @@ type Config struct { AuthJwtPubKeyPath string // will read pub key from file on disk AuthHttpHeaderUsername string AuthHttpHeaderUserGroup string + AuthLoginUrl string + AuthAllowGuest bool DefaultPermissions PermissionsList AccessControlLists []*AccessControlList WebUIDir string @@ -130,12 +132,16 @@ type Config struct { DefaultIconForActions string DefaultIconForDirectories string DefaultIconForBack string - AuthLoginUrl string - AuthAllowGuest bool + AdditionalNavigationLinks []*NavigationLink usedConfigDir string } +type NavigationLink struct { + Title string + Url string +} + type SaveLogsConfig struct { ResultsDirectory string OutputDirectory string diff --git a/internal/httpservers/webuiServer.go b/internal/httpservers/webuiServer.go index 32129e7..9e10e76 100644 --- a/internal/httpservers/webuiServer.go +++ b/internal/httpservers/webuiServer.go @@ -33,6 +33,7 @@ type webUISettings struct { SshFoundConfig string EnableCustomJs bool AuthLoginUrl string + AdditionalLinks []*config.NavigationLink } func findWebuiDir() string { @@ -119,6 +120,7 @@ func generateWebUISettings(w http.ResponseWriter, r *http.Request) { SshFoundConfig: installationinfo.Runtime.SshFoundConfig, EnableCustomJs: cfg.EnableCustomJs, AuthLoginUrl: cfg.AuthLoginUrl, + AdditionalLinks: cfg.AdditionalNavigationLinks, }) w.Header().Add("Content-Type", "application/json") diff --git a/webui.dev/main.js b/webui.dev/main.js index 63c7281..f09c61b 100644 --- a/webui.dev/main.js +++ b/webui.dev/main.js @@ -126,11 +126,27 @@ function processWebuiSettingsJson (settings) { if (titleElem) titleElem.innerText = window.pageTitle } + processAdditionaLinks(settings.AdditionalLinks) + window.settings = settings refreshDiagnostics() } +function processAdditionaLinks (links) { + for (const link of links) { + const linkA = document.createElement('a') + linkA.href = link.Url + linkA.innerText = link.Title + linkA.target = '_blank' + + const linkLi = document.createElement('li') + linkLi.appendChild(linkA) + + document.getElementById('supplemental-links').prepend(linkLi) + } +} + function main () { initMarshaller()