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