X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FApp.vue;h=fda13c31e07ef4cb7bcf5f1e50365d29f8fe4e65;hb=585844394d7a4cc4a58e30fd42cb1f8e83ac02f7;hp=62156d2ce9a87658a4145808d4bf355ea7cb75be;hpb=e9113b48cec284b041e4130e6afe932913f52d36;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/App.vue b/src/App.vue index 62156d2..fda13c3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,7 +13,9 @@
@@ -26,23 +28,28 @@ - +
@@ -51,8 +58,11 @@
+ + +
@@ -61,14 +71,20 @@
@@ -79,18 +95,24 @@ class="columns is-multiline layout-vertical" >

- + + {{ group.name }}

@@ -115,6 +137,7 @@ const jsyaml = require("js-yaml"); const merge = require("lodash.merge"); import Navbar from "./components/Navbar.vue"; +import GetStarted from "./components/GetStarted.vue"; import ConnectivityChecker from "./components/ConnectivityChecker.vue"; import Service from "./components/Service.vue"; import Message from "./components/Message.vue"; @@ -129,6 +152,7 @@ export default { name: "App", components: { Navbar, + GetStarted, ConnectivityChecker, Service, Message, @@ -139,6 +163,7 @@ export default { }, data: function () { return { + loaded: false, config: null, services: null, offline: false, @@ -149,17 +174,58 @@ export default { }; }, created: async function () { - const defaults = jsyaml.load(defaultConfig); - let config = await this.getConfig(); - this.config = merge(defaults, config); - this.services = this.config.services; - document.title = `${this.config.title} | ${this.config.subtitle}`; + this.buildDashboard(); + window.onhashchange = this.buildDashboard; + this.loaded = true; }, methods: { - getConfig: function (path = "config.yml") { + searchHotkey() { + if (this.config.hotkey && this.config.hotkey.search) { + return this.config.hotkey.search; + } + }, + buildDashboard: async function () { + const defaults = jsyaml.load(defaultConfig); + let config; + try { + config = await this.getConfig(); + const path = + window.location.hash.substring(1) != "" + ? window.location.hash.substring(1) + : null; + + if (path) { + let pathConfig = await this.getConfig(`assets/${path}.yml`); // the slash (/) is included in the pathname + config = Object.assign(config, pathConfig); + } + } catch (error) { + console.log(error); + config = this.handleErrors("⚠️ Error loading configuration", error); + } + this.config = merge(defaults, config); + this.services = this.config.services; + + document.title = + this.config.documentTitle || + `${this.config.title} | ${this.config.subtitle}`; + if (this.config.stylesheet) { + let stylesheet = ""; + for (const file of this.config.stylesheet) { + stylesheet += `@import "${file}";`; + } + this.createStylesheet(stylesheet); + } + }, + getConfig: function (path = "assets/config.yml") { return fetch(path).then((response) => { + if (response.redirected) { + // This allows to work with authentication proxies. + window.location.href = response.url; + return; + } + if (!response.ok) { - throw Error(response.statusText); + throw Error(`${response.statusText}: ${response.body}`); } const that = this; @@ -173,15 +239,13 @@ export default { return that.getConfig(config.externalConfig); } return config; - }) - .catch((error) => { - return this.handleErrors("⚠️ Error loading configuration", error); }); }); }, matchesFilter: function (item) { return ( item.name.toLowerCase().includes(this.filter) || + (item.subtitle && item.subtitle.toLowerCase().includes(this.filter)) || (item.tag && item.tag.toLowerCase().includes(this.filter)) ); }, @@ -227,6 +291,11 @@ export default { }, }; }, + createStylesheet: function (css) { + let style = document.createElement("style"); + style.appendChild(document.createTextNode(css)); + document.head.appendChild(style); + }, }, };