From 7110399d413d200243a80aa4e000fa36e3b33916 Mon Sep 17 00:00:00 2001 From: James Read Date: Sat, 31 May 2025 20:20:37 +0100 Subject: [PATCH] fix: Bug that caused duplicate links (eg Diagnostics and Logs) in the nav bar (#595) --- service/internal/executor/executor_windows.go | 2 +- .../servicehost/servicehost_windows.go | 1 + service/internal/updatecheck/updateCheck.go | 2 +- .../internal/updatecheck/updateCheck_test.go | 2 +- webui.dev/js/NavigationBar.js | 56 ++++++++++--------- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/service/internal/executor/executor_windows.go b/service/internal/executor/executor_windows.go index ae61742..511a7e4 100644 --- a/service/internal/executor/executor_windows.go +++ b/service/internal/executor/executor_windows.go @@ -5,8 +5,8 @@ package executor import ( "context" - "os/exec" "os" + "os/exec" ) func (e *Executor) Kill(execReq *InternalLogEntry) error { diff --git a/service/internal/servicehost/servicehost_windows.go b/service/internal/servicehost/servicehost_windows.go index 607ddb0..a653043 100644 --- a/service/internal/servicehost/servicehost_windows.go +++ b/service/internal/servicehost/servicehost_windows.go @@ -99,6 +99,7 @@ func cdToExecutableDir() { } } +//gocyclo:ignore func startServiceHandler(mode string) { cdToExecutableDir() diff --git a/service/internal/updatecheck/updateCheck.go b/service/internal/updatecheck/updateCheck.go index d9172d9..d46911e 100644 --- a/service/internal/updatecheck/updateCheck.go +++ b/service/internal/updatecheck/updateCheck.go @@ -2,10 +2,10 @@ package updatecheck import ( "encoding/json" + "github.com/Masterminds/semver" config "github.com/OliveTin/OliveTin/internal/config" "github.com/OliveTin/OliveTin/internal/installationinfo" "github.com/robfig/cron/v3" - "github.com/Masterminds/semver" log "github.com/sirupsen/logrus" "io" "net/http" diff --git a/service/internal/updatecheck/updateCheck_test.go b/service/internal/updatecheck/updateCheck_test.go index 54d652e..1410af9 100644 --- a/service/internal/updatecheck/updateCheck_test.go +++ b/service/internal/updatecheck/updateCheck_test.go @@ -1,8 +1,8 @@ package updatecheck import ( - "testing" "github.com/stretchr/testify/assert" + "testing" ) func TestVersionLater(t *testing.T) { diff --git a/webui.dev/js/NavigationBar.js b/webui.dev/js/NavigationBar.js index 5400f28..d578a47 100644 --- a/webui.dev/js/NavigationBar.js +++ b/webui.dev/js/NavigationBar.js @@ -1,33 +1,37 @@ export class NavigationBar { - constructor() { - this.navbar = document.getElementsByTagName('nav')[0] - this.mainLinks = document.getElementById('navigation-links') - this.supplementalLinks = document.getElementById('supplemental-links') - } + constructor () { + this.navbar = document.getElementsByTagName('nav')[0] + this.mainLinks = document.getElementById('navigation-links') + this.supplementalLinks = document.getElementById('supplemental-links') + } - createLink(title, url, isSupplemental) { - const linkA = document.createElement('a') - linkA.href = url - linkA.innerText = title + createLink (title, url, isSupplemental) { + let parent = (isSupplemental) ? this.supplementalLinks : this.mainLinks - const navigationLi = document.createElement('li') - navigationLi.appendChild(linkA) - navigationLi.title = title + const existsAlready = Array.from(parent.querySelectorAll('li')).some(el => el.title === title) - if (isSupplemental) { - this.supplementalLinks.appendChild(navigationLi) - } else { - this.mainLinks.appendChild(navigationLi) - } - } + if (existsAlready) { + return + } - refreshSectionPolicyLinks(policy) { - if (policy.showDiagnostics) { - this.createLink('Diagnostics', '/diagnostics', true) - } + const linkA = document.createElement('a') + linkA.href = url + linkA.innerText = title - if (policy.showLogList) { - this.createLink('Logs', '/logs', true) - } - } + const navigationLi = document.createElement('li') + navigationLi.appendChild(linkA) + navigationLi.title = title + + parent.appendChild(navigationLi) + } + + refreshSectionPolicyLinks (policy) { + if (policy.showDiagnostics) { + this.createLink('Diagnostics', '/diagnostics', true) + } + + if (policy.showLogList) { + this.createLink('Logs', '/logs', true) + } + } }