X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FApp.vue;h=1f4f5099625a26583174a504bf862d0497e32661;hb=76a46c3507b5c0daef7edcb165e949dea4968e2f;hp=fddc5853a6f20acbbf961a520313192b9ba8f057;hpb=bd9109425a40f5b6c43147a7c9852014a5797dca;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/App.vue b/src/App.vue index fddc585..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,30 +161,70 @@ 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 () { - return fetch("config.yml") - .then((response) => { - if (!response.ok) { - throw Error(response.statusText); - } - return response.text().then((body) => { + 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}: ${response.body}`); + } + + const that = this; + return response + .text() + .then((body) => { return jsyaml.load(body); + }) + .then(function (config) { + if (config.externalConfig) { + 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)) ); }, @@ -215,6 +270,11 @@ export default { }, }; }, + createStylesheet: function (css) { + let style = document.createElement("style"); + style.appendChild(document.createTextNode(css)); + document.head.appendChild(style); + }, }, };