Skip to content

Commit 5f80122

Browse files
authored
Merge pull request #420 from StatensPensjonskasse/default-layout
Default layout settings
2 parents 523329a + 10a2a59 commit 5f80122

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ docker stack deploy --compose-file docker-compose.yml docker-swarm-dashboard
154154
docker service create --name logger chentex/random-logger:latest 50 200
155155
```
156156

157+
----
157158
### Configuration
158-
159159
Docker Swarm Dashboard supports environment variables for configuration
160160

161-
* `DSD_HANDLE_LOGS`: Set to `false` to prevent fetching and displaying logs
161+
* `DSD_HANDLE_LOGS`: Set to `false` to prevent fetching and displaying logs.
162+
* `DSD_DEFAULT_LAYOUT`: Default dashboard layout. Either `row` (default) or `column`.

app-src/src/components/DashboardNavbar.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { useAtom, useAtomValue } from 'jotai'
2828
import {
2929
aboutId,
3030
dashboardHId,
31+
dashboardVId,
3132
timelineId,
3233
logsId,
3334
nodesId,
@@ -49,6 +50,9 @@ function DashboardNavbar({ dashboardSettings }) {
4950
const logsShowLogs = useAtomValue(logsShowLogsAtom)
5051
const logsConfig = useAtomValue(logsConfigAtom)
5152

53+
const defaultLayout =
54+
dashboardSettings.defaultLayout === 'column' ? dashboardVId : dashboardHId
55+
5256
if (isDarkMode) document.body.classList.add('bg-dark')
5357
else document.body.classList.remove('bg-dark')
5458

@@ -91,7 +95,7 @@ function DashboardNavbar({ dashboardSettings }) {
9195
<Container fluid>
9296
<Navbar.Brand
9397
className="cursorPointer"
94-
onClick={() => updateView({ id: dashboardHId })}
98+
onClick={() => updateView({ id: defaultLayout })}
9599
>
96100
<img
97101
alt="logo"
@@ -107,10 +111,15 @@ function DashboardNavbar({ dashboardSettings }) {
107111
<Navbar.Collapse id="responsive-navbar-left">
108112
<Nav className="mr-auto">
109113
<Nav.Link
110-
onClick={() => updateView({ id: dashboardHId })}
111-
active={view?.id === dashboardHId}
114+
onClick={() => updateView({ id: defaultLayout })}
115+
active={view?.id === defaultLayout}
112116
>
113-
<FontAwesomeIcon icon="grip" /> Dashboard
117+
<FontAwesomeIcon
118+
icon={
119+
defaultLayout === dashboardHId ? 'grip' : 'grip-vertical'
120+
}
121+
/>
122+
&nbsp;Dashboard
114123
</Nav.Link>
115124
<Nav.Link
116125
onClick={() => updateView({ id: timelineId })}

server-src/dashboardsettingshandler.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,37 @@ package main
33
import (
44
"encoding/json"
55
"net/http"
6+
"os"
7+
"strconv"
8+
"strings"
69
)
710

811
type dashboardSettings struct {
9-
ShowLogsButton bool `json:"showLogsButton"`
12+
ShowLogsButton bool `json:"showLogsButton"`
13+
DefaultLayout string `json:"defaultLayout"`
14+
}
15+
16+
var (
17+
handlingLogs = true
18+
dashboardLayout = "row"
19+
)
20+
21+
func init() {
22+
if handleLogsEnvValue, handleLogsSet := os.LookupEnv("DSD_HANDLE_LOGS"); handleLogsSet {
23+
handlingLogs, _ = strconv.ParseBool(handleLogsEnvValue)
24+
}
25+
26+
if dashboardLayoutEnvValue, dashboardLayoutSet := os.LookupEnv("DSD_DASHBOARD_LAYOUT"); dashboardLayoutSet {
27+
if strings.HasPrefix(strings.ToLower(dashboardLayoutEnvValue), "col") {
28+
dashboardLayout = "column"
29+
}
30+
}
1031
}
1132

1233
func dashboardSettingsHandler(w http.ResponseWriter, _ *http.Request) {
13-
jsonString, _ := json.Marshal(dashboardSettings{handlingLogs})
34+
jsonString, _ := json.Marshal(dashboardSettings{
35+
handlingLogs,
36+
dashboardLayout})
1437
w.Header().Set("Content-Type", "application/json")
1538
w.Write(jsonString)
1639
}

server-src/dockerswarmdashboard.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
package main
22

33
import (
4-
"log"
5-
"net/http"
6-
"os"
7-
"strconv"
8-
94
"github.com/docker/docker/client"
105
"github.com/gorilla/handlers"
116
"github.com/gorilla/mux"
12-
)
13-
14-
var (
15-
handlingLogs = true
7+
"log"
8+
"net/http"
9+
"os"
1610
)
1711

1812
func main() {
1913
log.Println("Starting Docker Swarm Dashboard...")
2014

21-
handleLogsEnvValue, handleLogsSet := os.LookupEnv("DSD_HANDLE_LOGS")
22-
if handleLogsSet {
23-
handlingLogs, _ = strconv.ParseBool(handleLogsEnvValue)
24-
}
25-
2615
router := mux.NewRouter().StrictSlash(true)
2716

2817
// CORS Headers

0 commit comments

Comments
 (0)