3
0

Fix clone processing for compose resources

This commit is contained in:
Jože Fortun 2024-03-12 13:52:13 +01:00
parent 73c5a2cbe2
commit ae536800fe
4 changed files with 51 additions and 57 deletions

View File

@ -82,6 +82,7 @@ export default {
}) })
}) })
}).then(({ pageID }) => { }).then(({ pageID }) => {
this.toastSuccess(this.$t('notification:page.saved'))
this.$router.push({ name: this.$route.name, params: { pageID } }) this.$router.push({ name: this.$route.name, params: { pageID } })
}) })
.catch(this.toastErrorHandler(this.$t('notification:page.cloneFailed'))) .catch(this.toastErrorHandler(this.$t('notification:page.cloneFailed')))

View File

@ -415,6 +415,7 @@
<editor-toolbar <editor-toolbar
:processing="processing" :processing="processing"
:processing-save="processingSave" :processing-save="processingSave"
:processing-clone="processingClone"
:processing-save-and-close="processingSaveAndClose" :processing-save-and-close="processingSaveAndClose"
:processing-delete="processingDelete" :processing-delete="processingDelete"
:hide-delete="hideDelete" :hide-delete="hideDelete"
@ -501,6 +502,7 @@ export default {
initialChartState: undefined, initialChartState: undefined,
processing: false, processing: false,
processingSave: false, processingSave: false,
processingClone: false,
processingSaveAndClose: false, processingSaveAndClose: false,
processingDelete: false, processingDelete: false,
@ -767,15 +769,21 @@ export default {
this.processing = false this.processing = false
}, },
handleSave ({ closeOnSuccess = false, chart = this.chart } = {}) { handleSave ({ chart = this.chart, closeOnSuccess = false, isClone = false } = {}) {
this.processing = true const toggleProcessing = () => {
this.processing = !this.processing
if (closeOnSuccess) { if (closeOnSuccess) {
this.processingSaveAndClose = true this.processingSaveAndClose = !this.processingSaveAndClose
} else { } else if (isClone) {
this.processingSave = true this.processingClone = !this.processingClone
} else {
this.processingSave = !this.processingSave
}
} }
toggleProcessing()
/** /**
* Pass a special tag alongside payload that * Pass a special tag alongside payload that
* instructs store layer to add content-language header to the API request * instructs store layer to add content-language header to the API request
@ -786,9 +794,10 @@ export default {
if (chart.chartID === NoID) { if (chart.chartID === NoID) {
this.createChart(c).then(({ chartID }) => { this.createChart(c).then(({ chartID }) => {
this.toastSuccess(this.$t('notification:chart.saved'))
this.chart = chartConstructor(chart) this.chart = chartConstructor(chart)
this.initialChartState = cloneDeep(chartConstructor(this.chart)) this.initialChartState = cloneDeep(chartConstructor(this.chart))
this.toastSuccess(this.$t('notification:chart.saved'))
if (closeOnSuccess) { if (closeOnSuccess) {
this.redirect() this.redirect()
} else { } else {
@ -797,18 +806,13 @@ export default {
}) })
.catch(this.toastErrorHandler(this.$t('notification:chart.saveFailed'))) .catch(this.toastErrorHandler(this.$t('notification:chart.saveFailed')))
.finally(() => { .finally(() => {
this.processing = false toggleProcessing()
if (closeOnSuccess) {
this.processingSaveAndClose = false
} else {
this.processingSave = false
}
}) })
} else { } else {
this.updateChart(c).then((chart) => { this.updateChart(c).then((chart) => {
this.chart = chartConstructor(chart) this.chart = chartConstructor(chart)
this.initialChartState = cloneDeep(chartConstructor(chart)) this.initialChartState = cloneDeep(chartConstructor(chart))
this.toastSuccess(this.$t('notification:chart.saved')) this.toastSuccess(this.$t('notification:chart.saved'))
if (closeOnSuccess) { if (closeOnSuccess) {
this.redirect() this.redirect()
@ -816,13 +820,7 @@ export default {
}) })
.catch(this.toastErrorHandler(this.$t('notification:chart.saveFailed'))) .catch(this.toastErrorHandler(this.$t('notification:chart.saveFailed')))
.finally(() => { .finally(() => {
this.processing = false toggleProcessing()
if (closeOnSuccess) {
this.processingSaveAndClose = false
} else {
this.processingSave = false
}
}) })
} }
}, },
@ -848,7 +846,7 @@ export default {
chart.name = `${this.chart.name} (copy)` chart.name = `${this.chart.name} (copy)`
chart.handle = this.chart.handle ? `${this.chart.handle}_copy` : '' chart.handle = this.chart.handle ? `${this.chart.handle}_copy` : ''
this.handleSave({ chart }) this.handleSave({ chart, isClone: true })
}, },
redirect () { redirect () {

View File

@ -431,6 +431,7 @@
<editor-toolbar <editor-toolbar
:processing="processing" :processing="processing"
:processing-save="processingSave" :processing-save="processingSave"
:processing-clone="processingClone"
:processing-save-and-close="processingSaveAndClose" :processing-save-and-close="processingSaveAndClose"
:processing-delete="processingDelete" :processing-delete="processingDelete"
:hide-delete="hideDelete" :hide-delete="hideDelete"
@ -439,8 +440,8 @@
:disable-save="disableSave" :disable-save="disableSave"
@delete="handleDelete" @delete="handleDelete"
@save="handleSave()" @save="handleSave()"
@saveAndClose="handleSave({ closeOnSuccess: true })"
@clone="handleClone" @clone="handleClone"
@saveAndClose="handleSave({ closeOnSuccess: true })"
@back="$router.push(previousPage || { name: 'admin.modules' })" @back="$router.push(previousPage || { name: 'admin.modules' })"
/> />
</portal> </portal>
@ -527,6 +528,7 @@ export default {
hasRecords: true, hasRecords: true,
processing: false, processing: false,
processingSave: false, processingSave: false,
processingClone: false,
processingSaveAndClose: false, processingSaveAndClose: false,
processingDelete: false, processingDelete: false,
@ -734,20 +736,27 @@ export default {
this.module.config = { ...this.module.config, ...changes } this.module.config = { ...this.module.config, ...changes }
}, },
handleSave ({ closeOnSuccess = false, module = this.module } = {}) { handleSave ({ module = this.module, closeOnSuccess = false, isClone = false } = {}) {
/** /**
* Pass a special tag alongside payload that * Pass a special tag alongside payload that
* instructs store layer to add content-language header to the API request * instructs store layer to add content-language header to the API request
*/ */
const resourceTranslationLanguage = this.currentLanguage const resourceTranslationLanguage = this.currentLanguage
this.processing = true
if (closeOnSuccess) { const toggleProcessing = () => {
this.processingSaveAndClose = true this.processing = !this.processing
} else {
this.processingSave = true if (closeOnSuccess) {
this.processingSaveAndClose = !this.processingSaveAndClose
} else if (isClone) {
this.processingClone = !this.processingClone
} else {
this.processingSave = !this.processingSave
}
} }
toggleProcessing()
if (module.moduleID === NoID) { if (module.moduleID === NoID) {
// Filter out record fields that reference this not yet created module // Filter out record fields that reference this not yet created module
let fields = [] let fields = []
@ -786,13 +795,7 @@ export default {
} }
}).catch(this.toastErrorHandler(this.$t('notification:module.saveFailed'))) }).catch(this.toastErrorHandler(this.$t('notification:module.saveFailed')))
.finally(() => { .finally(() => {
this.processing = false toggleProcessing()
if (closeOnSuccess) {
this.processingSaveAndClose = false
} else {
this.processingSave = false
}
}) })
} else { } else {
this.updateModule({ ...module, resourceTranslationLanguage }).then(module => { this.updateModule({ ...module, resourceTranslationLanguage }).then(module => {
@ -801,17 +804,11 @@ export default {
this.toastSuccess(this.$t('notification:module.saved')) this.toastSuccess(this.$t('notification:module.saved'))
if (closeOnSuccess) { if (closeOnSuccess) {
this.$router.push({ name: 'admin.modules' }) this.$router.push(this.previousPage || { name: 'admin.modules' })
} }
}).catch(this.toastErrorHandler(this.$t('notification:module.saveFailed'))) }).catch(this.toastErrorHandler(this.$t('notification:module.saveFailed')))
.finally(() => { .finally(() => {
this.processing = false toggleProcessing()
if (closeOnSuccess) {
this.processingSaveAndClose = false
} else {
this.processingSave = false
}
}) })
} }
}, },
@ -913,7 +910,7 @@ export default {
module.name = `${this.module.name} (copy)` module.name = `${this.module.name} (copy)`
module.handle = this.module.handle ? `${this.module.handle}_copy` : '' module.handle = this.module.handle ? `${this.module.handle}_copy` : ''
this.handleSave({ module }) this.handleSave({ module, isClone: true })
}, },
async fetchConnection (connectionID) { async fetchConnection (connectionID) {

View File

@ -1293,12 +1293,14 @@ export default {
}, },
handleSave ({ closeOnSuccess = false } = {}) { handleSave ({ closeOnSuccess = false } = {}) {
this.processing = true const toggleProcessing = () => {
this.processing = !this.processing
if (closeOnSuccess) { if (closeOnSuccess) {
this.processingSaveAndClose = true this.processingSaveAndClose = !this.processingSaveAndClose
} else { } else {
this.processingSave = true this.processingSave = !this.processingSave
}
} }
/** /**
@ -1306,6 +1308,8 @@ export default {
* instructs store layer to add content-language header to the API request * instructs store layer to add content-language header to the API request
*/ */
const resourceTranslationLanguage = this.currentLanguage const resourceTranslationLanguage = this.currentLanguage
toggleProcessing()
const { namespaceID } = this.namespace const { namespaceID } = this.namespace
return this.saveIcon().then(icon => { return this.saveIcon().then(icon => {
@ -1325,13 +1329,7 @@ export default {
this.$router.push(this.previousPage || { name: 'admin.pages' }) this.$router.push(this.previousPage || { name: 'admin.pages' })
} }
}).finally(() => { }).finally(() => {
this.processing = false toggleProcessing()
if (closeOnSuccess) {
this.processingSaveAndClose = false
} else {
this.processingSave = false
}
}).catch(this.toastErrorHandler(this.$t('notification:page.saveFailed'))) }).catch(this.toastErrorHandler(this.$t('notification:page.saveFailed')))
}, },