aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/components/FileEntryMixin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/components/FileEntryMixin.ts')
-rw-r--r--apps/files/src/components/FileEntryMixin.ts103
1 files changed, 74 insertions, 29 deletions
diff --git a/apps/files/src/components/FileEntryMixin.ts b/apps/files/src/components/FileEntryMixin.ts
index d949a907d43..735490c45b3 100644
--- a/apps/files/src/components/FileEntryMixin.ts
+++ b/apps/files/src/components/FileEntryMixin.ts
@@ -133,11 +133,16 @@ export default defineComponent({
return this.source.status === NodeStatus.FAILED
},
- canDrag() {
+ canDrag(): boolean {
if (this.isRenaming) {
return false
}
+ // Ignore if the node is not available
+ if (this.isFailedSource) {
+ return false
+ }
+
const canDrag = (node: Node): boolean => {
return (node?.permissions & Permission.UPDATE) !== 0
}
@@ -150,11 +155,16 @@ export default defineComponent({
return canDrag(this.source)
},
- canDrop() {
+ canDrop(): boolean {
if (this.source.type !== FileType.Folder) {
return false
}
+ // Ignore if the node is not available
+ if (this.isFailedSource) {
+ return false
+ }
+
// If the current folder is also being dragged, we can't drop it on itself
if (this.draggingFiles.includes(this.source.source)) {
return false
@@ -168,25 +178,52 @@ export default defineComponent({
return this.actionsMenuStore.opened === this.uniqueId.toString()
},
set(opened) {
- this.actionsMenuStore.opened = opened ? this.uniqueId.toString() : null
+ // If the menu is opened on another file entry, we ignore closed events
+ if (opened === false && this.actionsMenuStore.opened !== this.uniqueId.toString()) {
+ return
+ }
+
+ // If opened, we specify the current file id
+ // else we set it to null to close the menu
+ this.actionsMenuStore.opened = opened
+ ? this.uniqueId.toString()
+ : null
},
},
- mtimeOpacity() {
- const maxOpacityTime = 31 * 24 * 60 * 60 * 1000 // 31 days
+ mtime() {
+ // If the mtime is not a valid date, return it as is
+ if (this.source.mtime && !isNaN(this.source.mtime.getDate())) {
+ return this.source.mtime
+ }
+
+ if (this.source.crtime && !isNaN(this.source.crtime.getDate())) {
+ return this.source.crtime
+ }
+
+ return null
+ },
- const mtime = this.source.mtime?.getTime?.()
- if (!mtime) {
+ mtimeOpacity() {
+ if (!this.mtime) {
return {}
}
- // 1 = today, 0 = 31 days ago
- const ratio = Math.round(Math.min(100, 100 * (maxOpacityTime - (Date.now() - mtime)) / maxOpacityTime))
- if (ratio < 0) {
+ // The time when we start reducing the opacity
+ const maxOpacityTime = 31 * 24 * 60 * 60 * 1000 // 31 days
+ // everything older than the maxOpacityTime will have the same value
+ const timeDiff = Date.now() - this.mtime.getTime()
+ if (timeDiff < 0) {
+ // this means we have an invalid mtime which is in the future!
return {}
}
+
+ // inversed time difference from 0 to maxOpacityTime (which would mean today)
+ const opacityTime = Math.max(0, maxOpacityTime - timeDiff)
+ // 100 = today, 0 = 31 days ago or older
+ const percentage = Math.round(opacityTime * 100 / maxOpacityTime)
return {
- color: `color-mix(in srgb, var(--color-main-text) ${ratio}%, var(--color-text-maxcontrast))`,
+ color: `color-mix(in srgb, var(--color-main-text) ${percentage}%, var(--color-text-maxcontrast))`,
}
},
@@ -235,21 +272,16 @@ export default defineComponent({
},
openedMenu() {
- if (this.openedMenu === false) {
- // TODO: This timeout can be removed once `close` event only triggers after the transition
- // ref: https://github.com/nextcloud-libraries/nextcloud-vue/pull/6065
- window.setTimeout(() => {
- if (this.openedMenu) {
- // was reopened while the animation run
- return
- }
- // Reset any right menu position potentially set
- const root = document.getElementById('app-content-vue')
- if (root !== null) {
- root.style.removeProperty('--mouse-pos-x')
- root.style.removeProperty('--mouse-pos-y')
- }
- }, 300)
+ // Checking if the menu is really closed and not
+ // just a change in the open state to another file entry.
+ if (this.actionsMenuStore.opened === null) {
+ // Reset any right menu position potentially set
+ logger.debug('All actions menu closed, resetting right menu position...')
+ const root = this.$el?.closest('main.app-content') as HTMLElement
+ if (root !== null) {
+ root.style.removeProperty('--mouse-pos-x')
+ root.style.removeProperty('--mouse-pos-y')
+ }
}
},
},
@@ -274,6 +306,11 @@ export default defineComponent({
return
}
+ // Ignore right click if the node is not available
+ if (this.isFailedSource) {
+ return
+ }
+
// The grid mode is compact enough to not care about
// the actions menu mouse position
if (!this.gridMode) {
@@ -282,6 +319,7 @@ export default defineComponent({
const contentRect = root.getBoundingClientRect()
// Using Math.min/max to prevent the menu from going out of the AppContent
// 200 = max width of the menu
+ logger.debug('Setting actions menu position...')
root.style.setProperty('--mouse-pos-x', Math.max(0, event.clientX - contentRect.left - 200) + 'px')
root.style.setProperty('--mouse-pos-y', Math.max(0, event.clientY - contentRect.top) + 'px')
} else {
@@ -311,9 +349,14 @@ export default defineComponent({
return
}
+ // Ignore if the node is not available
+ if (this.isFailedSource) {
+ return
+ }
+
// if ctrl+click / cmd+click (MacOS uses the meta key) or middle mouse button (button & 4), open in new tab
// also if there is no default action use this as a fallback
- const metaKeyPressed = event.ctrlKey || event.metaKey || Boolean(event.button & 4)
+ const metaKeyPressed = event.ctrlKey || event.metaKey || event.button === 1
if (metaKeyPressed || !this.defaultFileAction) {
// If no download permission, then we can not allow to download (direct link) the files
if (isPublicShare() && !isDownloadable(this.source)) {
@@ -325,7 +368,9 @@ export default defineComponent({
: generateUrl('/f/{fileId}', { fileId: this.fileid })
event.preventDefault()
event.stopPropagation()
- window.open(url, metaKeyPressed ? '_self' : undefined)
+
+ // Open the file in a new tab if the meta key or the middle mouse button is clicked
+ window.open(url, metaKeyPressed ? '_blank' : '_self')
return
}
@@ -442,7 +487,7 @@ export default defineComponent({
logger.debug('Dropped', { event, folder, selection, fileTree })
// Check whether we're uploading files
- if (fileTree.contents.length > 0) {
+ if (selection.length === 0 && fileTree.contents.length > 0) {
await onDropExternalFiles(fileTree, folder, contents.contents)
return
}