From 72617b4b759253dbacba9187560f8207df22b8d0 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 11 Apr 2022 23:16:29 +0200 Subject: [PATCH] Handle EntityUpdateEvents on the UI --- .../src/components/panels/Entities/Index.vue | 20 +++++++++++++++++++ .../src/components/panels/Entities/Switch.vue | 7 +------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue index 9cbf97bce..4bae4aafe 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue +++ b/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue @@ -136,9 +136,29 @@ export default { this.loading = false } }, + + onEntityUpdate(event) { + const entityId = event.entity.id + if (entityId == null) + return + + this.entities[entityId] = { + ...event.entity, + meta: { + ...(this.entities[entityId]?.meta || {}), + ...(event.entity?.meta || {}), + }, + } + }, }, mounted() { + this.subscribe( + this.onEntityUpdate, + 'on-entity-update', + 'platypush.message.event.entities.EntityUpdateEvent' + ) + this.refresh() }, } diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue index e8fcf1c99..7d49dcf2c 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue +++ b/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue @@ -34,15 +34,10 @@ export default { methods: { async toggle() { - const response = await this.request('entities.execute', { + await this.request('entities.execute', { id: this.value.id, action: 'toggle', }) - - this.$emit('input', { - ...this.value, - state: response.on, - }) }, }, }