X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FApp.vue;h=1f4f5099625a26583174a504bf862d0497e32661;hb=afe6d34ced84cb22868e26466f5e6928c5cd0d06;hp=440ffa088e5b5e4b70248b973b931d8b574d0e3c;hpb=1a42e30a1752be5ab0fba5b224fad5686f12499e;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/App.vue b/src/App.vue index 440ffa0..1f4f509 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,7 +13,9 @@
@@ -26,7 +28,7 @@ @@ -40,16 +42,19 @@
- +
@@ -58,14 +63,19 @@
@@ -76,18 +86,23 @@ class="columns is-multiline layout-vertical" >

- + + {{ group.name }}

@@ -146,17 +161,50 @@ 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; }, methods: { - getConfig: function (path = "config.yml") { + 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; @@ -170,15 +218,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)) ); }, @@ -224,6 +270,11 @@ export default { }, }; }, + createStylesheet: function (css) { + let style = document.createElement("style"); + style.appendChild(document.createTextNode(css)); + document.head.appendChild(style); + }, }, };