Skip to content

Commit 4ed5b47

Browse files
committed
refactor(ui): Cleanup template option handling
1 parent b062977 commit 4ed5b47

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

web/app/public/index.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,28 @@
22
<html lang="en" class="{{ .Theme }}">
33
<head>
44
<meta charset="utf-8" />
5+
<title>{{ .UI.Title }}</title>
56
<script type="text/javascript">
6-
window.config = {logo: "{{ .UI.Logo }}", header: "{{ .UI.Header }}", dashboardHeading: "{{ .UI.DashboardHeading }}", dashboardSubheading: "{{ .UI.DashboardSubheading }}", link: "{{ .UI.Link }}", buttons: [], maximumNumberOfResults: "{{ .UI.MaximumNumberOfResults }}", defaultSortBy: "{{ .UI.DefaultSortBy }}", defaultFilterBy: "{{ .UI.DefaultFilterBy }}"};{{- range .UI.Buttons}}window.config.buttons.push({name:"{{ .Name }}",link:"{{ .Link }}"});{{end}}
7-
// Initialize theme immediately to prevent flash
87
(function() {
8+
// String is percent-encoded to prevent it from being replaced when ui config is injected
9+
if (document.title !== decodeURIComponent("%7B%7B%20.UI.Title%20%7D%7D")) {
10+
window.config = {
11+
logo: "{{ .UI.Logo }}",
12+
header: "{{ .UI.Header }}",
13+
dashboardHeading: "{{ .UI.DashboardHeading }}",
14+
dashboardSubheading: "{{ .UI.DashboardSubheading }}",
15+
link: "{{ .UI.Link }}",
16+
buttons: [],
17+
maximumNumberOfResults: "{{ .UI.MaximumNumberOfResults }}",
18+
defaultSortBy: "{{ .UI.DefaultSortBy }}",
19+
defaultFilterBy: "{{ .UI.DefaultFilterBy }}"
20+
};
21+
{{- range .UI.Buttons}}window.config.buttons.push({name:"{{ .Name }}",link:"{{ .Link }}"});{{end}}
22+
} else {
23+
console.warn('Running in development mode; UI configuration is not injected.');
24+
document.title= 'Gatus (Development)';
25+
}
26+
// Initialize theme immediately to prevent flash
927
const themeFromCookie = document.cookie.match(/theme=(dark|light);?/)?.[1];
1028
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
1129
if (themeFromCookie === 'dark' || (!themeFromCookie && prefersDark)) {
@@ -15,7 +33,6 @@
1533
}
1634
})();
1735
</script>
18-
<title>{{ .UI.Title }}</title>
1936
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
2037
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
2138
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />

web/app/src/App.vue

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,13 @@ const tooltipIsPersistent = ref(false)
177177
let configInterval = null
178178
179179
// Computed properties
180-
const logo = computed(() => {
181-
return window.config && window.config.logo && window.config.logo !== '{{ .UI.Logo }}' ? window.config.logo : ""
182-
})
180+
const logo = computed(() => window.config?.logo ?? "")
183181
184-
const header = computed(() => {
185-
return window.config && window.config.header && window.config.header !== '{{ .UI.Header }}' ? window.config.header : "Gatus"
186-
})
182+
const header = computed(() => window.config?.header ?? "Gatus")
187183
188-
const link = computed(() => {
189-
return window.config && window.config.link && window.config.link !== '{{ .UI.Link }}' ? window.config.link : null
190-
})
184+
const link = computed(() => window.config?.link ?? null)
191185
192-
const buttons = computed(() => {
193-
return window.config && window.config.buttons ? window.config.buttons : []
194-
})
186+
const buttons = computed(() => window.config?.buttons ?? [])
195187
196188
// Methods
197189
const fetchConfig = async () => {

web/app/src/views/Home.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,9 @@ const initializeCollapsedGroups = () => {
533533
}
534534
}
535535
536-
const dashboardHeading = computed(() => {
537-
return window.config && window.config.dashboardHeading && window.config.dashboardHeading !== '{{ .UI.DashboardHeading }}' ? window.config.dashboardHeading : "Health Dashboard"
538-
})
536+
const dashboardHeading = computed(() => window.config?.dashboardHeading ?? "Health Dashboard")
539537
540-
const dashboardSubheading = computed(() => {
541-
return window.config && window.config.dashboardSubheading && window.config.dashboardSubheading !== '{{ .UI.DashboardSubheading }}' ? window.config.dashboardSubheading : "Monitor the health of your endpoints in real-time"
542-
})
538+
const dashboardSubheading = computed(() => window.config?.dashboardSubheading ?? "Monitor the health of your endpoints in real-time")
543539
544540
onMounted(() => {
545541
fetchData()

0 commit comments

Comments
 (0)