3
0

Adjust refresh on related records update when saving in modal

This commit is contained in:
Jože Fortun 2023-09-21 15:35:00 +02:00 committed by Kelani Tolulope
parent 6284ac5af9
commit 35d455f154
11 changed files with 94 additions and 23 deletions

View File

@ -85,8 +85,8 @@ export default {
}, },
beforeDestroy () { beforeDestroy () {
this.setDefaultValues()
this.destroyEvents() this.destroyEvents()
this.setDefaultValues()
}, },
mounted () { mounted () {
@ -100,8 +100,8 @@ export default {
resolveRecords: 'record/resolveRecords', resolveRecords: 'record/resolveRecords',
}), }),
refreshOnRelatedModuleUpdate (module) { refreshOnRelatedModuleUpdate ({ moduleID }) {
if (this.relatedModuleID === module.moduleID) { if (this.relatedModuleID === moduleID) {
this.formatRecordValues(this.value) this.formatRecordValues(this.value)
} }
}, },

View File

@ -234,9 +234,14 @@ export default {
this.refreshBlock(this.refresh) this.refreshBlock(this.refresh)
}, },
mounted () {
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
beforeDestroy () { beforeDestroy () {
this.setDefaultValues() this.setDefaultValues()
this.abortRequests() this.abortRequests()
this.destroyEvents()
}, },
methods: { methods: {
@ -252,6 +257,18 @@ export default {
}) })
}, },
refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
this.options.feeds.forEach((feed) => {
const { moduleID: feedModuleID } = feed.options
if (feedModuleID) {
if (feedModuleID === moduleID && this.page.pageID !== notPageID) {
this.refresh()
}
}
})
},
/** /**
* Helper method to load requested locale. * Helper method to load requested locale.
* See https://github.com/fullcalendar/fullcalendar/tree/master/packages/core/src/locales * See https://github.com/fullcalendar/fullcalendar/tree/master/packages/core/src/locales
@ -406,6 +423,10 @@ export default {
abortRequests () { abortRequests () {
this.cancelTokenSource.cancel(`cancel-record-list-request-${this.block.blockID}`) this.cancelTokenSource.cancel(`cancel-record-list-request-${this.block.blockID}`)
}, },
destroyEvents () {
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
}, },
} }
</script> </script>

View File

@ -29,6 +29,7 @@ export default {
components: { components: {
ChartComponent, ChartComponent,
}, },
extends: base, extends: base,
data () { data () {
@ -69,8 +70,8 @@ export default {
findChartByID: 'chart/findByID', findChartByID: 'chart/findByID',
}), }),
refreshOnRelatedRecordsUpdate (module) { refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
if (this.filter.moduleID === module.moduleID) { if (this.filter.moduleID === moduleID && this.page.pageID !== notPageID) {
this.refresh() this.refresh()
} }
}, },

View File

@ -230,8 +230,8 @@ export default {
beforeDestroy () { beforeDestroy () {
this.abortRequests() this.abortRequests()
this.setDefaultValues()
this.destroyEvents() this.destroyEvents()
this.setDefaultValues()
}, },
methods: { methods: {
@ -244,8 +244,8 @@ export default {
return user.name || user.handle || user.email || '' return user.name || user.handle || user.email || ''
}, },
refreshOnRelatedRecordsUpdate (module) { refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
if (this.options.moduleID === module.moduleID) { if (this.options.moduleID === moduleID && this.page.pageID !== notPageID) {
this.refresh() this.refresh()
} }
}, },
@ -301,6 +301,9 @@ export default {
this.newRecord.title = '' this.newRecord.title = ''
this.newRecord.content = '' this.newRecord.content = ''
this.refresh() this.refresh()
const { moduleID } = this.options
this.$root.$emit('module-records-updated', { moduleID })
}) })
.catch(this.toastErrorHandler(this.$t('notification:record.createFailed'))) .catch(this.toastErrorHandler(this.$t('notification:record.createFailed')))
} }

View File

@ -154,9 +154,14 @@ export default {
this.refreshBlock(this.refresh) this.refreshBlock(this.refresh)
}, },
mounted () {
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
beforeDestroy () { beforeDestroy () {
this.setDefaultValues() this.setDefaultValues()
this.abortRequests() this.abortRequests()
this.destroyEvents()
}, },
methods: { methods: {
@ -164,6 +169,14 @@ export default {
findModuleByID: 'module/findByID', findModuleByID: 'module/findByID',
}), }),
refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
this.options.feeds.forEach((feed) => {
if (feed.options.moduleID === moduleID && this.page.pageID !== notPageID) {
this.refresh()
}
})
},
loadEvents () { loadEvents () {
this.geometries = [] this.geometries = []
@ -329,6 +342,10 @@ export default {
abortRequests () { abortRequests () {
this.cancelTokenSource.cancel(`abort-request-${this.block.blockID}`) this.cancelTokenSource.cancel(`abort-request-${this.block.blockID}`)
}, },
destroyEvents () {
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
}, },
} }
</script> </script>

View File

@ -235,11 +235,15 @@ export default {
}) })
}, },
refreshOnRelatedRecordsUpdate (module) { refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
if (this.page.pageID === notPageID) {
return
}
const metrics = this.options.metrics const metrics = this.options.metrics
const hasMatchingModule = metrics.some((m) => { const hasMatchingModule = metrics.some((m) => {
return m.moduleID === module.moduleID return m.moduleID === moduleID
}) })
if (hasMatchingModule) { if (hasMatchingModule) {

View File

@ -78,6 +78,7 @@ export default {
mounted () { mounted () {
this.$root.$on(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) this.$root.$on(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh)
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
beforeDestroy () { beforeDestroy () {
@ -132,6 +133,12 @@ export default {
}) })
}, },
refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
if (this.options.value.moduleID === moduleID && this.page.pageID !== notPageID) {
this.refresh()
}
},
setDefaultValues () { setDefaultValues () {
this.processing = false this.processing = false
this.value = undefined this.value = undefined
@ -141,6 +148,7 @@ export default {
destroyEvents () { destroyEvents () {
this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh)
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
}, },
} }

View File

@ -1103,13 +1103,17 @@ export default {
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate) this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
}, },
refreshOnRelatedRecordsUpdate (module) { refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
if (this.recordListModule.moduleID === module.moduleID) { if (this.page.pageID === notPageID) {
return
}
if (this.recordListModule.moduleID === moduleID) {
this.refresh(true) this.refresh(true)
} else { } else {
const recordFields = this.fields.filter((f) => f.moduleField.kind === 'Record') const recordFields = this.fields.filter((f) => f.moduleField.kind === 'Record')
const hasMatchingModule = recordFields.some((r) => { const hasMatchingModule = recordFields.some((r) => {
return r.moduleField.options.moduleID === module.moduleID return r.moduleField.options.moduleID === moduleID
}) })
if (hasMatchingModule) { if (hasMatchingModule) {

View File

@ -346,8 +346,8 @@ export default {
} }
}, },
refreshOnRelatedRecordsUpdate (module) { refreshOnRelatedRecordsUpdate ({ moduleID, notPageID }) {
if (this.options.moduleID === module.moduleID) { if (this.options.moduleID === moduleID && this.page.pageID !== notPageID) {
this.refresh() this.refresh()
} }
}, },

View File

@ -218,13 +218,24 @@ export default {
beforeDestroy () { beforeDestroy () {
this.setDefaultValues() this.setDefaultValues()
this.destroyEvents()
}, },
created () { created () {
this.refreshBlock(this.refresh) this.refreshBlock(this.refresh)
}, },
mounted () {
this.$root.$on('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
methods: { methods: {
refreshOnRelatedRecordsUpdate ({ moduleID }) {
if (this.module.moduleID === moduleID) {
this.refresh()
}
},
async loadRevisions () { async loadRevisions () {
if (this.revisionsDisabledOnModule) { if (this.revisionsDisabledOnModule) {
return return
@ -259,6 +270,10 @@ export default {
this.revisions = [] this.revisions = []
this.columns = [] this.columns = []
}, },
destroyEvents () {
this.$root.$off('module-records-updated', this.refreshOnRelatedRecordsUpdate)
},
}, },
} }
</script> </script>

View File

@ -169,6 +169,12 @@ export default {
if (this.showRecordModal) { if (this.showRecordModal) {
this.$emit('handle-record-redirect', { recordID: record.recordID, recordPageID: this.page.pageID }) this.$emit('handle-record-redirect', { recordID: record.recordID, recordPageID: this.page.pageID })
// If we are in a modal we need to refresh blocks not in modal
this.$root.$emit('module-records-updated', {
moduleID: this.module.moduleID,
notPageID: this.page.pageID,
})
} else { } else {
this.$router.push({ name: route, params: { ...this.$route.params, recordID: record.recordID } }) this.$router.push({ name: route, params: { ...this.$route.params, recordID: record.recordID } })
} }
@ -185,10 +191,6 @@ export default {
} }
this.toastSuccess(this.$t(`notification:record.${isNew ? 'create' : 'update'}Success`)) this.toastSuccess(this.$t(`notification:record.${isNew ? 'create' : 'update'}Success`))
this.$root.$emit('module-records-updated', {
moduleID: this.module.moduleID,
})
}) })
.catch(this.toastErrorHandler(this.$t(`notification:record.${isNew ? 'create' : 'update'}Failed`))) .catch(this.toastErrorHandler(this.$t(`notification:record.${isNew ? 'create' : 'update'}Failed`)))
.finally(() => { .finally(() => {
@ -243,10 +245,6 @@ export default {
this.initialRecordState = this.record.clone() this.initialRecordState = this.record.clone()
this.$router.push({ name: route, params: { ...this.$route.params, recordID: record.recordID } }) this.$router.push({ name: route, params: { ...this.$route.params, recordID: record.recordID } })
this.$root.$emit('module-records-updated', {
moduleID: this.module.moduleID,
})
} }
}) })
.catch(this.toastErrorHandler(this.$t( .catch(this.toastErrorHandler(this.$t(