Skip to content

Commit

Permalink
Support opening versions in viewer
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Jul 5, 2023
1 parent fc7944f commit b26cb7c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/files_versions/lib/Sabre/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function propFind(PropFind $propFind, INode $node): void {
if ($node instanceof VersionFile) {
$propFind->handle(self::VERSION_LABEL, fn() => $node->getLabel());
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
// $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, fn () => $node->get);
}
}

Expand Down
6 changes: 5 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="click"
:force-display-actions="true"
data-files-versions-version>
<template #icon>
Expand Down Expand Up @@ -272,6 +272,10 @@ export default {
deleteVersion() {
this.$emit('delete', this.version)
},
click() {
this.$emit('click', { version: this.version })
}
},
}
</script>
Expand Down
1 change: 1 addition & 0 deletions apps/files_versions/src/utils/davRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default `<?xml version="1.0"?>
<d:getcontentlength />
<d:getcontenttype />
<d:getlastmodified />
<d:getetag />
<nc:version-label />
<nc:has-preview />
</d:prop>
Expand Down
10 changes: 6 additions & 4 deletions apps/files_versions/src/utils/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import moment from '@nextcloud/moment'
* @typedef {object} Version
* @property {string} fileId - The id of the file associated to the version.
* @property {string} label - 'Current version' or ''
* @property {string} fileName - File name relative to the version DAV endpoint
* @property {string} filename - File name relative to the version DAV endpoint
* @property {string} mimeType - Empty for the current version, else the actual mime type of the version
* @property {string} etag - Empty for the current version, else the actual mime type of the version
* @property {string} size - Human readable size
* @property {string} type - 'file'
* @property {number} mtime - Version creation date as a timestamp
Expand Down Expand Up @@ -94,8 +95,9 @@ function formatVersion(version, fileInfo) {
return {
fileId: fileInfo.id,
label: version.props['version-label'],
fileName: version.filename,
filename: version.filename,
mimeType: version.mime,
etag: `${version.props.getetag}`,
size: version.size,
type: version.type,
mtime: moment(version.lastmod).unix() * 1000,
Expand All @@ -115,7 +117,7 @@ function formatVersion(version, fileInfo) {
*/
export async function setVersionLabel(version, newLabel) {
return await client.customRequest(
version.fileName,
version.filename,
{
method: 'PROPPATCH',
data: `<?xml version="1.0"?>
Expand All @@ -137,5 +139,5 @@ export async function setVersionLabel(version, newLabel) {
* @param {Version} version
*/
export async function deleteVersion(version) {
await client.deleteFile(version.fileName)
await client.deleteFile(version.filename)
}
17 changes: 17 additions & 0 deletions apps/files_versions/src/views/VersionTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@
:file-info="fileInfo"
:is-current="version.mtime === fileInfo.mtime"
:is-first-version="version.mtime === initialVersionMtime"
@click='openVersion'
@restore="handleRestore"
@label-update="handleLabelUpdate"
@delete="handleDelete" />
</ul>
</template>

<script>
import moment from 'moment'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { generateRemoteUrl } from '@nextcloud/router'
import { encodeFilePath } from '../../../files/src/utils/fileUtils.js'
import { fetchVersions, deleteVersion, restoreVersion, setVersionLabel } from '../utils/versions.js'
import Version from '../components/Version.vue'
Expand Down Expand Up @@ -182,6 +188,17 @@ export default {
resetState() {
this.$set(this, 'versions', [])
},
openVersion({version}) {
const source = generateRemoteUrl('dav') + encodeFilePath(version.filename)
OCA.Viewer.open({
fileInfo: {...version, source, basename: moment(version.mtime).format('LLL'), mime: version.mimeType},
list: [],
// list: this.versions,
loadMore: () => null
})
}
},
}
</script>

0 comments on commit b26cb7c

Please sign in to comment.