Skip to content

Commit

Permalink
Allow linking to directories in addition to linking to files.
Browse files Browse the repository at this point in the history
The link syntax supported is:

[LINK_TEXT_AS_NORMAL](RELATIVE/PATH/WITH/TRAILING/SLASH/?fileId=FILE_ID_OF_DIRECTORY)

In the current implementation clicking on the link leads to a new tab or
window where the linked directory is shown.

The difference to the syntax for ordinary files is just the missing
file-name at the end.
  • Loading branch information
rotdrop committed Feb 7, 2022
1 parent 51e0592 commit 3e7ae96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export default {
href,
})
})
}, false, [], true, undefined, this.linkPath)
}, false, [], true, undefined, this.linkPath, { allowDirectoryChooser: true })
},
optimalPathTo(targetFile) {
const absolutePath = targetFile.split('/')
Expand Down
8 changes: 6 additions & 2 deletions src/components/MenuBubble.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ export default {
client.getFileInfo(file).then((_status, fileInfo) => {
const path = optimalPath(this.filePath, `${fileInfo.path}/${fileInfo.name}`)
const encodedPath = path.split('/').map(encodeURIComponent).join('/')
command({ href: `${encodedPath}?fileId=${fileInfo.id}` })
if (fileInfo.mimetype === 'httpd/unix-directory') {
command({ href: `${encodedPath}/?fileId=${fileInfo.id}` })
} else {
command({ href: `${encodedPath}?fileId=${fileInfo.id}` })
}
this.hideLinkMenu()
})
}, false, [], true, undefined, startPath)
}, false, [], true, undefined, startPath, { allowDirectoryChooser: true })
},
setLinkUrl(command, url) {
// Heuristics for determining if we need a https:// prefix.
Expand Down
9 changes: 7 additions & 2 deletions src/helpers/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ const domHref = function(node) {
if (match) {
const [, relPath, id] = match
const currentDir = basedir(OCA.Viewer.file)
const dir = absolutePath(currentDir, basedir(relPath))
return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`)
if (relPath.slice(-1) === '/') {
const dir = absolutePath(currentDir, relPath)
return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}`)
} else {
const dir = absolutePath(currentDir, basedir(relPath))
return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`)
}
}
}

Expand Down

0 comments on commit 3e7ae96

Please sign in to comment.