Skip to content

Commit e73f060

Browse files
committed
Trigger click event when scrollTo is set
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent f6485f9 commit e73f060

9 files changed

Lines changed: 92 additions & 34 deletions

File tree

apps/files/js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
fileActions: fileActions,
9292
allowLegacyActions: true,
9393
scrollTo: urlParams.scrollto,
94+
openFile: urlParams.openfile,
9495
filesClient: OC.Files.getClient(),
9596
multiSelectMenu: [
9697
{

apps/files/js/dist/sidebar.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files/js/dist/sidebar.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files/js/fileactions.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,19 @@
679679
permissions: OC.PERMISSION_READ,
680680
icon: '',
681681
actionHandler: function (filename, context) {
682-
var dir = context.$file.attr('data-path') || context.fileList.getCurrentDirectory();
682+
let dir, id
683+
if (context.$file) {
684+
dir = context.$file.attr('data-path')
685+
id = context.$file.attr('data-id')
686+
} else{
687+
dir = context.fileList.getCurrentDirectory()
688+
id = context.objectId
689+
}
683690
if (OCA.Files.App && OCA.Files.App.getActiveView() !== 'files') {
684691
OCA.Files.App.setActiveView('files', {silent: true});
685692
OCA.Files.App.fileList.changeDirectory(OC.joinPaths(dir, filename), true, true);
686693
} else {
687-
context.fileList.changeDirectory(OC.joinPaths(dir, filename), true, false, parseInt(context.$file.attr('data-id'), 10));
694+
context.fileList.changeDirectory(OC.joinPaths(dir, filename), true, false, parseInt(id, 10));
688695
}
689696
},
690697
displayName: t('files', 'Open')

apps/files/js/filelist.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,32 @@
414414
});
415415
}
416416

417+
if(options.openFile) {
418+
// Wait for some initialisation process to be over before triggering the default action.
419+
_.defer(() => {
420+
try {
421+
const fileInfo = JSON.parse(atob($('#initial-state-files-openFileInfo').val()))
422+
var spec = this.fileActions.getDefaultFileAction(fileInfo.mime, fileInfo.type, fileInfo.permissions)
423+
if (spec && spec.action) {
424+
spec.action(fileInfo.name, {
425+
objectId: fileInfo.id,
426+
fileList: this,
427+
fileActions: this.fileActions,
428+
dir: fileInfo.directory
429+
});
430+
}
431+
else {
432+
var url = this.getDownloadUrl(fileInfo.name, fileInfo.dir, true);
433+
OCA.Files.Files.handleDownload(url);
434+
}
435+
436+
OCA.Files.Sidebar.open(fileInfo.path);
437+
} catch (error) {
438+
console.error(`Failed to trigger default action on the file for URL: ${location.href}`, error)
439+
}
440+
})
441+
}
442+
417443
this._operationProgressBar = new OCA.Files.OperationProgressBar();
418444
this._operationProgressBar.render();
419445
this.$el.find('#uploadprogresswrapper').replaceWith(this._operationProgressBar.$el);
@@ -1320,31 +1346,6 @@
13201346
}, 0);
13211347
}
13221348

1323-
if(!this.triedActionOnce) {
1324-
var id = OC.Util.History.parseUrlQuery().openfile;
1325-
if (id) {
1326-
var $tr = this.$fileList.children().filterAttr('data-id', '' + id);
1327-
var filename = $tr.attr('data-file');
1328-
this.fileActions.currentFile = $tr.find('td');
1329-
var dir = $tr.attr('data-path') || this.getCurrentDirectory();
1330-
var spec = this.fileActions.getCurrentDefaultFileAction();
1331-
if (spec && spec.action) {
1332-
spec.action(filename, {
1333-
$file: $tr,
1334-
fileList: this,
1335-
fileActions: this.fileActions,
1336-
dir: dir
1337-
});
1338-
1339-
}
1340-
else {
1341-
var url = this.getDownloadUrl(filename, dir, true);
1342-
OCA.Files.Files.handleDownload(url);
1343-
}
1344-
}
1345-
this.triedActionOnce = true;
1346-
}
1347-
13481349
return newTrs;
13491350
},
13501351

