From f9d7d4542bb17947ed1c0ebb531d40d4453e6a93 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 f2e9576abd0..ca2ac5ca6c3 100644 --- a/apps/files_versions/src/views/VersionTab.vue +++ b/apps/files_versions/src/views/VersionTab.vue @@ -33,6 +33,7 @@ import { showError, showSuccess } from '@nextcloud/dialogs' 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', @@ -47,6 +48,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. @@ -114,6 +121,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 !== '') { @@ -123,10 +140,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