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