apps/files/lib/Controller/ViewController.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function showFile(string $fileid = null): Response {
182182
* @return TemplateResponse|RedirectResponse
183183
* @throws NotFoundException
184184
*/
185-
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
185+
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) {
186186
if ($fileid !== null) {
187187
try {
188188
return $this->redirectToFile($fileid);
@@ -331,6 +331,34 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
331331
$policy->addAllowedFrameDomain('\'self\'');
332332
$response->setContentSecurityPolicy($policy);
333333

334+
$user = $this->userSession->getUser();
335+
if ($openfile !== null && $user != null) {
336+
$uid = $user->getUID();
337+
$userFolder = $this->rootFolder->getUserFolder($uid);
338+
$node = $userFolder->getById($openfile)[0];
339+
340+
// properly format full path and make sure
341+
// we're relative to the user home folder
342+
$isRoot = $node === $userFolder;
343+
$path = $userFolder->getRelativePath($node->getPath());
344+
$directory = $userFolder->getRelativePath($node->getParent()->getPath());
345+
346+
// Prevent opening a file from another folder.
347+
if ($dir === $directory) {
348+
$this->initialState->provideInitialState(
349+
'openFileInfo', [
350+
'id' => $node->getId(),
351+
'name' => $isRoot ? '' : $node->getName(),
352+
'path' => $path,
353+
'directory' => $directory,
354+
'mime' => $node->getMimetype(),
355+
'type' => $node->getType(),
356+
'permissions' => $node->getPermissions(),
357+
]
358+
);
359+
}
360+
}
361+
334362
return $response;
335363
}
336364

apps/files/lib/Search/FilesSearchProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
123123
[
124124
'dir' => dirname($path),
125125
'scrollto' => $result->getName(),
126+
'openfile' => $result->getId(),
126127
]
127128
);
128129

apps/files/src/sidebar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ window.addEventListener('DOMContentLoaded', function() {
5858
AppSidebar.$mount('#app-sidebar')
5959
window.OCA.Files.Sidebar.open = AppSidebar.open
6060
window.OCA.Files.Sidebar.close = AppSidebar.close
61+
window.OCA.Files.Sidebar.setFullScreenMode = AppSidebar.setFullScreenMode
6162
})

apps/files/src/views/Sidebar.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export default {
110110
loading: true,
111111
fileInfo: null,
112112
starLoading: false,
113+
isFullScreen: false,
113114
}
114115
},
115116
@@ -202,7 +203,10 @@ export default {
202203
'star-loading': this.starLoading,
203204
active: this.activeTab,
204205
background: this.background,
205-
class: { 'has-preview': this.fileInfo.hasPreview },
206+
class: {
207+
'app-sidebar--has-preview': this.fileInfo.hasPreview,
208+
'app-sidebar--full': this.isFullScreen,
209+
},
206210
compact: !this.fileInfo.hasPreview,
207211
loading: this.loading,
208212
starred: this.fileInfo.isFavourited,
@@ -428,6 +432,14 @@ export default {
428432
this.resetData()
429433
},
430434
435+
/**
436+
* Allow to set the Sidebar as fullscreen from OCA.Files.Sidebar
437+
* @param {boolean} isFullScreen - Wether or not to render the Sidebar in fullscreen.
438+
*/
439+
setFullScreenMode(isFullScreen) {
440+
this.isFullScreen = isFullScreen
441+
},
442+
431443
/**
432444
* Emit SideBar events.
433445
*/
@@ -448,7 +460,7 @@ export default {
448460
</script>
449461
<style lang="scss" scoped>
450462
.app-sidebar {
451-
&.has-preview::v-deep {
463+
&--has-preview::v-deep {
452464
.app-sidebar-header__figure {
453465
background-size: cover;
454466
}
@@ -460,5 +472,12 @@ export default {
460472
}
461473
}
462474
}
475+
476+
&--full {
477+
position: fixed !important;
478+
z-index: 2025 !important;
479+
top: 0 !important;
480+
height: 100% !important;
481+
}
463482
}
464483
</style>

0 commit comments

Comments
 (0)