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