]>
Commit | Line | Data |
---|---|---|
b9c5fcf0 BW |
1 | <template> |
2 | <div | |
3 | id="app" | |
4 | v-if="config" | |
5 | :class="[ | |
6 | `theme-${config.theme}`, | |
7 | isDark ? 'is-dark' : 'is-light', | |
9814a037 | 8 | !config.footer ? 'no-footer' : '', |
b9c5fcf0 BW |
9 | ]" |
10 | > | |
11 | <DynamicTheme :themes="config.colors" /> | |
12 | <div id="bighead"> | |
13 | <section v-if="config.header" class="first-line"> | |
14 | <div v-cloak class="container"> | |
15 | <div class="logo"> | |
ba07da6b BW |
16 | <a href="#"> |
17 | <img v-if="config.logo" :src="config.logo" alt="dashboard logo" /> | |
18 | </a> | |
239ef168 | 19 | <i v-if="config.icon" :class="config.icon"></i> |
b9c5fcf0 BW |
20 | </div> |
21 | <div class="dashboard-title"> | |
22 | <span class="headline">{{ config.subtitle }}</span> | |
23 | <h1>{{ config.title }}</h1> | |
24 | </div> | |
25 | </div> | |
26 | </section> | |
27 | ||
28 | <Navbar | |
29 | :open="showMenu" | |
30 | :links="config.links" | |
ed8b17e0 | 31 | @navbar-toggle="showMenu = !showMenu" |
b9c5fcf0 BW |
32 | > |
33 | <DarkMode @updated="isDark = $event" /> | |
34 | ||
35 | <SettingToggle | |
36 | @updated="vlayout = $event" | |
37 | name="vlayout" | |
38 | icon="fa-list" | |
39 | iconAlt="fa-columns" | |
40 | /> | |
41 | ||
42 | <SearchInput | |
43 | class="navbar-item is-inline-block-mobile" | |
584f2b4b | 44 | :hotkey="config.hotkey" |
b9c5fcf0 | 45 | @input="filterServices" |
ed8b17e0 BW |
46 | @search-focus="showMenu = true" |
47 | @search-open="navigateToFirstService" | |
48 | @search-cancel="filterServices" | |
b9c5fcf0 BW |
49 | /> |
50 | </Navbar> | |
51 | </div> | |
52 | ||
53 | <section id="main-section" class="section"> | |
54 | <div v-cloak class="container"> | |
e9113b48 BW |
55 | <ConnectivityChecker |
56 | v-if="config.connectivityCheck" | |
ed8b17e0 | 57 | @network-status-update="offline = $event" |
e9113b48 | 58 | /> |
b9c5fcf0 BW |
59 | <div v-if="!offline"> |
60 | <!-- Optional messages --> | |
61 | <Message :item="config.message" /> | |
62 | ||
63 | <!-- Horizontal layout --> | |
64 | <div v-if="!vlayout || filter" class="columns is-multiline"> | |
65 | <template v-for="group in services"> | |
66 | <h2 v-if="group.name" class="column is-full group-title"> | |
da6e676d | 67 | <i v-if="group.icon" :class="['fa-fw', group.icon]"></i> |
42477020 GC |
68 | <div v-else-if="group.logo" class="group-logo media-left"> |
69 | <figure class="image is-48x48"> | |
70 | <img :src="group.logo" :alt="`${group.name} logo`" /> | |
71 | </figure> | |
72 | </div> | |
b9c5fcf0 BW |
73 | {{ group.name }} |
74 | </h2> | |
75 | <Service | |
e1ecf86f | 76 | v-for="(item, index) in group.items" |
77 | :key="index" | |
b9c5fcf0 | 78 | v-bind:item="item" |
9e4fe0d2 | 79 | :class="['column', `is-${12 / config.columns}`]" |
b9c5fcf0 BW |
80 | /> |
81 | </template> | |
82 | </div> | |
83 | ||
84 | <!-- Vertical layout --> | |
85 | <div | |
86 | v-if="!filter && vlayout" | |
87 | class="columns is-multiline layout-vertical" | |
88 | > | |
89 | <div | |
9e4fe0d2 | 90 | :class="['column', `is-${12 / config.columns}`]" |
b9c5fcf0 BW |
91 | v-for="group in services" |
92 | :key="group.name" | |
93 | > | |
94 | <h2 v-if="group.name" class="group-title"> | |
da6e676d | 95 | <i v-if="group.icon" :class="['fa-fw', group.icon]"></i> |
42477020 GC |
96 | <div v-else-if="group.logo" class="group-logo media-left"> |
97 | <figure class="image is-48x48"> | |
98 | <img :src="group.logo" :alt="`${group.name} logo`" /> | |
99 | </figure> | |
100 | </div> | |
b9c5fcf0 BW |
101 | {{ group.name }} |
102 | </h2> | |
103 | <Service | |
e1ecf86f | 104 | v-for="(item, index) in group.items" |
105 | :key="index" | |
b9c5fcf0 | 106 | v-bind:item="item" |
b9c5fcf0 BW |
107 | /> |
108 | </div> | |
109 | </div> | |
110 | </div> | |
111 | </div> | |
112 | </section> | |
113 | ||
114 | <footer class="footer"> | |
115 | <div class="container"> | |
116 | <div | |
117 | class="content has-text-centered" | |
118 | v-if="config.footer" | |
119 | v-html="config.footer" | |
120 | ></div> | |
121 | </div> | |
122 | </footer> | |
123 | </div> | |
124 | </template> | |
125 | ||
126 | <script> | |
127 | const jsyaml = require("js-yaml"); | |
128 | const merge = require("lodash.merge"); | |
129 | ||
130 | import Navbar from "./components/Navbar.vue"; | |
131 | import ConnectivityChecker from "./components/ConnectivityChecker.vue"; | |
132 | import Service from "./components/Service.vue"; | |
133 | import Message from "./components/Message.vue"; | |
134 | import SearchInput from "./components/SearchInput.vue"; | |
135 | import SettingToggle from "./components/SettingToggle.vue"; | |
136 | import DarkMode from "./components/DarkMode.vue"; | |
137 | import DynamicTheme from "./components/DynamicTheme.vue"; | |
138 | ||
139 | import defaultConfig from "./assets/defaults.yml"; | |
140 | ||
141 | export default { | |
142 | name: "App", | |
143 | components: { | |
144 | Navbar, | |
145 | ConnectivityChecker, | |
146 | Service, | |
147 | Message, | |
148 | SearchInput, | |
149 | SettingToggle, | |
150 | DarkMode, | |
9814a037 | 151 | DynamicTheme, |
b9c5fcf0 BW |
152 | }, |
153 | data: function () { | |
154 | return { | |
155 | config: null, | |
156 | services: null, | |
157 | offline: false, | |
158 | filter: "", | |
159 | vlayout: true, | |
160 | isDark: null, | |
9814a037 | 161 | showMenu: false, |
b9c5fcf0 BW |
162 | }; |
163 | }, | |
164 | created: async function () { | |
ba07da6b BW |
165 | this.buildDashboard(); |
166 | window.onhashchange = this.buildDashboard; | |
b9c5fcf0 BW |
167 | }, |
168 | methods: { | |
ba07da6b BW |
169 | buildDashboard: async function () { |
170 | const defaults = jsyaml.load(defaultConfig); | |
171 | let config; | |
172 | try { | |
173 | config = await this.getConfig(); | |
174 | const path = | |
175 | window.location.hash.substring(1) != "" | |
176 | ? window.location.hash.substring(1) | |
177 | : null; | |
178 | ||
179 | if (path) { | |
180 | let pathConfig = await this.getConfig(`assets/${path}.yml`); // the slash (/) is included in the pathname | |
181 | config = Object.assign(config, pathConfig); | |
182 | } | |
183 | } catch (error) { | |
184 | console.log(error); | |
185 | config = this.handleErrors("⚠️ Error loading configuration", error); | |
186 | } | |
187 | this.config = merge(defaults, config); | |
188 | this.services = this.config.services; | |
189 | document.title = | |
190 | this.config.documentTitle || | |
191 | `${this.config.title} | ${this.config.subtitle}`; | |
192 | if (this.config.stylesheet) { | |
193 | let stylesheet = ""; | |
194 | for (const file of this.config.stylesheet) { | |
195 | stylesheet += `@import "${file}";`; | |
196 | } | |
197 | this.createStylesheet(stylesheet); | |
198 | } | |
199 | }, | |
b102c9b2 | 200 | getConfig: function (path = "assets/config.yml") { |
1a42e30a | 201 | return fetch(path).then((response) => { |
0ae40f78 BW |
202 | if (response.redirected) { |
203 | // This allows to work with authentication proxies. | |
204 | window.location.href = response.url; | |
205 | return; | |
206 | } | |
1a42e30a | 207 | if (!response.ok) { |
0ae40f78 | 208 | throw Error(`${response.statusText}: ${response.body}`); |
1a42e30a BW |
209 | } |
210 | ||
211 | const that = this; | |
212 | return response | |
213 | .text() | |
214 | .then((body) => { | |
bd910942 | 215 | return jsyaml.load(body); |
1a42e30a BW |
216 | }) |
217 | .then(function (config) { | |
218 | if (config.externalConfig) { | |
219 | return that.getConfig(config.externalConfig); | |
220 | } | |
221 | return config; | |
bd910942 | 222 | }); |
1a42e30a | 223 | }); |
b9c5fcf0 BW |
224 | }, |
225 | matchesFilter: function (item) { | |
226 | return ( | |
227 | item.name.toLowerCase().includes(this.filter) || | |
1c451e11 | 228 | (item.subtitle && item.subtitle.toLowerCase().includes(this.filter)) || |
b9c5fcf0 BW |
229 | (item.tag && item.tag.toLowerCase().includes(this.filter)) |
230 | ); | |
231 | }, | |
232 | navigateToFirstService: function (target) { | |
233 | try { | |
234 | const service = this.services[0].items[0]; | |
235 | window.open(service.url, target || service.target || "_self"); | |
236 | } catch (error) { | |
237 | console.warning("fail to open service"); | |
238 | } | |
239 | }, | |
240 | filterServices: function (filter) { | |
241 | this.filter = filter; | |
242 | ||
243 | if (!filter) { | |
244 | this.services = this.config.services; | |
245 | return; | |
246 | } | |
247 | ||
248 | const searchResultItems = []; | |
249 | for (const group of this.config.services) { | |
250 | for (const item of group.items) { | |
251 | if (this.matchesFilter(item)) { | |
252 | searchResultItems.push(item); | |
253 | } | |
254 | } | |
255 | } | |
256 | ||
257 | this.services = [ | |
258 | { | |
259 | name: filter, | |
260 | icon: "fas fa-search", | |
9814a037 BW |
261 | items: searchResultItems, |
262 | }, | |
b9c5fcf0 | 263 | ]; |
9814a037 | 264 | }, |
bd910942 BW |
265 | handleErrors: function (title, content) { |
266 | return { | |
267 | message: { | |
268 | title: title, | |
269 | style: "is-danger", | |
270 | content: content, | |
271 | }, | |
272 | }; | |
273 | }, | |
ffe3404a BW |
274 | createStylesheet: function (css) { |
275 | let style = document.createElement("style"); | |
6777bc34 GC |
276 | style.appendChild(document.createTextNode(css)); |
277 | document.head.appendChild(style); | |
278 | }, | |
9814a037 | 279 | }, |
b9c5fcf0 BW |
280 | }; |
281 | </script> |