diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/Message.vue | 29 |
1 files changed, 18 insertions, 11 deletions
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 { | |||
29 | created: async function () { | 29 | created: async function () { |
30 | // Look for a new message if an endpoint is provided. | 30 | // Look for a new message if an endpoint is provided. |
31 | this.message = Object.assign({}, this.item); | 31 | this.message = Object.assign({}, this.item); |
32 | if (this.item && this.item.url) { | 32 | await this.getMessage(); |
33 | let fetchedMessage = await this.getMessage(this.item.url); | ||
34 | if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); | ||
35 | // keep the original config value if no value is provided by the endpoint | ||
36 | for (const prop of ["title", "style", "content"]) { | ||
37 | if (prop in fetchedMessage && fetchedMessage[prop] !== null) { | ||
38 | this.message[prop] = fetchedMessage[prop]; | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | this.show = this.message.title || this.message.content; | 33 | this.show = this.message.title || this.message.content; |
43 | }, | 34 | }, |
35 | |||
44 | methods: { | 36 | methods: { |
45 | getMessage: function (url) { | 37 | getMessage: async function() { |
38 | if (this.item && this.item.url) { | ||
39 | let fetchedMessage = await this.downloadMessage(this.item.url); | ||
40 | if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); | ||
41 | // keep the original config value if no value is provided by the endpoint | ||
42 | for (const prop of ["title", "style", "content"]) { | ||
43 | if (prop in fetchedMessage && fetchedMessage[prop] !== null) { | ||
44 | this.message[prop] = fetchedMessage[prop]; | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | console.log(this.item.refreshInterval); | ||
49 | if (this.item.refreshInterval) setTimeout(this.getMessage, this.item.refreshInterval); | ||
50 | }, | ||
51 | |||
52 | downloadMessage: function (url) { | ||
46 | return fetch(url).then(function (response) { | 53 | return fetch(url).then(function (response) { |
47 | if (response.status != 200) { | 54 | if (response.status != 200) { |
48 | return; | 55 | return; |