diff --git a/bundles/org.openhab.ui/web/src/pages/settings/persistence/configuration-popup.vue b/bundles/org.openhab.ui/web/src/pages/settings/persistence/configuration-popup.vue
index 0c413a6ae5..0f37f97c17 100644
--- a/bundles/org.openhab.ui/web/src/pages/settings/persistence/configuration-popup.vue
+++ b/bundles/org.openhab.ui/web/src/pages/settings/persistence/configuration-popup.vue
@@ -21,12 +21,12 @@
s
)',
+ label: 'Unit',
+ name: 'unit',
+ required: false,
+ type: 'STRING'
+ }
+ ]
+ },
+ {
+ name: 'equalsFilters',
+ label: 'Equals/Not Equals',
+ configDescriptionParameters: [
+ {
+ advanced: false,
+ description: 'Enter values seperated by comma (use point .
as decimal point), e.g. one, two, three
, to be persisted',
+ label: 'Values',
+ name: 'values',
+ required: true,
+ type: ''
+ },
+ filterInvertedParameter
+ ]
+ },
+ {
+ name: 'includeFilters',
+ label: 'Include/Exclude',
+ configDescriptionParameters: [
+ {
+ advanced: false,
+ description: 'Lower bound of the range of value to be persisted',
+ label: 'Lower Bound',
+ name: 'lower',
+ required: true,
+ type: 'DECIMAL'
+ },
+ {
+ advanced: false,
+ description: 'Lower bound of the range of value to be persisted',
+ label: 'Upper Bound',
+ name: 'upper',
+ required: true,
+ type: 'DECIMAL'
+ },
+ {
+ advanced: false,
+ description: 'Unit of the given bounds, only used for UoM Items',
+ label: 'Unit',
+ name: 'unit',
+ required: false,
+ type: 'STRING'
+ },
+ filterInvertedParameter
+ ]
+ }
+ ],
notEditableMgs: 'This persistence configuration is not editable because it has been provisioned from a file.'
}
},
@@ -197,6 +359,14 @@ export default {
},
strategies () {
return this.predefinedStrategies.concat(this.persistence.cronStrategies.map(cs => cs.name))
+ },
+ filters () {
+ let names = []
+ for (let i = 0; i < this.filterTypes.length; i++) {
+ const filterTypeName = this.filterTypes[i].name
+ if (this.persistence[filterTypeName]) names = names.concat(this.persistence[filterTypeName].map((f) => f.name))
+ }
+ return names
}
},
watch: {
@@ -271,6 +441,21 @@ export default {
save (noToast) {
if (!this.isEditable) return
if (this.currentTab === 'code') this.fromYaml()
+
+ // Ensure relative is set on threshold filter, otherwise the save request fails with a 500
+ this.persistence.thresholdFilters.forEach((f) => {
+ if (f.relative === undefined) f.relative = false
+ })
+ // Ensure inverted is set for equals and include filter, otherwise the save request fails with a 500
+ this.persistence.equalsFilters.forEach((f) => {
+ if (f.inverted === undefined) f.inverted = false
+ })
+ this.persistence.includeFilters.forEach((f) => {
+ if (f.inverted === undefined) f.inverted = false
+ })
+ // Update the code tab
+ if (this.persistenceYaml) this.toYaml()
+
return this.$oh.api.put('/rest/persistence/' + this.persistence.serviceId, this.persistence).then((data) => {
this.dirty = false
if (this.newPersistence) {
@@ -331,7 +516,8 @@ export default {
}, {
props: {
configuration: this.currentConfiguration,
- strategies: this.strategies
+ strategies: this.strategies,
+ filters: this.filters
}
})
@@ -339,7 +525,7 @@ export default {
},
saveConfiguration (index, configuration) {
const idx = this.persistence.configs.findIndex((cfg) => cfg.items.join() === configuration.items.join())
- if (idx !== -1 && idx !== index) {
+ if (idx !== -1 && idx === index) {
this.$f7.dialog.alert('A configuration for this/these Item(s) already exists!')
return
}
@@ -368,12 +554,49 @@ export default {
},
saveCronStrategy (index, cronStrategy) {
const idx = this.persistence.cronStrategies.findIndex((cs) => cs.name === cronStrategy.name)
- if ((idx !== -1 && idx !== index) || this.predefinedStrategies.includes(cronStrategy.name)) {
+ if ((idx !== -1 && idx === index) || this.predefinedStrategies.includes(cronStrategy.name)) {
this.$f7.dialog.alert('A (cron) strategy with the same name already exists!')
return
}
this.saveModule('cronStrategies', index, cronStrategy)
},
+ editFilter (ev, filterType, index, filter) {
+ if (!this.isEditable) return
+ this.currentFilter = filter
+
+ // Stringify values array from equals filter
+ if (filterType.name === 'equalsFilters' && filter) filter.values = filter.values.join(', ')
+
+ const popup = {
+ component: FilterPopup
+ }
+ this.$f7router.navigate({
+ url: 'filter-config',
+ route: {
+ path: 'filter-config',
+ popup
+ }
+ }, {
+ props: {
+ filter: this.currentFilter,
+ filterType: filterType,
+ filterConfigDescriptionParameters: filterType.configDescriptionParameters
+ }
+ })
+
+ this.$f7.once('filterUpdate', (ev, ftn) => this.saveFilter(ftn, index, ev))
+ },
+ saveFilter (filterTypeName, index, filter) {
+ const idx = this.filters.findIndex((f) => f === filter.name)
+ if (index === null && idx !== -1) {
+ this.$f7.dialog.alert('A filter with the same name already exists!')
+ return
+ }
+ // Convert comma separated string to array for equals filter
+ if (filterTypeName === 'equalsFilters') filter.values = filter.values.split(',').map((v) => v.trim())
+
+ this.saveModule(filterTypeName, index, filter)
+ },
saveModule (module, index, updatedModule) {
if (index === null) {
console.debug(`Adding ${module}:`)
@@ -409,7 +632,9 @@ export default {
cronStrategies: this.persistence.cronStrategies,
defaultStrategies: this.persistence.defaults,
thresholdFilters: this.persistence.thresholdFilters,
- timeFilters: this.persistence.timeFilters
+ timeFilters: this.persistence.timeFilters,
+ equalsFilters: this.persistence.equalsFilters,
+ includeFilters: this.persistence.includeFilters
})
},
fromYaml () {
@@ -421,6 +646,8 @@ export default {
this.$set(this.persistence, 'defaults', updatedPersistence.defaultStrategies)
this.$set(this.persistence, 'thresholdFilters', updatedPersistence.thresholdFilters)
this.$set(this.persistence, 'timeFilters', updatedPersistence.timeFilters)
+ this.$set(this.persistence, 'equalsFilters', updatedPersistence.equalsFilters)
+ this.$set(this.persistence, 'includeFilters', updatedPersistence.includeFilters)
return true
} catch (e) {
this.$f7.dialog.alert(e).open()