X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FApp.vue;h=fda13c31e07ef4cb7bcf5f1e50365d29f8fe4e65;hb=585844394d7a4cc4a58e30fd42cb1f8e83ac02f7;hp=d7054a7f453c8e0bd03eb0f64975482c44722d44;hpb=0ae40f78f837e95ba2ccb04025c6bebcc09d7ab4;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/App.vue b/src/App.vue index d7054a7..fda13c3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,8 +13,10 @@
{{ config.subtitle }} @@ -26,23 +28,28 @@ - +
@@ -51,8 +58,11 @@
+ + +
@@ -62,12 +72,18 @@ @@ -85,12 +101,18 @@ >

+ {{ 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,19 +174,48 @@ export default { }; }, created: async function () { - const defaults = jsyaml.load(defaultConfig); - let config; - try { - config = await this.getConfig(); - } 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.title} | ${this.config.subtitle}`; + this.buildDashboard(); + window.onhashchange = this.buildDashboard; + this.loaded = true; }, methods: { + 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) { @@ -169,6 +223,7 @@ export default { window.location.href = response.url; return; } + if (!response.ok) { throw Error(`${response.statusText}: ${response.body}`); } @@ -190,6 +245,7 @@ export default { 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)) ); }, @@ -235,6 +291,11 @@ export default { }, }; }, + createStylesheet: function (css) { + let style = document.createElement("style"); + style.appendChild(document.createTextNode(css)); + document.head.appendChild(style); + }, }, };