From de431aea6c22c30ac0270eddf495cad1bf1a7500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Fortun?= Date: Tue, 22 Aug 2023 16:50:14 +0200 Subject: [PATCH] Restructure event destroy and request abort code --- .../compose/src/components/Chart/index.vue | 15 ++++++- .../components/PageBlocks/AutomationBase.vue | 16 ++++--- .../src/components/PageBlocks/ChartBase.vue | 4 +- .../src/components/PageBlocks/CommentBase.vue | 16 ++++--- .../src/components/PageBlocks/MetricBase.vue | 26 ++++++----- .../components/PageBlocks/ProgressBase.vue | 2 +- .../src/components/PageBlocks/RecordBase.vue | 15 ++++--- .../components/PageBlocks/RecordListBase.vue | 38 +++++++++------- .../PageBlocks/RecordOrganizerBase.vue | 18 +++++--- .../src/components/PageBlocks/Report/Base.vue | 15 ++++--- .../Public/Page/Attachment/Modal.vue | 26 +++++------ .../components/Public/Page/Block/Modal.vue | 2 +- .../src/components/Public/Record/Modal.vue | 4 +- .../Translator/CTranslatorModal.vue | 30 +++++++------ .../compose/src/views/Admin/Modules/Edit.vue | 15 ++++--- .../src/views/Admin/Modules/Records/View.vue | 24 ++++++----- .../compose/src/views/Admin/Pages/Edit.vue | 24 ++++++----- .../compose/src/views/Admin/Pages/List.vue | 15 ++++--- client/web/compose/src/views/Layout.vue | 9 ++-- .../src/views/Public/Pages/Records/View.vue | 43 +++++++++++-------- .../compose/src/views/Public/Pages/View.vue | 12 +++--- .../src/components/navigation/CSidebar.vue | 7 +-- .../permissions/CPermissionsModal.vue | 21 ++++----- 23 files changed, 237 insertions(+), 160 deletions(-) diff --git a/client/web/compose/src/components/Chart/index.vue b/client/web/compose/src/components/Chart/index.vue index 5712168d0..6e8426f8d 100644 --- a/client/web/compose/src/components/Chart/index.vue +++ b/client/web/compose/src/components/Chart/index.vue @@ -75,8 +75,9 @@ export default { }, beforeDestroy () { - const { pageID = NoID } = this.$route.params - this.$root.$off(`refetch-non-record-blocks:${pageID}`) + this.abortRequests() + this.setDefaultValues() + this.destroyEvents() }, methods: { @@ -199,6 +200,16 @@ export default { /* eslint-disable no-console */ console.error(msg) }, + + setDefaultValues () { + this.processing = false + this.rendeder = undefined + }, + + destroyEvents () { + const { pageID = NoID } = this.$route.params + this.$root.$off(`refetch-non-record-blocks:${pageID}`) + }, }, } diff --git a/client/web/compose/src/components/PageBlocks/AutomationBase.vue b/client/web/compose/src/components/PageBlocks/AutomationBase.vue index 0bc96537b..75e104bdc 100644 --- a/client/web/compose/src/components/PageBlocks/AutomationBase.vue +++ b/client/web/compose/src/components/PageBlocks/AutomationBase.vue @@ -41,7 +41,7 @@ export default { automationScripts: [], - abortRequests: [], + abortableRequests: [], } }, @@ -52,11 +52,8 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() - - this.abortRequests.forEach((cancel) => { - cancel() - }) }, created () { @@ -74,7 +71,7 @@ export default { const { response, cancel } = this.$ComposeAPI .automationListCancellable({ eventTypes: ['onManual'], excludeInvalid: true }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) return response() .then(({ set = [] }) => { @@ -88,6 +85,13 @@ export default { setDefaultValues () { this.processing = false this.automationScripts = [] + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/components/PageBlocks/ChartBase.vue b/client/web/compose/src/components/PageBlocks/ChartBase.vue index 8d1834fee..baba3fc86 100644 --- a/client/web/compose/src/components/PageBlocks/ChartBase.vue +++ b/client/web/compose/src/components/PageBlocks/ChartBase.vue @@ -153,7 +153,6 @@ export default { allowExport: true, perPage: 14, showTotalCount: true, - magnifyOption: 'modal', recordDisplayOption: 'modal', }, }) @@ -169,8 +168,7 @@ export default { }, destroyEvents () { - this.$root.$off('drill-down-chart') - this.$root.$off('magnify-page-block') + this.$root.$off('drill-down-chart', this.drillDown) }, }, } diff --git a/client/web/compose/src/components/PageBlocks/CommentBase.vue b/client/web/compose/src/components/PageBlocks/CommentBase.vue index f382cd100..14e07b6e5 100644 --- a/client/web/compose/src/components/PageBlocks/CommentBase.vue +++ b/client/web/compose/src/components/PageBlocks/CommentBase.vue @@ -124,7 +124,7 @@ export default { content: '', }, - abortRequests: [], + abortableRequests: [], } }, @@ -218,11 +218,8 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() - - this.abortRequests.forEach((cancel) => { - cancel() - }) }, methods: { @@ -346,7 +343,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordListCancellable(params) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) return response() .then(({ set }) => set.map(r => Object.freeze(new compose.Record(module, r)))) @@ -357,6 +354,13 @@ export default { this.filter = false this.records = [] this.newRecord = {} + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/components/PageBlocks/MetricBase.vue b/client/web/compose/src/components/PageBlocks/MetricBase.vue index 64dd5bf1c..4bbe7cb68 100644 --- a/client/web/compose/src/components/PageBlocks/MetricBase.vue +++ b/client/web/compose/src/components/PageBlocks/MetricBase.vue @@ -67,7 +67,7 @@ export default { processing: false, reports: [], - abortRequests: [], + abortableRequests: [], } }, @@ -94,14 +94,9 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() this.destroyEvents() - this.$root.$off('metric.update', this.refresh) - this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`) - - this.abortRequests.forEach((cancel) => { - cancel() - }) }, created () { @@ -147,7 +142,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordReportCancellable({ ...r, namespaceID }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) return response() } @@ -204,18 +199,20 @@ export default { options: { moduleID, prefilter: filter, - presort: '', + presort: 'createdAt DESC', hideRecordReminderButton: true, hideRecordViewButton: false, hideConfigureFieldsButton: false, hideImportButton: true, + enableRecordPageNavigation: true, selectable: true, allowExport: true, perPage: 14, showTotalCount: true, - magnifyOption: 'modal', + recordDisplayOption: 'modal', }, }) + this.$root.$emit('magnify-page-block', { block }) } }, @@ -223,11 +220,18 @@ export default { setDefaultValues () { this.processing = false this.reports = [] + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, destroyEvents () { this.$root.$off('metric.update', this.refresh) - this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`) + this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) this.$root.$off('drill-down-chart', this.drillDown) }, }, diff --git a/client/web/compose/src/components/PageBlocks/ProgressBase.vue b/client/web/compose/src/components/PageBlocks/ProgressBase.vue index 5c8e64669..eb2a209f5 100644 --- a/client/web/compose/src/components/PageBlocks/ProgressBase.vue +++ b/client/web/compose/src/components/PageBlocks/ProgressBase.vue @@ -140,7 +140,7 @@ export default { }, destroyEvents () { - this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`) + this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) }, }, } diff --git a/client/web/compose/src/components/PageBlocks/RecordBase.vue b/client/web/compose/src/components/PageBlocks/RecordBase.vue index c1e1e263b..ae3746d53 100644 --- a/client/web/compose/src/components/PageBlocks/RecordBase.vue +++ b/client/web/compose/src/components/PageBlocks/RecordBase.vue @@ -139,7 +139,7 @@ export default { initialRecord: {}, }, - abortRequests: [], + abortableRequests: [], } }, @@ -216,10 +216,8 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() - this.abortRequests.forEach((cancel) => { - cancel() - }) }, methods: { @@ -265,7 +263,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordReadCancellable({ namespaceID, moduleID, recordID }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) response() .then(record => { @@ -327,6 +325,13 @@ export default { this.referenceRecord = undefined this.referenceModule = undefined this.inlineEdit = {} + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/components/PageBlocks/RecordListBase.vue b/client/web/compose/src/components/PageBlocks/RecordListBase.vue index 3f4cc0e43..9482145af 100644 --- a/client/web/compose/src/components/PageBlocks/RecordListBase.vue +++ b/client/web/compose/src/components/PageBlocks/RecordListBase.vue @@ -830,7 +830,7 @@ export default { showCustomPresetFilterModal: false, selectedAllRecords: false, - abortRequests: [], + abortableRequests: [], } }, @@ -1055,6 +1055,7 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() this.destroyEvents() }, @@ -1091,17 +1092,6 @@ export default { }) }, - destroyEvents () { - this.$root.$off(`record-line:collect:${this.uniqueID}`) - this.$root.$off(`page-block:validate:${this.uniqueID}`) - this.$root.$off(`drill-down-recordList:${this.uniqueID}`) - this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`) - - this.abortRequests.forEach((cancel) => { - cancel() - }) - }, - onFilter (filter = []) { filter.forEach(f => { if (this.activeFilters.includes(f.name)) { @@ -1505,7 +1495,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordBulkUndeleteCancellable({ moduleID, namespaceID, query }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) response() .then(() => { @@ -1539,7 +1529,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordBulkDeleteCancellable({ moduleID, namespaceID, query }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) response() .then(() => this.refresh(true)) @@ -1601,7 +1591,7 @@ export default { this.showingDeletedRecords ? this.filter.deleted = 2 : this.filter.deleted = 0 const { response, cancel } = this.$ComposeAPI.recordListCancellable({ ...this.filter, moduleID, namespaceID, query, ...paginationOptions }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) return response() .then(({ set, filter }) => { @@ -1883,6 +1873,24 @@ export default { this.currentCustomPresetFilter = undefined this.showCustomPresetFilterModal = false this.selectedAllRecords = false + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) + }, + + destroyEvents () { + const { pageID = NoID } = this.page + + this.$root.$on(`record-line:collect:${this.uniqueID}`, this.resolveRecords) + this.$root.$on(`page-block:validate:${this.uniqueID}`, this.validatePageBlock) + this.$root.$on(`drill-down-recordList:${this.uniqueID}`, this.setDrillDownFilter) + this.$root.$on(`refetch-non-record-blocks:${pageID}`, () => { + this.refresh(true) + }) }, }, } diff --git a/client/web/compose/src/components/PageBlocks/RecordOrganizerBase.vue b/client/web/compose/src/components/PageBlocks/RecordOrganizerBase.vue index e9bed0049..55487edca 100644 --- a/client/web/compose/src/components/PageBlocks/RecordOrganizerBase.vue +++ b/client/web/compose/src/components/PageBlocks/RecordOrganizerBase.vue @@ -146,7 +146,7 @@ export default { records: [], - abortRequests: [], + abortableRequests: [], } }, @@ -254,12 +254,9 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() this.destroyEvents() - this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`) - this.abortRequests.forEach((cancel) => { - cancel() - }) }, methods: { @@ -446,7 +443,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordListCancellable({ namespaceID, moduleID, query, sort }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) return response() .then(({ set }) => { @@ -503,10 +500,17 @@ export default { this.processing = false this.filter = {} this.records = [] + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, destroyEvents () { - this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`) + this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`, this.refresh) }, }, } diff --git a/client/web/compose/src/components/PageBlocks/Report/Base.vue b/client/web/compose/src/components/PageBlocks/Report/Base.vue index b64b18f21..2c18defac 100644 --- a/client/web/compose/src/components/PageBlocks/Report/Base.vue +++ b/client/web/compose/src/components/PageBlocks/Report/Base.vue @@ -43,7 +43,7 @@ export default { processing: false, report: undefined, displayElement: undefined, - abortRequests: [], + abortableRequests: [], } }, @@ -60,10 +60,8 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() - this.abortRequests.forEach((cancel) => { - cancel() - }) }, created () { @@ -77,7 +75,7 @@ export default { const { response, cancel } = this.$SystemAPI .reportReadCancellable({ reportID }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) return response() .then(report => { @@ -161,6 +159,13 @@ export default { this.processing = false this.report = undefined this.displayElement = undefined + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/components/Public/Page/Attachment/Modal.vue b/client/web/compose/src/components/Public/Page/Attachment/Modal.vue index 765edda98..82cf852c5 100644 --- a/client/web/compose/src/components/Public/Page/Attachment/Modal.vue +++ b/client/web/compose/src/components/Public/Page/Attachment/Modal.vue @@ -71,17 +71,7 @@ export default { created () { window.addEventListener('keyup', this.onKeyUp) - this.$root.$on('showAttachmentsModal', ({ url, download, name, document = undefined, meta, enableDownload }) => { - this.attachment = { - document, - download, - meta, - src: url, - name: name, - caption: name, - enableDownload, - } - }) + this.$root.$on('showAttachmentsModal', this.showAttachmentModal) }, beforeDestroy () { @@ -96,13 +86,25 @@ export default { } }, + showAttachmentModal ({ url, download, name, document = undefined, meta, enableDownload }) { + this.attachment = { + document, + download, + meta, + src: url, + name: name, + caption: name, + enableDownload, + } + }, + setDefaultValues () { this.attachment = undefined }, destroyEvents () { window.removeEventListener('keyup', this.onKeyUp) - this.$root.$off('showAttachmentsModal') + this.$root.$off('showAttachmentsModal', this.showAttachmentModal) }, }, } diff --git a/client/web/compose/src/components/Public/Page/Block/Modal.vue b/client/web/compose/src/components/Public/Page/Block/Modal.vue index 53f652830..d311d14c8 100644 --- a/client/web/compose/src/components/Public/Page/Block/Modal.vue +++ b/client/web/compose/src/components/Public/Page/Block/Modal.vue @@ -141,7 +141,7 @@ export default { onHidden () { setTimeout(() => { - this.$router.push({ + this.$router.replace({ query: { ...this.$route.query, magnifiedBlockID: undefined, diff --git a/client/web/compose/src/components/Public/Record/Modal.vue b/client/web/compose/src/components/Public/Record/Modal.vue index 97e622d0b..a2b2bb87e 100644 --- a/client/web/compose/src/components/Public/Record/Modal.vue +++ b/client/web/compose/src/components/Public/Record/Modal.vue @@ -154,7 +154,7 @@ export default { onHidden () { setTimeout(() => { - this.$router.push({ + this.$router.replace({ query: { ...this.$route.query, recordID: undefined, @@ -173,7 +173,7 @@ export default { }, destroyEvents () { - this.$root.$off('show-record-modal') + this.$root.$off('show-record-modal', this.loadRecord) }, }, } diff --git a/client/web/compose/src/components/Translator/CTranslatorModal.vue b/client/web/compose/src/components/Translator/CTranslatorModal.vue index 9a3089d63..6519c4071 100644 --- a/client/web/compose/src/components/Translator/CTranslatorModal.vue +++ b/client/web/compose/src/components/Translator/CTranslatorModal.vue @@ -93,7 +93,19 @@ export default { mounted () { this.loaded = false - this.$root.$on('c-translator', payload => { + this.$root.$on('c-translator', this.loadModal) + }, + + beforeDestroy () { + this.destroyEvents() + }, + + methods: { + ...mapActions({ + loadLanguages: 'languages/load', + }), + + loadModal (payload) { if (!payload) { // when falsy payload is received, // close the translator modal @@ -114,17 +126,7 @@ export default { this.translations = tt this.loaded = true }) - }) - }, - - destroyed () { - this.$root.$off('c-translator') - }, - - methods: { - ...mapActions({ - loadLanguages: 'languages/load', - }), + }, onSubmit () { if (this.changes.length === 0) { @@ -155,6 +157,10 @@ export default { this.keyPrettyfier = undefined this.loaded = false }, + + destroyEvents () { + this.$root.$off('c-translator', this.loadModal) + }, }, } diff --git a/client/web/compose/src/views/Admin/Modules/Edit.vue b/client/web/compose/src/views/Admin/Modules/Edit.vue index b170454a4..9301f7589 100644 --- a/client/web/compose/src/views/Admin/Modules/Edit.vue +++ b/client/web/compose/src/views/Admin/Modules/Edit.vue @@ -530,7 +530,7 @@ export default { modal: false, }, - abortRequests: [], + abortableRequests: [], } }, @@ -686,7 +686,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordListCancellable({ moduleID, namespaceID, limit: 1 }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) response() .then(({ set }) => { this.hasRecords = (set.length > 0) }) @@ -705,10 +705,8 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() - this.abortRequests.forEach((cancel) => { - cancel() - }) }, beforeRouteUpdate (to, from, next) { @@ -879,6 +877,13 @@ export default { this.processing = false this.federationSettings = {} this.discoverySettings = {} + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/views/Admin/Modules/Records/View.vue b/client/web/compose/src/views/Admin/Modules/Records/View.vue index 87e96ff6a..15dbeb10c 100644 --- a/client/web/compose/src/views/Admin/Modules/Records/View.vue +++ b/client/web/compose/src/views/Admin/Modules/Records/View.vue @@ -148,7 +148,7 @@ export default { namespace: this.$attrs.namespace, }, - abortRequests: [], + abortableRequests: [], } }, @@ -230,19 +230,16 @@ export default { }, }, - beforeDestroy () { - this.setDefaultValues() - - this.abortRequests.forEach((cancel) => { - cancel() - }) - }, - created () { this.createBlocks() this.record = new compose.Record(this.module, { values: this.values }) }, + beforeDestroy () { + this.abortRequests() + this.setDefaultValues() + }, + methods: { createBlocks () { this.fields.forEach(f => { @@ -263,7 +260,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordReadCancellable({ namespaceID, moduleID, recordID }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) response() .then(record => { @@ -311,6 +308,13 @@ export default { this.inEditing = false this.blocks = [] this.bindParams = {} + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/views/Admin/Pages/Edit.vue b/client/web/compose/src/views/Admin/Pages/Edit.vue index 5424b3cbc..18450efbb 100644 --- a/client/web/compose/src/views/Admin/Pages/Edit.vue +++ b/client/web/compose/src/views/Admin/Pages/Edit.vue @@ -904,7 +904,7 @@ export default { off: this.$t('general:label.no'), }, - abortRequests: [], + abortableRequests: [], } }, @@ -1062,18 +1062,15 @@ export default { this.checkUnsavedComposePage(next) }, - beforeDestroy () { - this.setDefaultValues() - - this.abortRequests.forEach((cancel) => { - cancel() - }) - }, - created () { this.fetchRoles() }, + beforeDestroy () { + this.abortRequests() + this.setDefaultValues() + }, + methods: { ...mapActions({ findPageByID: 'page/findByID', @@ -1100,7 +1097,7 @@ export default { const { response, cancel } = this.$SystemAPI .roleListCancellable({}) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) response() .then(({ set: roles = [] }) => { @@ -1290,6 +1287,13 @@ export default { this.removedLayouts.clear() this.roles = {} this.checkboxLabel = {} + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/views/Admin/Pages/List.vue b/client/web/compose/src/views/Admin/Pages/List.vue index 3626ace75..0e4a63e73 100644 --- a/client/web/compose/src/views/Admin/Pages/List.vue +++ b/client/web/compose/src/views/Admin/Pages/List.vue @@ -122,7 +122,7 @@ export default { tree: [], page: new compose.Page({ visible: true }), processing: false, - abortRequests: [], + abortableRequests: [], } }, @@ -131,10 +131,8 @@ export default { }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() - this.abortRequests.forEach((cancel) => { - cancel() - }) }, methods: { @@ -150,7 +148,7 @@ export default { const { response, cancel } = this.$ComposeAPI .pageTreeCancellable({ namespaceID }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) response() .then((tree) => { @@ -188,6 +186,13 @@ export default { this.tree = [] this.page = {} this.processing = false + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, }, } diff --git a/client/web/compose/src/views/Layout.vue b/client/web/compose/src/views/Layout.vue index a8ebf310e..5afe445c4 100644 --- a/client/web/compose/src/views/Layout.vue +++ b/client/web/compose/src/views/Layout.vue @@ -186,9 +186,8 @@ export default { * Listen for incoming warnings, alerts and other messages * from the (mostly) Corredor scripts and display them using toasts */ - this.$root.$on('alert', ({ message, ...params }) => this.toast(message, params)) + this.$root.$on('alert', this.showAlert) this.$root.$on('reminder.show', this.showReminder) - this.$root.$on('check-namespace-sidebar', this.checkNamespaceSidebar) }, @@ -238,6 +237,10 @@ export default { }) }, + showAlert ({ message, ...params }) { + this.toast(message, params) + }, + showReminder (r) { const i = this.toasts.findIndex(({ reminderID }) => reminderID === r.reminderID) if (i > -1 && (!r.editedAt || r.editedAt === this.toasts[i].editedAt)) { @@ -295,7 +298,7 @@ export default { }, destroyEvents () { - this.$root.$off('alert') + this.$root.$off('alert', this.showAlert) this.$root.$off('reminder.show', this.showReminder) this.$root.$off('check-namespace-sidebar', this.checkNamespaceSidebar) }, diff --git a/client/web/compose/src/views/Public/Pages/Records/View.vue b/client/web/compose/src/views/Public/Pages/Records/View.vue index 86182e3fc..4a45daeb0 100644 --- a/client/web/compose/src/views/Public/Pages/Records/View.vue +++ b/client/web/compose/src/views/Public/Pages/Records/View.vue @@ -194,7 +194,7 @@ export default { next: undefined, }, - abortRequests: [], + abortableRequests: [], } }, @@ -312,31 +312,18 @@ export default { }, mounted () { - this.$root.$on('refetch-record-blocks', () => { - // Don't refresh when creating and prompt user before refreshing when editing - if (this.inCreating || (this.inEditing && !window.confirm(this.$t('notification:record.staleDataRefresh')))) { - return - } - - // Refetch the record and other page blocks that use records - this.loadRecord() - this.$root.$emit(`refetch-non-record-blocks:${this.page.pageID}`) - }) + this.$root.$on('refetch-record-blocks', this.refetchRecordBlocks) }, beforeDestroy () { + this.abortRequests() this.setDefaultValues() this.destroyEvents() - this.$root.$off('refetch-record-blocks') - - this.abortRequests.forEach((cancel) => { - cancel() - }) }, // Destroy event before route leave to ensure it doesn't destroy the newly created one beforeRouteLeave (to, from, next) { - this.$root.$off('refetch-record-blocks') + this.$root.$off('refetch-record-blocks', this.refetchRecordBlocks) next() }, @@ -360,7 +347,7 @@ export default { const { response, cancel } = this.$ComposeAPI .recordReadCancellable({ namespaceID, moduleID, recordID }) - this.abortRequests.push(cancel) + this.abortableRequests.push(cancel) return response() .then(record => { @@ -538,6 +525,17 @@ export default { }) }, + refetchRecordBlocks () { + // Don't refresh when creating and prompt user before refreshing when editing + if (this.inCreating || (this.inEditing && !window.confirm(this.$t('notification:record.staleDataRefresh')))) { + return + } + + // Refetch the record and other page blocks that use records + this.loadRecord() + this.$root.$emit(`refetch-non-record-blocks:${this.page.pageID}`) + }, + setDefaultValues () { this.inEditing = false this.inCreating = false @@ -546,10 +544,17 @@ export default { this.layoutButtons.clear() this.blocks = undefined this.recordNavigation = {} + this.abortableRequests = [] + }, + + abortRequests () { + this.abortableRequests.forEach((cancel) => { + cancel() + }) }, destroyEvents () { - this.$root.$off('refetch-record-blocks') + this.$root.$off('refetch-record-blocks', this.refetchRecordBlocks) }, }, } diff --git a/client/web/compose/src/views/Public/Pages/View.vue b/client/web/compose/src/views/Public/Pages/View.vue index 107841e22..c441b5ab4 100644 --- a/client/web/compose/src/views/Public/Pages/View.vue +++ b/client/web/compose/src/views/Public/Pages/View.vue @@ -193,10 +193,7 @@ export default { }, mounted () { - this.$root.$on('refetch-records', () => { - // If on a record page, let it take care of events else just refetch non record-blocks (that use records) - this.$root.$emit(this.page.moduleID !== NoID ? 'refetch-record-blocks' : `refetch-non-record-blocks:${this.page.pageID}`) - }) + this.$root.$on('refetch-records', this.refetchRecords) }, beforeDestroy () { @@ -310,6 +307,11 @@ export default { }) }, + refetchRecords () { + // If on a record page, let it take care of events else just refetch non record-blocks (that use records) + this.$root.$emit(this.page.moduleID !== NoID ? 'refetch-record-blocks' : `refetch-non-record-blocks:${this.page.pageID}`) + }, + setDefaultValues () { this.layouts = [] this.layout = undefined @@ -318,7 +320,7 @@ export default { }, destroyEvents () { - this.$root.$off('refetch-records') + this.$root.$off('refetch-records', this.refetchRecords) }, }, } diff --git a/lib/vue/src/components/navigation/CSidebar.vue b/lib/vue/src/components/navigation/CSidebar.vue index 1a1ef5bfe..f7c30e0c4 100644 --- a/lib/vue/src/components/navigation/CSidebar.vue +++ b/lib/vue/src/components/navigation/CSidebar.vue @@ -218,15 +218,12 @@ export default { created () { this.checkIfMobile() - this.$root.$on('close-sidebar', () => { - this.isExpanded = false - this.isPinned = false - }) + this.$root.$on('close-sidebar', this.closeSidebar) window.addEventListener('resize', this.checkIfMobile) }, beforeDestroy () { - this.$root.$off('close-sidebar') + this.$root.$off('close-sidebar', this.closeSidebar) window.removeEventListener('resize', this.checkIfMobile) }, diff --git a/lib/vue/src/components/permissions/CPermissionsModal.vue b/lib/vue/src/components/permissions/CPermissionsModal.vue index e449e1912..72fe9d25c 100644 --- a/lib/vue/src/components/permissions/CPermissionsModal.vue +++ b/lib/vue/src/components/permissions/CPermissionsModal.vue @@ -330,7 +330,16 @@ export default { mounted () { this.searchUsers('', () => {}) - this.$root.$on(modalOpenEventName, ({ resource, title, target, allSpecific }) => { + this.$root.$on(modalOpenEventName, this.loadModal) + }, + + beforeDestroy () { + this.setDefaultValues() + this.destroyEvents() + }, + + methods: { + loadModal ({ resource, title, target, allSpecific }) { this.resource = resource this.title = title this.target = target @@ -364,16 +373,8 @@ export default { }) } }) + }, - }) - }, - - beforeDestroy () { - this.setDefaultValues() - this.destroyEvents() - }, - - methods: { onHide () { this.clear() },