From: Julius Härtl Date: Thu, 31 Aug 2023 14:11:13 +0000 (+0200) Subject: feat: Add events for version restore X-Git-Tag: v27.1.0rc2~9^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a518225a80fb1516dc8d6931b06db862c8d25cbe;p=nextcloud-server.git feat: Add events for version restore Signed-off-by: Julius Härtl --- 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) } },