diff options
author | luixal <luixal@gmail.com> | 2021-01-04 09:43:58 +0100 |
---|---|---|
committer | luixal <luixal@gmail.com> | 2021-01-04 09:43:58 +0100 |
commit | 6d29bc27e78bc549479cbbc203c683137ace9d48 (patch) | |
tree | 29e7de508e38c4f01706e81e8176390e70e3ba0d /src | |
parent | 3786f80dae2df7780d19ba8ffd9374ef3c2fc30f (diff) | |
download | homer-6d29bc27e78bc549479cbbc203c683137ace9d48.tar.gz homer-6d29bc27e78bc549479cbbc203c683137ace9d48.tar.zst homer-6d29bc27e78bc549479cbbc203c683137ace9d48.zip |
Adds mapping remote field to Homer expected ones when loading message from url
Diffstat (limited to 'src')
-rw-r--r-- | src/components/Message.vue | 10 |
1 files changed, 9 insertions, 1 deletions
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 { | |||
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 | if (this.item && this.item.url) { |
33 | const fetchedMessage = await this.getMessage(this.item.url); | 33 | let fetchedMessage = await this.getMessage(this.item.url); |
34 | if (this.item.mapping) fetchedMessage = this.mapRemoteMessage(fetchedMessage); | ||
34 | // keep the original config value if no value is provided by the endpoint | 35 | // keep the original config value if no value is provided by the endpoint |
35 | for (const prop of ["title", "style", "content"]) { | 36 | for (const prop of ["title", "style", "content"]) { |
36 | if (prop in fetchedMessage && fetchedMessage[prop] !== null) { | 37 | if (prop in fetchedMessage && fetchedMessage[prop] !== null) { |
@@ -49,6 +50,13 @@ export default { | |||
49 | return response.json(); | 50 | return response.json(); |
50 | }); | 51 | }); |
51 | }, | 52 | }, |
53 | |||
54 | mapRemoteMessage: function (message) { | ||
55 | let mapped = {}; | ||
56 | // map property from message into mapped according to mapping config (only if field has a value): | ||
57 | for (const prop in this.item.mapping) if (message[this.item.mapping[prop]]) mapped[prop] = message[this.item.mapping[prop]]; | ||
58 | return mapped; | ||
59 | }, | ||
52 | }, | 60 | }, |
53 | }; | 61 | }; |
54 | </script> | 62 | </script> |