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