Skip to content

Commit

Permalink
Item metadata: Improve dirty handling & Fix description metadata alwa…
Browse files Browse the repository at this point in the history
…ys dirty (#2778)

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Sep 30, 2024
1 parent 851d250 commit e500ffe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default {
},
updateComponent () {
const value = this.$refs.widgets.f7SmartSelect.getValue()
this.metadata.value = value
this.metadata.value = value || ' ' // ' ' is used to indicate the default widget
this.setCurrentComponent()
this.setConfigDescriptions()
this.setPreviewContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

<script>
import YAML from 'yaml'
import fastDeepEqual from 'fast-deep-equal/es6'
import cloneDeep from 'lodash/cloneDeep'
import MetadataNamespaces from '@/assets/definitions/metadata/namespaces.js'
Expand Down Expand Up @@ -93,14 +95,15 @@ export default {
generic: false,
item: {},
metadata: { value: '', config: {} },
savedMetadata: {},
yaml: null
}
},
watch: {
metadata: {
handler: function () {
if (this.ready) {
this.dirty = true
this.dirty = !fastDeepEqual(this.metadata, this.savedMetadata)
}
},
deep: true
Expand Down Expand Up @@ -153,28 +156,27 @@ export default {
methods: {
onPageBeforeIn () {
this.generic = MetadataNamespaces.map((n) => n.name).indexOf(this.namespace) < 0
this.ready = false
},
onPageAfterIn () {
this.$oh.api.get(`/rest/items/${this.itemName}?metadata=${this.namespace}`).then((data) => {
this.item = data
if (this.item.metadata) {
this.metadata = this.item.metadata[this.namespace]
this.$oh.api.get(`/rest/items/${this.itemName}?metadata=${this.namespace}`).then((item) => {
this.item = item
if (item.metadata) {
this.metadata = item.metadata[this.namespace]
if (!this.metadata.config) this.$set(this.metadata, 'config', {})
this.creationMode = false
}
if (this.generic) {
this.currentTab = 'code'
this.toYaml()
}
this.savedMetadata = cloneDeep(this.metadata)
this.$nextTick(() => {
this.ready = true
})
})
},
onEditorInput (value) {
this.yaml = value
this.dirty = true
},
save () {
if (this.currentTab === 'code' && !this.fromYaml()) return
Expand All @@ -193,6 +195,7 @@ export default {
closeTimeout: 2000
}).open()
}
this.savedMetadata = cloneDeep(this.metadata)
this.dirty = false
this.$f7router.back()
}).catch((err) => {
Expand Down

0 comments on commit e500ffe

Please sign in to comment.