Skip to content

Commit

Permalink
feat: Compare files side by side
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Aug 3, 2023
1 parent 621722b commit b90dbb4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/services/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class Viewer {
this._state = {}
this._state.file = ''
this._state.fileInfo = null
this._state.compareFileInfo = null
this._state.files = []
this._state.enableSidebar = true
this._state.el = null
Expand Down Expand Up @@ -107,6 +108,16 @@ export default class Viewer {
return this._state.fileInfo
}

/**
* Get the current comparison view opened file fileInfo
*
* @memberof Viewer
* @return {?Fileinfo} the currently opened file fileInfo
*/
get compareFileInfo() {
return this._state.compareFileInfo
}

/**
* Get the current files list
*
Expand Down Expand Up @@ -291,6 +302,13 @@ export default class Viewer {
this.open(options)
}

compare(currentFileInfo, versionFileInfo) {
/* this.open({
fileInfo: currentFileInfo,
}) */
this._state.compareFileInfo = versionFileInfo
}

/**
* Close the opened file
*
Expand Down
52 changes: 49 additions & 3 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,22 @@
</NcActionButton>
</template>

<div class="viewer__content" @click.self.exact="close">
<div class="viewer__content" :class="contentClass" @click.self.exact="close">
<component :is="comparisonFile.modal"
v-if="comparisonFile && !comparisonFile.failed"
:key="comparisonFile.fileid"
ref="content"
v-bind="comparisonFile"
:active="true"
:can-swipe="false"
:can-zoom="false"
:editing="false"
:is-full-screen="isFullscreen"
:is-sidebar-shown="isSidebarShown"
:loaded.sync="comparisonFile.loaded"
class="viewer__file viewer__file--active"
@error="currentFailed" />

<!-- PREVIOUS -->
<component :is="previousFile.modal"
v-if="previousFile && !previousFile.failed"
Expand Down Expand Up @@ -230,6 +245,7 @@ export default {
currentIndex: 0,
previousFile: {},
currentFile: {},
comparisonFile: {},
nextFile: {},
fileList: [],
Expand Down Expand Up @@ -274,6 +290,9 @@ export default {
fileInfo() {
return this.Viewer.fileInfo
},
comparisonFileInfo() {
return this.Viewer.compareFileInfo
},
files() {
return this.Viewer.files
},
Expand Down Expand Up @@ -365,6 +384,12 @@ export default {
'image--fullscreen': this.isImage && this.isFullscreenMode,
}
},
contentClass() {
return {
viewer__split: this.comparisonFile,
}
},
},
watch: {
Expand Down Expand Up @@ -406,6 +431,16 @@ export default {
}
},
comparisonFileInfo(fileInfo) {
if (fileInfo) {
logger.info('Opening viewer for comparisonFileInfo ', { fileInfo })
this.compareFile(fileInfo)
} else {
// object is undefined, we're closing!
this.cleanup()
}
},
files(fileList) {
// the files list changed, let's update the current opened index
const currentIndex = fileList.findIndex(file => file.basename === this.currentFile.basename)
Expand Down Expand Up @@ -516,7 +551,7 @@ export default {
this.cancelRequestFile()
// do not open the same file again
if (path === this.currentFile.path) {
if (path === this.currentFile.path && !this.currentFile.source) { // need to still run when switching from version to current file
return
}
Expand Down Expand Up @@ -567,7 +602,7 @@ export default {
this.cancelRequestFolder()
// do not open the same file info again
if (fileInfo.basename === this.currentFile.basename) {
if (fileInfo.basename === this.currentFile.basename && fileInfo.source !== this.currentFile.source) {
return
}
Expand Down Expand Up @@ -637,6 +672,7 @@ export default {
// show file
this.currentFile = new File(fileInfo, mime, handler.component)
this.comparisonFile = null
this.updatePreviousNext()
// if sidebar was opened before, let's update the file
Expand All @@ -656,6 +692,10 @@ export default {
this.updatePreviousNext()
},
async compareFile(fileInfo) {
this.comparisonFile = new File(fileInfo, fileInfo.mime, this.components[fileInfo.mime])
},
/**
* Show sidebar if available and a file is already opened
*/
Expand Down Expand Up @@ -1085,6 +1125,12 @@ export default {
cursor: pointer;
}
&__split {
.viewer__file--active {
width: 50%;
}
}
:deep(.modal-wrapper) {
.modal-container {
// Ensure some space at the bottom
Expand Down

0 comments on commit b90dbb4

Please sign in to comment.