Skip to content

Commit

Permalink
Add a persistence configuration page
Browse files Browse the repository at this point in the history
It is accessible from the add-on settings page and has both a design and a code tab.

The design tab allows to set persistence strategies for Items, define cron strategies and set the default strategies.
It does not duplicate names for (cron) persistence strategies and duplicate configs for the same set of Items.

The code tab also allows to also specify threshold and time filters and needs minor adjustment once openhab/openhab-core#3642 is merged code completion is not provided.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 committed Jun 6, 2023
1 parent a8ef9cc commit 7890b94
Show file tree
Hide file tree
Showing 6 changed files with 649 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bundles/org.openhab.ui/web/src/js/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const InboxListPage = () => import(/* webpackChunkName: "admin-config" */ '../pa
const TransformationsListPage = () => import(/* webpackChunkName: "admin-config" */ '../pages/settings/transformations/transformations-list.vue')
const TransformationsEditPage = () => import(/* webpackChunkName: "admin-rules" */ '../pages/settings/transformations/transformation-edit.vue')

const PersistenceEditPage = () => import(/* webpackChunkName: "admin-config" */ '../pages/settings/persistence/persistence-edit.vue')

const SemanticModelPage = () => import(/* webpackChunkName: "admin-config" */ '../pages/settings/model/model.vue')

const PagesListPage = () => import(/* webpackChunkName: "admin-pages" */ '../pages/settings/pages/pages-list.vue')
Expand Down Expand Up @@ -237,6 +239,17 @@ export default [
beforeEnter: [enforceAdminForRoute],
async: loadAsync(SemanticModelPage)
},
{
path: 'persistence/',
routes: [
{
path: ':serviceId',
beforeEnter: [enforceAdminForRoute],
beforeLeave: [checkDirtyBeforeLeave],
async: loadAsync(PersistenceEditPage)
}
]
},
{
path: 'rules/',
beforeEnter: [enforceAdminForRoute],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
</f7-link>
</f7-nav-right>
</f7-navbar>
<f7-block v-if="type === 'persistence'" class="service-config block-narrow">
<f7-col>
<f7-block-title medium>
<f7-link color="blue" :href="'/settings/persistence/' + name">
Persistence configuration
</f7-link>
</f7-block-title>
</f7-col>
</f7-block>
<f7-block form v-if="configDescription && config" class="service-config block-narrow">
<f7-col>
<f7-block-title medium>
Expand Down Expand Up @@ -74,6 +83,14 @@ export default {
strippedAddonId: ''
}
},
computed: {
type () {
return this.addonId.split('-')[0]
},
name () {
return this.addonId.split('-')[1]
}
},
methods: {
save () {
let promises = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<f7-popup ref="modulePopup" class="moduleconfig-popup">
<f7-page>
<f7-navbar>
<f7-nav-left>
<f7-link icon-ios="f7:arrow_left" icon-md="material:arrow_back" icon-aurora="f7:arrow_left" popup-close />
</f7-nav-left>
<f7-nav-title>
Configure strategies and filters for Item(s)
</f7-nav-title>
<f7-nav-right>
<f7-link v-show="currentConfiguration.items.length > 0" @click="updateModuleConfig">
Done
</f7-link>
</f7-nav-right>
</f7-navbar>
<f7-block>
<f7-block-title>Items</f7-block-title>
<f7-list>
<item-picker title="Select groups whose Items are to be persisted" name="groupItems" multiple="true"
filterType="Group" :value="groupItems" @input="selectGroupItems" />
<item-picker title="Select Items to be persisted" name="items" multiple="true" :value="items"
@input="selectItems" />
</f7-list>
</f7-block>
<f7-block>
<f7-block-title>Strategies</f7-block-title>
<strategy-picker title="Select Strategies" name="strategies" :strategies="strategies"
:value="currentConfiguration.strategies"
@strategiesSelected="currentConfiguration.strategies = $event" />
</f7-block>
</f7-page>
</f7-popup>
</template>

<script>
import ItemPicker from '@/components/config/controls/item-picker.vue'
import StrategyPicker from '@/pages/settings/persistence/strategy-picker.vue'
export default {
components: { StrategyPicker, ItemPicker },
props: ['configuration', 'strategies'],
emits: ['configurationUpdate'],
data () {
return {
currentConfiguration: this.configuration || {
items: [],
strategies: [],
filters: []
}
}
},
computed: {
groupItems () {
return this.currentConfiguration.items.filter((i) => i.endsWith('*')).map((i) => i.slice(0, -1))
},
items () {
return this.currentConfiguration.items.filter((i) => !i.endsWith('*'))
}
},
methods: {
selectGroupItems (ev) {
this.currentConfiguration.items = ev.sort((a, b) => a.localeCompare(b)).map((i) => i + '*').concat(this.items)
},
selectItems (ev) {
this.currentConfiguration.items = this.groupItems.map((i) => i + '*').concat(ev.sort((a, b) => a.localeCompare(b)))
},
updateModuleConfig () {
if (this.currentConfiguration.items.length === 0) {
this.$f7.dialog.alert('Please select Items')
return
}
this.$f7.emit('configurationUpdate', this.currentConfiguration)
this.$refs.modulePopup.close()
}
}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<f7-popup ref="modulePopup" class="moduleconfig-popup">
<f7-page>
<f7-navbar>
<f7-nav-left>
<f7-link icon-ios="f7:arrow_left" icon-md="material:arrow_back" icon-aurora="f7:arrow_left" popup-close />
</f7-nav-left>
<f7-nav-title>
Configure cron strategy
</f7-nav-title>
<f7-nav-right>
<f7-link v-show="currentCronStrategy.name && currentCronStrategy.cronExpression" @click="updateModuleConfig">
Done
</f7-link>
</f7-nav-right>
</f7-navbar>
<f7-block>
<f7-list>
<f7-list-input ref="name" label="Name" type="text" placeholder="Required" :value="currentCronStrategy.name"
@input="currentCronStrategy.name = $event.target.value"
:disabled="!createMode"
:info="(createMode) ? 'Note: cannot be changed after the creation' : ''"
required validate pattern="[A-Za-z]+" error-message="Required. A-Z,a-z only" />
<parameter-cronexpression ref="cronExpression" :configDescription="cronExpressionConfigDescription"
:value="currentCronStrategy.cronExpression"
@input="currentCronStrategy.cronExpression = $event" />
</f7-list>
</f7-block>
</f7-page>
</f7-popup>
</template>

<script>
import ParameterCronexpression from '@/components/config/controls/parameter-cronexpression.vue'
export default {
components: {
ParameterCronexpression
},
props: ['cronStrategy'],
emits: ['cronStrategyConfigUpdate'],
data () {
return {
createMode: !this.cronStrategy,
currentCronStrategy: this.cronStrategy || {
name: null,
cronExpression: null
},
cronExpressionConfigDescription: {
label: 'Cron Expression',
name: 'cronExpression',
required: true
}
}
},
methods: {
updateModuleConfig () {
if (!this.$f7.input.validateInputs(this.$refs.name.$el) && !this.$f7.input.validateInputs(this.$refs.cronExpression.$el)) {
this.$f7.dialog.alert('Please review the configuration and correct validation errors')
return
}
this.$f7.emit('cronStrategyConfigUpdate', this.currentCronStrategy)
this.$refs.modulePopup.close()
}
}
}
</script>
Loading

0 comments on commit 7890b94

Please sign in to comment.