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