Skip to content

Commit 3e7ae96

Browse files
committed
Allow linking to directories in addition to linking to files.
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.
1 parent 51e0592 commit 3e7ae96

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/components/MenuBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ export default {
450450
href,
451451
})
452452
})
453-
}, false, [], true, undefined, this.linkPath)
453+
}, false, [], true, undefined, this.linkPath, { allowDirectoryChooser: true })
454454
},
455455
optimalPathTo(targetFile) {
456456
const absolutePath = targetFile.split('/')

src/components/MenuBubble.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,14 @@ export default {
151151
client.getFileInfo(file).then((_status, fileInfo) => {
152152
const path = optimalPath(this.filePath, `${fileInfo.path}/${fileInfo.name}`)
153153
const encodedPath = path.split('/').map(encodeURIComponent).join('/')
154-
command({ href: `${encodedPath}?fileId=${fileInfo.id}` })
154+
if (fileInfo.mimetype === 'httpd/unix-directory') {
155+
command({ href: `${encodedPath}/?fileId=${fileInfo.id}` })
156+
} else {
157+
command({ href: `${encodedPath}?fileId=${fileInfo.id}` })
158+
}
155159
this.hideLinkMenu()
156160
})
157-
}, false, [], true, undefined, startPath)
161+
}, false, [], true, undefined, startPath, { allowDirectoryChooser: true })
158162
},
159163
setLinkUrl(command, url) {
160164
// Heuristics for determining if we need a https:// prefix.

src/helpers/links.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ const domHref = function(node) {
5959
if (match) {
6060
const [, relPath, id] = match
6161
const currentDir = basedir(OCA.Viewer.file)
62-
const dir = absolutePath(currentDir, basedir(relPath))
63-
return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`)
62+
if (relPath.slice(-1) === '/') {
63+
const dir = absolutePath(currentDir, relPath)
64+
return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}`)
65+
} else {
66+
const dir = absolutePath(currentDir, basedir(relPath))
67+
return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`)
68+
}
6469
}
6570
}
6671

0 commit comments

Comments
 (0)