Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] Add version sidebar events #40352

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion apps/files_versions/src/components/Version.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div>
<NcListItem class="version"
:title="versionLabel"
:href="downloadURL"
@click="openVersion"
:force-display-actions="true"
data-files-versions-version>
<template #icon>
Expand Down Expand Up @@ -122,6 +122,7 @@ import { translate } from '@nextcloud/l10n'
import { joinPaths } from '@nextcloud/paths'
import { generateUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import { emit } from '@nextcloud/event-bus'

export default {
name: 'Version',
Expand Down Expand Up @@ -238,6 +239,19 @@ export default {
},
},
methods: {
openVersion(e) {
e.preventDefault()
const openVersionEvent = {
preventDefault: false,
fileInfo: this.fileInfo,
version: this.version,
}
emit('files_versions:view:open', openVersionEvent)
if (openVersionEvent.preventDefault) {
return
}
window.location.href = this.downloadURL
},
openVersionLabelModal() {
this.showVersionLabelForm = true
this.$nextTick(() => {
Expand Down
20 changes: 19 additions & 1 deletion apps/files_versions/src/views/VersionTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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.
Expand Down Expand Up @@ -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 !== '') {
Expand All @@ -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)
}
},

Expand Down
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_versions-files_versions.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_versions-files_versions.js.map

Large diffs are not rendered by default.