]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - src/App.vue
Add some local changes
[github/bastienwirtz/homer.git] / src / App.vue
CommitLineData
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">
e0a72b7d 13 <section v-if="config.header" class="first-line is-hidden-touch">
b9c5fcf0
BW
14 <div v-cloak class="container">
15 <div class="logo">
3bf0edcf 16 <img v-if="config.logo" :src="config.logo" alt="dashboard logo" />
b9c5fcf0
BW
17 <i v-if="config.icon" :class="config.icon"></i>
18 </div>
19 <div class="dashboard-title">
20 <span class="headline">{{ config.subtitle }}</span>
21 <h1>{{ config.title }}</h1>
22 </div>
23 </div>
24 </section>
25
26 <Navbar
27 :open="showMenu"
28 :links="config.links"
29 @navbar:toggle="showMenu = !showMenu"
e0a72b7d
IB
30 :navigateToFirstService="navigateToFirstService"
31 :filterServices="filterServices"
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 />
b9c5fcf0
BW
41 </Navbar>
42 </div>
43
44 <section id="main-section" class="section">
45 <div v-cloak class="container">
e9113b48
BW
46 <ConnectivityChecker
47 v-if="config.connectivityCheck"
48 @network:status-update="offline = $event"
49 />
b9c5fcf0
BW
50 <div v-if="!offline">
51 <!-- Optional messages -->
52 <Message :item="config.message" />
53
54 <!-- Horizontal layout -->
55 <div v-if="!vlayout || filter" class="columns is-multiline">
56 <template v-for="group in services">
57 <h2 v-if="group.name" class="column is-full group-title">
58 <i v-if="group.icon" :class="group.icon"></i>
59 {{ group.name }}
60 </h2>
61 <Service
62 v-for="item in group.items"
1a42e30a 63 :key="item.name"
b9c5fcf0 64 v-bind:item="item"
e0a72b7d 65 class="column is-half-tablet is-one-third-widescreen is-half-desktop"
b9c5fcf0
BW
66 />
67 </template>
68 </div>
69
70 <!-- Vertical layout -->
71 <div
72 v-if="!filter && vlayout"
73 class="columns is-multiline layout-vertical"
74 >
75 <div
e0a72b7d 76 class="column is-half-tablet is-one-third-widescreen is-half-desktop"
b9c5fcf0
BW
77 v-for="group in services"
78 :key="group.name"
79 >
80 <h2 v-if="group.name" class="group-title">
81 <i v-if="group.icon" :class="group.icon"></i>
82 {{ group.name }}
83 </h2>
84 <Service
85 v-for="item in group.items"
86 v-bind:item="item"
87 :key="item.url"
88 />
89 </div>
90 </div>
91 </div>
92 </div>
93 </section>
94
95 <footer class="footer">
96 <div class="container">
97 <div
98 class="content has-text-centered"
99 v-if="config.footer"
100 v-html="config.footer"
101 ></div>
102 </div>
103 </footer>
104 </div>
105</template>
106
107<script>
108const jsyaml = require("js-yaml");
109const merge = require("lodash.merge");
110
111import Navbar from "./components/Navbar.vue";
112import ConnectivityChecker from "./components/ConnectivityChecker.vue";
113import Service from "./components/Service.vue";
114import Message from "./components/Message.vue";
b9c5fcf0
BW
115import SettingToggle from "./components/SettingToggle.vue";
116import DarkMode from "./components/DarkMode.vue";
117import DynamicTheme from "./components/DynamicTheme.vue";
118
119import defaultConfig from "./assets/defaults.yml";
120
121export default {
122 name: "App",
123 components: {
124 Navbar,
125 ConnectivityChecker,
126 Service,
127 Message,
b9c5fcf0
BW
128 SettingToggle,
129 DarkMode,
9814a037 130 DynamicTheme,
b9c5fcf0
BW
131 },
132 data: function () {
133 return {
134 config: null,
135 services: null,
136 offline: false,
137 filter: "",
e0a72b7d 138 vlayout: false,
b9c5fcf0 139 isDark: null,
9814a037 140 showMenu: false,
b9c5fcf0
BW
141 };
142 },
143 created: async function () {
bd910942
BW
144 const defaults = jsyaml.load(defaultConfig);
145 let config = await this.getConfig();
146 this.config = merge(defaults, config);
147 this.services = this.config.services;
148 document.title = `${this.config.title} | ${this.config.subtitle}`;
b9c5fcf0
BW
149 },
150 methods: {
1a42e30a
BW
151 getConfig: function (path = "config.yml") {
152 return fetch(path).then((response) => {
153 if (!response.ok) {
154 throw Error(response.statusText);
155 }
156
157 const that = this;
158 return response
159 .text()
160 .then((body) => {
bd910942 161 return jsyaml.load(body);
1a42e30a
BW
162 })
163 .then(function (config) {
164 if (config.externalConfig) {
165 return that.getConfig(config.externalConfig);
166 }
167 return config;
168 })
169 .catch((error) => {
170 return this.handleErrors("⚠️ Error loading configuration", error);
bd910942 171 });
1a42e30a 172 });
b9c5fcf0
BW
173 },
174 matchesFilter: function (item) {
175 return (
176 item.name.toLowerCase().includes(this.filter) ||
177 (item.tag && item.tag.toLowerCase().includes(this.filter))
178 );
179 },
180 navigateToFirstService: function (target) {
181 try {
182 const service = this.services[0].items[0];
183 window.open(service.url, target || service.target || "_self");
184 } catch (error) {
185 console.warning("fail to open service");
186 }
187 },
188 filterServices: function (filter) {
189 this.filter = filter;
190
191 if (!filter) {
192 this.services = this.config.services;
193 return;
194 }
195
196 const searchResultItems = [];
197 for (const group of this.config.services) {
198 for (const item of group.items) {
199 if (this.matchesFilter(item)) {
200 searchResultItems.push(item);
201 }
202 }
203 }
204
205 this.services = [
206 {
207 name: filter,
208 icon: "fas fa-search",
9814a037
BW
209 items: searchResultItems,
210 },
b9c5fcf0 211 ];
9814a037 212 },
bd910942
BW
213 handleErrors: function (title, content) {
214 return {
215 message: {
216 title: title,
217 style: "is-danger",
218 content: content,
219 },
220 };
221 },
9814a037 222 },
b9c5fcf0
BW
223};
224</script>