mirror of
https://github.com/bastienwirtz/homer.git
synced 2025-12-17 21:59:50 +01:00
Adds mapping remote field to Homer expected ones when loading message from url
This commit is contained in:
@@ -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;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user