Support for nested configuration objects on entity modals

This commit is contained in:
Fabio Manganiello 2023-01-03 23:16:14 +01:00
parent 13eb515f87
commit 7868d6fe37
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 82 additions and 8 deletions

View file

@ -15,9 +15,12 @@
</header> </header>
<div class="groups-canvas"> <div class="groups-canvas">
<EntityModal :entity="entities[modalEntityId]" <EntityModal
:visible="modalVisible" @close="onEntityModal" :entity="entities[modalEntityId]"
v-if="modalEntityId" :visible="modalVisible"
:config-values="configValuesByParentId(modalEntityId)"
@close="onEntityModal"
v-if="modalEntityId && entities[modalEntityId]"
/> />
<NoItems v-if="!Object.keys(displayGroups || {})?.length">No entities found</NoItems> <NoItems v-if="!Object.keys(displayGroups || {})?.length">No entities found</NoItems>
@ -240,6 +243,19 @@ export default {
}, {}) }, {})
}, },
configValuesByParentId(parentId) {
return Object.values(this.entities).
filter(
(entity) => entity
&& entity.parent_id === parentId
&& entity.is_configuration
).
reduce((obj, entity) => {
obj[entity.id] = entity
return obj
}, {})
},
clearEntityTimeouts(entityId) { clearEntityTimeouts(entityId) {
if (this.errorEntities[entityId]) if (this.errorEntities[entityId])
delete this.errorEntities[entityId] delete this.errorEntities[entityId]

View file

@ -1,5 +1,5 @@
<template> <template>
<Modal :visible="visible" class="entity-modal" :title="entity.name || entity.external_id"> <Modal :visible="visible" class="entity-modal" :title="entity.name || entity.external_id" v-if="entity">
<ConfirmDialog ref="deleteConfirmDiag" title="Confirm entity deletion" @input="onDelete"> <ConfirmDialog ref="deleteConfirmDiag" title="Confirm entity deletion" @input="onDelete">
Are you <b>sure</b> that you want to delete this entity? <br/><br/> 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 Note: you should only delete an entity if its plugin has been disabled
@ -101,6 +101,30 @@
</button> </button>
</div> </div>
</div> </div>
<div class="config-container"
v-if="computedConfig.length">
<div class="title"
@click="configCollapsed = !configCollapsed">
<div class="col-11">
<i class="fas fa-screwdriver-wrench" /> &nbsp;
Configuration
</div>
<div class="col-1 pull-right">
<i class="fas"
:class="{'fa-chevron-down': configCollapsed, 'fa-chevron-up': !configCollapsed}" />
</div>
</div>
<div class="entities" v-if="!configCollapsed">
<Entity
v-for="entity in computedConfig"
:key="entity.id"
:value="entity"
@input="$emit('input', entity)" />
</div>
</div>
</Modal> </Modal>
</template> </template>
@ -111,11 +135,12 @@ 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";
import meta from './meta.json' import Entity from "./Entity";
import meta from './meta.json';
export default { export default {
name: "Entity", name: "EntityModal",
components: {Modal, EditButton, NameEditor, Icon, ConfirmDialog}, components: {Entity, Modal, EditButton, NameEditor, Icon, ConfirmDialog},
mixins: [Utils], mixins: [Utils],
emits: ['input', 'loading'], emits: ['input', 'loading'],
props: { props: {
@ -128,6 +153,19 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
configValues: {
type: Object,
default: () => {},
},
},
computed: {
computedConfig() {
return Object.values(this.configValues).sort(
(a, b) => (a.name || '').localeCompare(b.name || '')
)
},
}, },
data() { data() {
@ -135,6 +173,7 @@ export default {
loading: false, loading: false,
editName: false, editName: false,
editIcon: false, editIcon: false,
configCollapsed: true,
} }
}, },
@ -211,10 +250,11 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
:deep(.modal) { :deep(.modal) {
.body { .body {
padding: .5em !important; padding: 0;
.table-row { .table-row {
box-shadow: none; box-shadow: none;
padding: 0.5em;
} }
} }
@ -256,5 +296,23 @@ export default {
color: $error-fg; color: $error-fg;
} }
} }
.config-container {
margin: 0;
.title {
display: flex;
padding: 1em;
text-transform: uppercase;
letter-spacing: 0.033em;
border-top: $default-border;
box-shadow: $border-shadow-bottom;
cursor: pointer;
&:hover {
background: $hover-bg;
}
}
}
} }
</style> </style>