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