]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat: Add events for version restore
authorJulius Härtl <jus@bitgrid.net>
Thu, 31 Aug 2023 14:11:13 +0000 (16:11 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Wed, 6 Sep 2023 13:59:34 +0000 (13:59 +0000)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/files_versions/src/views/VersionTab.vue

index 4857b8e0ded6d37457b0725db707c99c64d5ca13..178cc3e931a37eab7ca15c6c434926385edfb0ef 100644 (file)
@@ -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)
                        }
                },