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