X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FApp.vue;h=1f1791ca616c0786236dc9901b7a131575e8f861;hb=5db2414d052af629e2848f53ce9c2e0e686eefaf;hp=8185da212c260f672ec5defd9957349a918c6d63;hpb=5fa6b6cfa6b3010279ead23088add5c5664e8ac0;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/App.vue b/src/App.vue index 8185da2..1f1791c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,7 +13,9 @@
@@ -26,30 +28,37 @@ - +
- +
@@ -58,14 +67,20 @@
@@ -76,18 +91,24 @@ class="columns is-multiline layout-vertical" >

- + + {{ group.name }}

@@ -146,31 +167,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); 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)) ); }, @@ -207,6 +267,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); + }, }, };