Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformation edit: Improve dirty handling & Fix settings styling #2759

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
</f7-link>
</div>
</f7-toolbar>
<transformation-general-settings :createMode="createMode" :transformation="transformation" />
<f7-block class="block-narrow">
<transformation-general-settings :createMode="createMode" :transformation="transformation" />
<f7-col>
<f7-list v-if="isEditable">
<f7-list-button color="red" @click="deleteTransformation">
Expand All @@ -82,6 +82,9 @@
</style>

<script>
import cloneDeep from 'lodash/cloneDeep'
import fastDeepEqual from 'fast-deep-equal/es6'

import DirtyMixin from '../dirty-mixin'
import TransformationGeneralSettings from '@/pages/settings/transformations/transformation-general-settings'
import { CodeSnippets, EditorModes } from '@/assets/definitions/transformations.js'
Expand All @@ -101,6 +104,7 @@ export default {
ready: false,
loading: false,
transformation: {},
savedTransformation: {},
types: [],
languages: [],
language: '',
Expand All @@ -109,6 +113,16 @@ export default {
blocklyCodePreview: false
}
},
watch: {
transformation: {
handler: function () {
if (!this.loading) { // ignore changes during loading
this.dirty = !fastDeepEqual(this.transformation, this.savedTransformation)
}
},
deep: true
}
},
computed: {
isEditable () {
return this.transformation && this.transformation.editable !== false
Expand Down Expand Up @@ -150,6 +164,7 @@ export default {
},
editable: true
}
this.savedTransformation = cloneDeep(this.transformation)
Promise.all([this.$oh.api.get('/rest/transformations/services'), this.$oh.api.get('/rest/config-descriptions/system:i18n')]).then((data) => {
this.$set(this, 'types', data[0])

Expand Down Expand Up @@ -183,6 +198,7 @@ export default {
if (CodeSnippets[this.transformation.type.toLowerCase()]) this.transformation.configuration.function = CodeSnippets[this.transformation.type.toLowerCase()]

this.$oh.api.put('/rest/transformations/' + this.transformation.uid, this.transformation).then(() => {
this.dirty = false
this.$f7.toast.create({
text: 'Transformation created',
destroyOnClose: true,
Expand All @@ -197,6 +213,7 @@ export default {

this.$oh.api.get('/rest/transformations/' + this.transformationId).then((data) => {
this.$set(this, 'transformation', data)
this.savedTransformation = cloneDeep(this.transformation)
this.editorMode = EditorModes[this.transformation.type.toLowerCase()] || this.transformation.type
this.loading = false
this.ready = true
Expand All @@ -215,6 +232,7 @@ export default {
}
return this.$oh.api.put('/rest/transformations/' + this.transformation.uid, this.transformation).then((data) => {
this.dirty = false
this.savedTransformation = cloneDeep(this.transformation)
if (!noToast) {
this.$f7.toast.create({
text: 'Transformation updated',
Expand Down Expand Up @@ -257,7 +275,6 @@ export default {
},
onEditorInput (value) {
this.transformation.configuration.function = value
this.dirty = true
},
keyDown (ev) {
if ((ev.ctrlKey || ev.metaKey) && !(ev.altKey || ev.shiftKey)) {
Expand Down