Persistence edit: Support excluding items or groups (#2896)

Ability to exclude items or groups from persistence configurations.

Refs https://github.com/openhab/openhab-core/pull/4468.

---------

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
pull/2909/head
Mark Herwege 2024-12-08 16:25:40 +01:00 committed by GitHub
parent 92dd646387
commit 320c3f57b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 43 additions and 8 deletions

View File

@ -34,6 +34,16 @@
:disabled="allItemsSelected" :value="items" @input="items = $event" />
<f7-list-item>... to be persisted.</f7-list-item>
</f7-list>
<f7-list>
<item-picker :key="'exclude-groups-' + excludeGroupItems.length" title="Select exclude groups" name="excludeGroupItems" multiple="true" filterType="Group"
:disabled="!anySelected" :value="excludeGroupItems" @input="excludeGroupItems = $event" />
<f7-list-item>... whose members are to be excluded from persistence.</f7-list-item>
</f7-list>
<f7-list>
<item-picker :key="'exclude-items-' + excludeItems.length" title="Select exclude Items" name="excludeItems" multiple="true"
:disabled="!anySelected" :value="excludeItems" @input="excludeItems = $event" />
<f7-list-item>... to be excluded from persistence.</f7-list-item>
</f7-list>
</f7-col>
<f7-col>
<f7-block-title medium class="padding-bottom">
@ -79,35 +89,60 @@ export default {
computed: {
groupItems: {
get () {
return this.currentConfiguration.items.filter((i) => i.length > 1 && i.endsWith('*')).map((i) => i.slice(0, -1))
return this.currentConfiguration.items.filter((i) => i.length > 1 && !i.startsWith('!') && i.endsWith('*')).map((i) => i.slice(0, -1))
},
set (newGroupItems) {
this.$set(this.currentConfiguration, 'items', newGroupItems.sort((a, b) => a.localeCompare(b)).map((i) => i + '*').concat(this.items))
this.$set(this.currentConfiguration, 'items', this.itemConfig(this.allItemsSelected, newGroupItems.sort((a, b) => a.localeCompare(b)), this.items, this.excludeGroupItems, this.excludeItems))
}
},
items: {
get () {
return this.currentConfiguration.items.filter((i) => !i.endsWith('*'))
return this.currentConfiguration.items.filter((i) => !i.startsWith('!') && !i.endsWith('*'))
},
set (newItems) {
this.$set(this.currentConfiguration, 'items', this.groupItems.map((i) => i + '*').concat(newItems.sort((a, b) => a.localeCompare(b))))
this.$set(this.currentConfiguration, 'items', this.itemConfig(this.allItemsSelected, this.groupItems, newItems.sort((a, b) => a.localeCompare(b)), this.excludeGroupItems, this.excludeItems))
}
},
excludeGroupItems: {
get () {
return this.currentConfiguration.items.filter((i) => i.startsWith('!') && i.endsWith('*')).map((i) => i.slice(1, -1))
},
set (newExcludeGroupItems) {
this.$set(this.currentConfiguration, 'items', this.itemConfig(this.allItemsSelected, this.groupItems, this.items, newExcludeGroupItems.sort((a, b) => a.localeCompare(b)), this.excludeItems))
}
},
excludeItems: {
get () {
return this.currentConfiguration.items.filter((i) => i.startsWith('!') && !i.endsWith('*')).map((i) => i.slice(1))
},
set (newExcludeItems) {
this.$set(this.currentConfiguration, 'items', this.itemConfig(this.allItemsSelected, this.groupItems, this.items, this.excludeGroupItems, newExcludeItems.sort((a, b) => a.localeCompare(b))))
}
},
allItemsSelected: {
get () {
return this.currentConfiguration.items.length === 1 && this.currentConfiguration.items[0] === '*'
return this.currentConfiguration.items.filter((i) => i === '*').length > 0
},
set (value) {
this.$set(this.currentConfiguration, 'items', value ? ['*'] : [])
set (newAllItemsSelected) {
this.$set(this.currentConfiguration, 'items', this.itemConfig(newAllItemsSelected, this.groupItems, this.items, this.excludeGroupItems, this.excludeItems))
}
},
anySelected: {
get () {
return this.allItemsSelected || (this.groupItems.length > 0) || (this.items.length > 0)
}
}
},
methods: {
itemConfig (allItemsSelected, groupItems, items, excludeGroupItems, excludeItems) {
return (allItemsSelected ? ['*'] : []).concat(groupItems.map((i) => i + '*')).concat(items).concat(excludeGroupItems.map((i) => '!' + i + '*')).concat(excludeItems.map((i) => '!' + i))
},
updateModuleConfig () {
if (this.currentConfiguration.items.length === 0) {
if (!this.anySelected) {
this.$f7.dialog.alert('Please select Items')
return
}
this.$set(this.currentConfiguration, 'items', this.itemConfig(this.allItemsSelected, this.allItemsSelected ? [] : this.groupItems, this.allItemsSelected ? [] : this.items, this.excludeGroupItems, this.excludeItems))
this.$f7.emit('configurationUpdate', this.currentConfiguration)
this.$refs.modulePopup.close()
}