Przeglądaj źródła

feature: Custom navigation links in the nav (sidebar/topbar)

jamesread 1 rok temu
rodzic
commit
706441799f

+ 8 - 2
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

+ 2 - 0
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")

+ 16 - 0
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()