Skip to content

Commit

Permalink
Merge pull request #3171 from nextcloud/bugfix/noid/version-view-26
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Sep 15, 2023
2 parents fbddd92 + e4e6094 commit 30b5d28
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 86 deletions.
57 changes: 25 additions & 32 deletions src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const documentsMain = {
},

loadRevViewerContainer() {
if (!$('revViewerContainer').length) {
if (!$('#revViewerContainer').length) {
$(document.body).prepend(documentsMain.UI.viewContainer)
const closeButton = $('<button class="icon-close closeButton" title="' + t('richdocuments', 'Close version preview') + '"/>')
$('#revViewerContainer').prepend(closeButton)
Expand Down Expand Up @@ -379,40 +379,33 @@ const documentsMain = {
return
}

if (documentsMain.isViewerMode) {
let { fileId, title, version } = args
switch (parsed.msgId) {
case 'Action_loadRevViewer':
documentsMain.UI.loadRevViewerContainer()
if (fileId) {
fileId += '_' + Config.get('instanceId')
if (version) {
fileId += `_${version}`
title += `_${version}`
}
documentsMain.UI.showViewer(
fileId, title
)
}
break
case 'Host_VersionRestore':
// resolve the deferred object immediately if client doesn't support version states
if (!documentsMain.wopiClientFeatures || !documentsMain.wopiClientFeatures.VersionStates) {
console.error('No version support')
// Not forwarding message to collabora
return
let { fileId, title, version } = args
switch (parsed.msgId) {
case 'Action_loadRevViewer':
documentsMain.UI.loadRevViewerContainer()
if (fileId) {
fileId += '_' + Config.get('instanceId')
if (version) {
fileId += `_${version}`
title += `_${version}`
}
documentsMain.onCloseViewer()
break
case 'App_VersionRestore':
// Status = Pre_Restore_Ack -> Ready to restore version
break
case 'UI_Share':
break
default:
documentsMain.UI.showViewer(
fileId, title
)
}
break
case 'Host_VersionRestore':
// resolve the deferred object immediately if client doesn't support version states
if (!documentsMain.wopiClientFeatures || !documentsMain.wopiClientFeatures.VersionStates) {
console.error('No version support')
// Not forwarding message to collabora
return
}

documentsMain.onCloseViewer()
break
case 'App_VersionRestore':
// Status = Pre_Restore_Ack -> Ready to restore version
break
}

// Pass all messages to viewer if not direct editing or
Expand Down
92 changes: 38 additions & 54 deletions src/view/FilesAppIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import { generateUrl, generateRemoteUrl, getRootUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import moment from '@nextcloud/moment'
import { subscribe, unsubscribe, emit } from '@nextcloud/event-bus'
import { getCurrentDirectory } from '../helpers/filesApp.js'

const isPublic = document.getElementById('isPublic') && document.getElementById('isPublic').value === '1'
Expand Down Expand Up @@ -94,6 +94,9 @@ export default {
this.updateFileInfo(undefined, Date.now())

this.fileModel = null
this.fileName = null
this.fileId = null

if (!isPublic) {
this.removeVersionSidebarEvents()
}
Expand Down Expand Up @@ -428,76 +431,56 @@ export default {
},

addVersionSidebarEvents() {
$(document.querySelector('#content')).on('click.revisions', '.app-sidebar .preview-container', this.showVersionPreview.bind(this))
$(document.querySelector('#content')).on('click.revisions', '.app-sidebar .downloadVersion', this.showVersionPreview.bind(this))
$(document.querySelector('#content')).on('mousedown.revisions', '.app-sidebar .revertVersion', this.restoreVersion.bind(this))
$(document.querySelector('#content')).on('click.revisionsTab', '.app-sidebar [data-tabid=versionsTabView]', this.addCurrentVersion.bind(this))
subscribe('files_versions:view:open', this.handleVersionOpen.bind(this))
subscribe('files_versions:restore:requested', this.handleVersionRestore.bind(this))

// $(document.querySelector('#content')).on('mousedown.revisions', '.app-sidebar .revertVersion', this.restoreVersion.bind(this))
},

removeVersionSidebarEvents() {
$(document.querySelector('#content')).off('click.revisions')
$(document.querySelector('#content')).off('click.revisions')
$(document.querySelector('#content')).off('mousedown.revisions')
$(document.querySelector('#content')).off('click.revisionsTab')
},

addCurrentVersion() {
$('#lastSavedVersion').remove()
$('#currentVersion').remove()
if (this.getFileModel()) {
const preview = OC.MimeType.getIconUrl(this.getFileModel().get('mimetype'))
const mtime = this.getFileModel().get('mtime')
$('.tab.versionsTabView').prepend('<ul id="lastSavedVersion"><li data-revision="0"><div><div class="preview-container"><img src="' + preview + '" width="44" /></div><div class="version-container">\n'
+ '<div><a class="downloadVersion">' + t('richdocuments', 'Last saved version') + ' (<span class="versiondate has-tooltip live-relative-timestamp" data-timestamp="' + mtime + '"></span>)</div></div></li></ul>')
$('.tab.versionsTabView').prepend('<ul id="currentVersion"><li data-revision="" class="active"><div><div class="preview-container"><img src="' + preview + '" width="44" /></div><div class="version-container">\n'
+ '<div><a class="downloadVersion">' + t('richdocuments', 'Current version (unsaved changes)') + '</a></div></div></li></ul>')
$('.live-relative-timestamp').each(function() {
$(this).text(moment(parseInt($(this).attr('data-timestamp'), 10)).fromNow())
})
}
unsubscribe('files_versions:view:open', this.handleVersionOpen.bind(this))
unsubscribe('files_versions:restore:requested', this.handleVersionRestore.bind(this))
},

showRevHistory() {
if (this.handlers.showRevHistory && this.handlers.showRevHistory(this)) {
handleVersionOpen(event) {
const version = event.version.mtime !== event.fileInfo.mtime ? Math.round(event.version.mtime / 1000) : 0
const fileId = this.fileId
const title = this.fileName

if (!fileId) {
return
}

if (this.getFileList()) {
this.getFileList()
.showDetailsView(this.fileName, 'versionsTabView')
this.addCurrentVersion()
}
},
event.preventDefault = true

showVersionPreview(e) {
e.preventDefault()
let element = e.currentTarget.parentElement.parentElement
if ($(e.currentTarget).hasClass('downloadVersion')) {
element = e.currentTarget.parentElement.parentElement.parentElement.parentElement
}
const version = element.dataset.revision
const fileId = this.fileId
const title = this.fileName
console.debug('[FilesAppIntegration] showVersionPreview', version, fileId, title)
console.debug('[FilesAppIntegration] showVersionPreview', version, fileId, title, event)
this.sendPostMessage('Action_loadRevViewer', { fileId, title, version })
$(element.parentElement.parentElement).find('li').removeClass('active')
$(element).addClass('active')
},

restoreVersion(e) {
e.preventDefault()
e.stopPropagation()
handleVersionRestore(event) {
event.preventDefault = true

this.versionInRestore = event.version

this.sendPostMessage('Host_VersionRestore', { Status: 'Pre_Restore' })

const version = e.currentTarget.parentElement.parentElement.dataset.revision
const version = Math.round(event.version.mtime / 1000)

this._restoreVersionCallback = () => {
this._restoreDAV(version)
this._restoreVersionCallback = null
}
},

showRevHistory() {
if (this.handlers.showRevHistory && this.handlers.showRevHistory(this)) {
return
}

return false
if (this.getFileList()) {
this.getFileList()
.showDetailsView(this.fileName, 'version_vue')
}
},

restoreVersionExecute() {
Expand All @@ -514,10 +497,11 @@ export default {
if (response.status === 'error') {
OC.Notification.showTemporary(t('richdocuments', 'Failed to revert the document to older version'))
}
// Reload the document frame to get the new file
// TODO: ideally we should have a post messsage that can be sent to collabora to just reload the file once the restore is finished
document.getElementById('richdocumentsframe').src = document.getElementById('richdocumentsframe').src
OC.Apps.hideAppSidebar()

OC.Notification.showTemporary(t('richdocuments', 'Version restored'))

emit('files_versions:restore:restored', this.versionInRestore)
this.versionInRestore = null
},

_restoreError() {
Expand Down

0 comments on commit 30b5d28

Please sign in to comment.