Frontend support for entities deletion

This commit is contained in:
Fabio Manganiello 2022-04-24 21:40:10 +02:00
parent 9981cc4746
commit d261b9bb9b
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 51 additions and 1 deletions

View file

@ -256,6 +256,16 @@ export default {
this.entities[entityId] = entity this.entities[entityId] = entity
}, },
onEntityDelete(event) {
const entityId = event.entity?.id
if (entityId == null)
return
if (entityId === this.modalEntityId)
this.modalEntityId = null
if (this.entities[entityId])
delete this.entities[entityId]
},
onEntityModal(entityId) { onEntityModal(entityId) {
if (entityId) { if (entityId) {
this.modalEntityId = entityId this.modalEntityId = entityId
@ -274,6 +284,12 @@ export default {
'platypush.message.event.entities.EntityUpdateEvent' 'platypush.message.event.entities.EntityUpdateEvent'
) )
this.subscribe(
this.onEntityDelete,
'on-entity-delete',
'platypush.message.event.entities.EntityDeleteEvent'
)
this.sync() this.sync()
}, },
} }

View file

@ -1,5 +1,12 @@
<template> <template>
<Modal :visible="visible" :title="entity.name || entity.external_id"> <Modal :visible="visible" :title="entity.name || entity.external_id">
<ConfirmDialog ref="deleteConfirmDiag" title="Confirm entity deletion" @input="onDelete">
Are you <b>sure</b> that you want to delete this entity? <br/><br/>
Note: you should only delete an entity if its plugin has been disabled
or the entity is no longer reachable.<br/><br/>
Otherwise, the entity will simply be created again upon the next scan.
</ConfirmDialog>
<div class="table-row"> <div class="table-row">
<div class="title"> <div class="title">
Name Name
@ -78,12 +85,22 @@
<div class="title">Updated at</div> <div class="title">Updated at</div>
<div class="value" v-text="formatDateTime(entity.updated_at)" /> <div class="value" v-text="formatDateTime(entity.updated_at)" />
</div> </div>
<div class="table-row delete-entity-container">
<div class="title">Delete Entity</div>
<div class="value">
<button @click="$refs.deleteConfirmDiag.show()">
<i class="fas fa-trash" />
</button>
</div>
</div>
</Modal> </Modal>
</template> </template>
<script> <script>
import Modal from "@/components/Modal"; import Modal from "@/components/Modal";
import Icon from "@/components/elements/Icon"; import Icon from "@/components/elements/Icon";
import ConfirmDialog from "@/components/elements/ConfirmDialog";
import EditButton from "@/components/elements/EditButton"; import EditButton from "@/components/elements/EditButton";
import NameEditor from "@/components/elements/NameEditor"; import NameEditor from "@/components/elements/NameEditor";
import Utils from "@/Utils"; import Utils from "@/Utils";
@ -91,7 +108,7 @@ import meta from './meta.json'
export default { export default {
name: "Entity", name: "Entity",
components: {Modal, EditButton, NameEditor, Icon}, components: {Modal, EditButton, NameEditor, Icon, ConfirmDialog},
mixins: [Utils], mixins: [Utils],
emits: ['input', 'loading'], emits: ['input', 'loading'],
props: { props: {
@ -128,6 +145,16 @@ export default {
} }
}, },
async onDelete() {
this.loading = true
try {
await this.request('entities.delete', [this.entity.id])
} finally {
this.loading = false
}
},
async onIconEdit(newIcon) { async onIconEdit(newIcon) {
this.loading = true this.loading = true
@ -207,5 +234,12 @@ export default {
.help { .help {
font-size: 0.75em; font-size: 0.75em;
} }
.delete-entity-container {
color: $error-fg;
button {
color: $error-fg;
}
}
} }
</style> </style>