aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/components/Message.vue
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Message.vue')
-rw-r--r--src/components/Message.vue25
1 files changed, 18 insertions, 7 deletions
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 {
22 }, 22 },
23 data: function () { 23 data: function () {
24 return { 24 return {
25 show: false,
26 message: {}, 25 message: {},
27 }; 26 };
28 }, 27 },
@@ -30,14 +29,23 @@ export default {
30 // Look for a new message if an endpoint is provided. 29 // Look for a new message if an endpoint is provided.
31 this.message = Object.assign({}, this.item); 30 this.message = Object.assign({}, this.item);
32 await this.getMessage(); 31 await this.getMessage();
33 this.show = this.message.title || this.message.content;
34 }, 32 },
35 33 computed: {
34 show: function () {
35 return this.message.title || this.message.content;
36 },
37 },
38 watch: {
39 item: function (item) {
40 this.message = Object.assign({}, item);
41 },
42 },
36 methods: { 43 methods: {
37 getMessage: async function() { 44 getMessage: async function () {
38 if (this.item && this.item.url) { 45 if (this.item && this.item.url) {
39 let fetchedMessage = await this.downloadMessage(this.item.url); 46 let fetchedMessage = await this.downloadMessage(this.item.url);
40 if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); 47 if (this.item.mapping)
48 fetchedMessage = this.mapRemoteMessage(fetchedMessage);
41 // keep the original config value if no value is provided by the endpoint 49 // keep the original config value if no value is provided by the endpoint
42 for (const prop of ["title", "style", "content"]) { 50 for (const prop of ["title", "style", "content"]) {
43 if (prop in fetchedMessage && fetchedMessage[prop] !== null) { 51 if (prop in fetchedMessage && fetchedMessage[prop] !== null) {
@@ -45,7 +53,8 @@ export default {
45 } 53 }
46 } 54 }
47 } 55 }
48 if (this.item.refreshInterval) setTimeout(this.getMessage, this.item.refreshInterval); 56 if (this.item.refreshInterval)
57 setTimeout(this.getMessage, this.item.refreshInterval);
49 }, 58 },
50 59
51 downloadMessage: function (url) { 60 downloadMessage: function (url) {
@@ -60,7 +69,9 @@ export default {
60 mapRemoteMessage: function (message) { 69 mapRemoteMessage: function (message) {
61 let mapped = {}; 70 let mapped = {};
62 // map property from message into mapped according to mapping config (only if field has a value): 71 // map property from message into mapped according to mapping config (only if field has a value):
63 for (const prop in this.item.mapping) if (message[this.item.mapping[prop]]) mapped[prop] = message[this.item.mapping[prop]]; 72 for (const prop in this.item.mapping)
73 if (message[this.item.mapping[prop]])
74 mapped[prop] = message[this.item.mapping[prop]];
64 return mapped; 75 return mapped;
65 }, 76 },
66 }, 77 },