Skip to content

Commit

Permalink
Item edit: Fix state description not saved for existing Item (#2474)
Browse files Browse the repository at this point in the history
Fixes #2468.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 authored Mar 13, 2024
1 parent 7db99cb commit f5d9cb4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 11 additions & 5 deletions bundles/org.openhab.ui/web/src/components/item/group-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
label="State Description Pattern"
type="text"
:info="(createMode) ? 'Pattern or transformation applied to the state for display purposes. Only saved if you change the pre-filled default value.' : ''"
:value="getStateDescription()"
@input="item.stateDescriptionPattern = $event.target.value" :clear-button:="editable" />
:value="stateDescriptionPattern"
@input="stateDescriptionPattern = $event.target.value" :clear-button:="editable" />
<!-- Aggregation Functions -->
<f7-list-item v-if="aggregationFunctions" :disabled="!editable" title="Aggregation Function" class="aligned-smart-select" smart-select :smart-select-params="{openIn: 'popup', closeOnSelect: true}">
<select name="select-function" @change="groupFunctionKey = $event.target.value">
Expand Down Expand Up @@ -118,6 +118,15 @@ export default {
this.$set(this.item, 'unit', newUnit)
}
},
stateDescriptionPattern: {
get () {
if (this.item.stateDescriptionPattern) return this.item.stateDescriptionPattern
return this.item.metadata?.stateDescription?.config.pattern || '%.0f %unit%'
},
set (newPattern) {
this.$set(this.item, 'stateDescriptionPattern', newPattern)
}
},
groupFunctionKey: {
get () {
return this.item.functionKey
Expand Down Expand Up @@ -188,9 +197,6 @@ export default {
this.$set(this.item, 'unit', this.oldGroupUnit)
}
},
getStateDescription () {
return this.item.stateDescriptionPattern ? this.item.stateDescriptionPattern : '%.0f %unit%'
},
initializeAutocompleteGroupUnit () {
const self = this
const unitControl = this.$refs.groupUnit
Expand Down
16 changes: 11 additions & 5 deletions bundles/org.openhab.ui/web/src/components/item/item-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
type="text"
:info="(createMode) ? 'Pattern or transformation applied to the state for display purposes. Only saved if you change the pre-filled default value.' : ''"
:disabled="!editable"
:value="getStateDescription()"
@input="item.stateDescriptionPattern = $event.target.value"
:value="stateDescriptionPattern"
@input="stateDescriptionPattern = $event.target.value"
:clear-button="editable" />

<!-- Group Item Form -->
Expand Down Expand Up @@ -167,6 +167,15 @@ export default {
set (newCategory) {
this.$set(this.item, 'category', newCategory)
}
},
stateDescriptionPattern: {
get () {
if (this.item.stateDescriptionPattern) return this.item.stateDescriptionPattern
return this.item.metadata?.stateDescription?.config.pattern || '%.0f %unit%'
},
set (newPattern) {
this.$set(this.item, 'stateDescriptionPattern', newPattern)
}
}
},
methods: {
Expand Down Expand Up @@ -197,9 +206,6 @@ export default {
this.$set(this.item, 'unit', this.oldItemUnit)
}
},
getStateDescription () {
return this.item.stateDescriptionPattern ? this.item.stateDescriptionPattern : '%.0f %unit%'
},
initializeAutocompleteUnit () {
if (this.hideType) return
const self = this
Expand Down
8 changes: 5 additions & 3 deletions bundles/org.openhab.ui/web/src/components/item/item-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ export default {
config: {}
}
return this.$oh.api.put('/rest/items/' + item.name + '/metadata/unit', metadata)
} else {
return Promise.resolve()
}
return Promise.resolve()
}).then(() => {
// Save state description if Item is an UoM Item and if state description changed from the default value
if (this.createMode && (item.type.startsWith('Number:') || item.groupType?.startsWith('Number:')) && stateDescriptionPattern) {
if ((item.type.startsWith('Number:') || item.groupType?.startsWith('Number:')) && stateDescriptionPattern) {
if (stateDescriptionPattern !== '%.0f %unit%') {
const metadata = {
value: ' ',
Expand All @@ -87,8 +88,9 @@ export default {
}
return this.$oh.api.put('/rest/items/' + item.name + '/metadata/stateDescription', metadata)
}
} else {
return Promise.resolve()
}
return Promise.resolve()
}).catch((err) => {
return Promise.reject(err)
})
Expand Down

0 comments on commit f5d9cb4

Please sign in to comment.