From 6d29bc27e78bc549479cbbc203c683137ace9d48 Mon Sep 17 00:00:00 2001 From: luixal Date: Mon, 4 Jan 2021 09:43:58 +0100 Subject: Adds mapping remote field to Homer expected ones when loading message from url --- src/components/Message.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/components/Message.vue') diff --git a/src/components/Message.vue b/src/components/Message.vue index 5a1e0ea..df203ae 100644 --- a/src/components/Message.vue +++ b/src/components/Message.vue @@ -30,7 +30,8 @@ export default { // Look for a new message if an endpoint is provided. this.message = Object.assign({}, this.item); if (this.item && this.item.url) { - const fetchedMessage = await this.getMessage(this.item.url); + let fetchedMessage = await this.getMessage(this.item.url); + if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); // keep the original config value if no value is provided by the endpoint for (const prop of ["title", "style", "content"]) { if (prop in fetchedMessage && fetchedMessage[prop] !== null) { @@ -49,6 +50,13 @@ export default { return response.json(); }); }, + + mapRemoteMessage: function (message) { + let mapped = {}; + // map property from message into mapped according to mapping config (only if field has a value): + for (const prop in this.item.mapping) if (message[this.item.mapping[prop]]) mapped[prop] = message[this.item.mapping[prop]]; + return mapped; + }, }, }; -- cgit v1.2.3 From 1ddf394176ffe7e1c4118ead46b9fa76c6f3c614 Mon Sep 17 00:00:00 2001 From: luixal Date: Thu, 7 Jan 2021 21:23:13 +0100 Subject: Refactors created function (splits logic for getting message) and adds timeout according to refreshInterval field --- src/components/Message.vue | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/components/Message.vue') diff --git a/src/components/Message.vue b/src/components/Message.vue index df203ae..72106c2 100644 --- a/src/components/Message.vue +++ b/src/components/Message.vue @@ -29,20 +29,27 @@ export default { created: async function () { // Look for a new message if an endpoint is provided. this.message = Object.assign({}, this.item); - if (this.item && this.item.url) { - let fetchedMessage = await this.getMessage(this.item.url); - if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); - // keep the original config value if no value is provided by the endpoint - for (const prop of ["title", "style", "content"]) { - if (prop in fetchedMessage && fetchedMessage[prop] !== null) { - this.message[prop] = fetchedMessage[prop]; - } - } - } + await this.getMessage(); this.show = this.message.title || this.message.content; }, + methods: { - getMessage: function (url) { + getMessage: async function() { + if (this.item && this.item.url) { + let fetchedMessage = await this.downloadMessage(this.item.url); + if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); + // keep the original config value if no value is provided by the endpoint + for (const prop of ["title", "style", "content"]) { + if (prop in fetchedMessage && fetchedMessage[prop] !== null) { + this.message[prop] = fetchedMessage[prop]; + } + } + } + console.log(this.item.refreshInterval); + if (this.item.refreshInterval) setTimeout(this.getMessage, this.item.refreshInterval); + }, + + downloadMessage: function (url) { return fetch(url).then(function (response) { if (response.status != 200) { return; -- cgit v1.2.3 From b6782c92b5ee91c4d6ac19ee01768363d4f0dc8b Mon Sep 17 00:00:00 2001 From: luixal Date: Thu, 7 Jan 2021 21:26:22 +0100 Subject: Removes forgotten console.log --- src/components/Message.vue | 1 - 1 file changed, 1 deletion(-) (limited to 'src/components/Message.vue') diff --git a/src/components/Message.vue b/src/components/Message.vue index 72106c2..2f71f3f 100644 --- a/src/components/Message.vue +++ b/src/components/Message.vue @@ -45,7 +45,6 @@ export default { } } } - console.log(this.item.refreshInterval); if (this.item.refreshInterval) setTimeout(this.getMessage, this.item.refreshInterval); }, -- cgit v1.2.3 From ba07da6b1011e77c9ed42e8643e62b903c6c6d7b Mon Sep 17 00:00:00 2001 From: Bastien Wirtz Date: Sat, 6 Mar 2021 22:50:58 -0800 Subject: Avoid full reload when swithcing page. --- src/components/Message.vue | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/components/Message.vue') diff --git a/src/components/Message.vue b/src/components/Message.vue index 2f71f3f..7c6acdd 100644 --- a/src/components/Message.vue +++ b/src/components/Message.vue @@ -22,7 +22,6 @@ export default { }, data: function () { return { - show: false, message: {}, }; }, @@ -30,14 +29,23 @@ export default { // Look for a new message if an endpoint is provided. this.message = Object.assign({}, this.item); await this.getMessage(); - this.show = this.message.title || this.message.content; }, - + computed: { + show: function () { + return this.message.title || this.message.content; + }, + }, + watch: { + item: function (item) { + this.message = Object.assign({}, item); + }, + }, methods: { - getMessage: async function() { + getMessage: async function () { if (this.item && this.item.url) { let fetchedMessage = await this.downloadMessage(this.item.url); - if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); + if (this.item.mapping) + fetchedMessage = this.mapRemoteMessage(fetchedMessage); // keep the original config value if no value is provided by the endpoint for (const prop of ["title", "style", "content"]) { if (prop in fetchedMessage && fetchedMessage[prop] !== null) { @@ -45,7 +53,8 @@ export default { } } } - if (this.item.refreshInterval) setTimeout(this.getMessage, this.item.refreshInterval); + if (this.item.refreshInterval) + setTimeout(this.getMessage, this.item.refreshInterval); }, downloadMessage: function (url) { @@ -60,7 +69,9 @@ export default { mapRemoteMessage: function (message) { let mapped = {}; // map property from message into mapped according to mapping config (only if field has a value): - for (const prop in this.item.mapping) if (message[this.item.mapping[prop]]) mapped[prop] = message[this.item.mapping[prop]]; + for (const prop in this.item.mapping) + if (message[this.item.mapping[prop]]) + mapped[prop] = message[this.item.mapping[prop]]; return mapped; }, }, -- cgit v1.2.3 From 7596bc527f5b995bedd6a77ed71b6e1feba1364d Mon Sep 17 00:00:00 2001 From: Bastien Wirtz Date: Wed, 21 Apr 2021 22:09:01 -0700 Subject: Fix null error releated to refreshInterval + cleanup. Fix #210 --- src/components/Message.vue | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/components/Message.vue') diff --git a/src/components/Message.vue b/src/components/Message.vue index 7c6acdd..6cc649a 100644 --- a/src/components/Message.vue +++ b/src/components/Message.vue @@ -42,19 +42,29 @@ export default { }, methods: { getMessage: async function () { - if (this.item && this.item.url) { + if (!this.item) { + return; + } + if (this.item.url) { let fetchedMessage = await this.downloadMessage(this.item.url); - if (this.item.mapping) + console.log("done"); + if (this.item.mapping) { fetchedMessage = this.mapRemoteMessage(fetchedMessage); + } + // keep the original config value if no value is provided by the endpoint + const message = this.message; for (const prop of ["title", "style", "content"]) { if (prop in fetchedMessage && fetchedMessage[prop] !== null) { - this.message[prop] = fetchedMessage[prop]; + message[prop] = fetchedMessage[prop]; } } + this.message = { ...message }; // Force computed property to re-evaluate } - if (this.item.refreshInterval) + + if (this.item.refreshInterval) { setTimeout(this.getMessage, this.item.refreshInterval); + } }, downloadMessage: function (url) { -- cgit v1.2.3 From 742ae4eb528df6803d6b575b7a60a1e68d8d7e4d Mon Sep 17 00:00:00 2001 From: Tom Pansino <2768420+tpansino@users.noreply.github.com> Date: Sat, 15 May 2021 02:20:51 -0700 Subject: Support passing FA icon in message URL payload --- src/components/Message.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components/Message.vue') diff --git a/src/components/Message.vue b/src/components/Message.vue index 6cc649a..00ce158 100644 --- a/src/components/Message.vue +++ b/src/components/Message.vue @@ -54,7 +54,7 @@ export default { // keep the original config value if no value is provided by the endpoint const message = this.message; - for (const prop of ["title", "style", "content"]) { + for (const prop of ["title", "style", "content", "icon"]) { if (prop in fetchedMessage && fetchedMessage[prop] !== null) { message[prop] = fetchedMessage[prop]; } -- cgit v1.2.3