X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FApp.vue;h=1f1791ca616c0786236dc9901b7a131575e8f861;hb=5db2414d052af629e2848f53ce9c2e0e686eefaf;hp=fec020c36c265859a13af423cef9369a434e7c45;hpb=da6e676d6e42bb3e9a9feb212e152904330cff10;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/App.vue b/src/App.vue index fec020c..1f1791c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,8 +13,10 @@
{{ config.subtitle }} @@ -26,23 +28,27 @@ - +
@@ -51,7 +57,7 @@
@@ -62,12 +68,18 @@ @@ -85,12 +97,18 @@ >

+ {{ group.name }}

@@ -149,17 +167,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; @@ -173,15 +224,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 +276,11 @@ export default { }, }; }, + createStylesheet: function (css) { + let style = document.createElement("style"); + style.appendChild(document.createTextNode(css)); + document.head.appendChild(style); + }, }, };