Преглед изворни кода

fix: Bug that caused duplicate links (eg Diagnostics and Logs) in the nav bar (#595)

James Read пре 1 година
родитељ
комит
7110399d41

+ 1 - 1
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 {

+ 1 - 0
service/internal/servicehost/servicehost_windows.go

@@ -99,6 +99,7 @@ func cdToExecutableDir() {
 	}
 }
 
+//gocyclo:ignore
 func startServiceHandler(mode string) {
 	cdToExecutableDir()
 

+ 1 - 1
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"

+ 1 - 1
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) {

+ 35 - 31
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')
-	}
-
-	createLink(title, url, isSupplemental) {
-		const linkA = document.createElement('a')
-		linkA.href = url
-		linkA.innerText = title
-
-		const navigationLi = document.createElement('li')
-		navigationLi.appendChild(linkA)
-		navigationLi.title = title
-
-		if (isSupplemental) {
-			this.supplementalLinks.appendChild(navigationLi)
-		} else {
-			this.mainLinks.appendChild(navigationLi)
-		}
-	}
-
-	refreshSectionPolicyLinks(policy) {
-		if (policy.showDiagnostics) {
-			this.createLink('Diagnostics', '/diagnostics', true)
-		}
-
-		if (policy.showLogList) {
-			this.createLink('Logs', '/logs', true)
-		}
-	}
+  constructor () {
+    this.navbar = document.getElementsByTagName('nav')[0]
+    this.mainLinks = document.getElementById('navigation-links')
+    this.supplementalLinks = document.getElementById('supplemental-links')
+  }
+
+  createLink (title, url, isSupplemental) {
+    let parent = (isSupplemental) ? this.supplementalLinks : this.mainLinks
+
+    const existsAlready = Array.from(parent.querySelectorAll('li')).some(el => el.title === title)
+
+    if (existsAlready) {
+      return
+    }
+
+    const linkA = document.createElement('a')
+    linkA.href = url
+    linkA.innerText = title
+
+    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)
+    }
+  }
 }