From a518225a80fb1516dc8d6931b06db862c8d25cbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20H=C3=A4rtl?= Date: Thu, 31 Aug 2023 16:11:13 +0200 Subject: [PATCH] feat: Add events for version restore MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files_versions/src/views/VersionTab.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/files_versions/src/views/VersionTab.vue b/apps/files_versions/src/views/VersionTab.vue index 4857b8e0ded..178cc3e931a 100644 --- a/apps/files_versions/src/views/VersionTab.vue +++ b/apps/files_versions/src/views/VersionTab.vue @@ -39,6 +39,7 @@ import { showError, showSuccess } from '@nextcloud/dialogs' import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js' import { fetchVersions, deleteVersion, restoreVersion, setVersionLabel } from '../utils/versions.js' import Version from '../components/Version.vue' +import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus' export default { name: 'VersionTab', @@ -57,6 +58,12 @@ export default { loading: false, } }, + mounted() { + subscribe('files_versions:restore:restored', this.fetchVersions) + }, + beforeUnmount() { + unsubscribe('files_versions:restore:restored', this.fetchVersions) + }, computed: { /** * Order versions by mtime. @@ -163,6 +170,16 @@ export default { mtime: version.mtime, } + const restoreStartedEventState = { + preventDefault: false, + fileInfo: this.fileInfo, + version, + } + emit('files_versions:restore:requested', restoreStartedEventState) + if (restoreStartedEventState.preventDefault) { + return + } + try { await restoreVersion(version) if (version.label !== '') { @@ -172,10 +189,11 @@ export default { } else { showSuccess(t('files_versions', 'Version restored')) } - await this.fetchVersions() + emit('files_versions:restore:restored', version) } catch (exception) { this.fileInfo = oldFileInfo showError(t('files_versions', 'Could not restore version')) + emit('files_versions:restore:failed', version) } }, -- 2.39.5