X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FApp.vue;h=1f4f5099625a26583174a504bf862d0497e32661;hb=afe6d34ced84cb22868e26466f5e6928c5cd0d06;hp=a35699785df88cd9ebf2903e6118d64555c0f245;hpb=9814a037a5158d31c77fecc8bfb3b61b45d015b3;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/App.vue b/src/App.vue index a356997..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,33 +161,70 @@ export default { }; }, created: async function () { - try { + this.buildDashboard(); + window.onhashchange = this.buildDashboard; + }, + methods: { + buildDashboard: async function () { const defaults = jsyaml.load(defaultConfig); - let config = await this.getConfig(); + 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); - - console.log(this.config); this.services = this.config.services; - document.title = `${this.config.title} | ${this.config.subtitle}`; - } catch (error) { - this.offline = true; - } - }, - methods: { - getConfig: function () { - return fetch("config.yml").then(function (response) { - if (response.status != 200) { + 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; } - return response.text().then(function (body) { - return jsyaml.load(body); - }); + 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; + }); }); }, 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)) ); }, @@ -209,6 +261,20 @@ export default { }, ]; }, + handleErrors: function (title, content) { + return { + message: { + title: title, + style: "is-danger", + content: content, + }, + }; + }, + createStylesheet: function (css) { + let style = document.createElement("style"); + style.appendChild(document.createTextNode(css)); + document.head.appendChild(style); + }, }, };