2 <article v-if="show" class="message" :class="message.style">
3 <div v-if="message.title || message.icon" class="message-header">
5 <i v-if="message.icon" :class="`fa-fw ${message.icon}`"></i>
10 v-if="message.content"
12 v-html="message.content"
29 created: async function () {
30 // Look for a new message if an endpoint is provided.
31 this.message = Object.assign({}, this.item);
32 await this.getMessage();
33 this.show = this.message.title || this.message.content;
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];
48 console.log(this.item.refreshInterval);
49 if (this.item.refreshInterval) setTimeout(this.getMessage, this.item.refreshInterval);
52 downloadMessage: function (url) {
53 return fetch(url).then(function (response) {
54 if (response.status != 200) {
57 return response.json();
61 mapRemoteMessage: function (message) {
63 // map property from message into mapped according to mapping config (only if field has a value):
64 for (const prop in this.item.mapping) if (message[this.item.mapping[prop]]) mapped[prop] = message[this.item.mapping[prop]];