Skip to content

Commit 206ddb1

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

File tree

9 files changed

+115
-34
lines changed

9 files changed

+115
-34
lines changed

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.fileId
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: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,31 @@
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+
var 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+
fileId: fileInfo.id,
426+
fileList: this,
427+
fileActions: this.fileActions,
428+
dir: fileInfo.directory
429+
});
430+
} else {
431+
var url = this.getDownloadUrl(fileInfo.name, fileInfo.dir, true);
432+
OCA.Files.Files.handleDownload(url);
433+
}
434+
435+
OCA.Files.Sidebar.open(fileInfo.path);
436+
} catch (error) {
437+
console.error(`Failed to trigger default action on the file for URL: ${location.href}`, error)
438+
}
439+
})
440+
}
441+
417442
this._operationProgressBar = new OCA.Files.OperationProgressBar();
418443
this._operationProgressBar.render();
419444
this.$el.find('#uploadprogresswrapper').replaceWith(this._operationProgressBar.$el);
@@ -1320,31 +1345,6 @@
13201345
}, 0);
13211346
}
13221347

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-
13481348
return newTrs;
13491349
},
13501350

apps/files/lib/Controller/ViewController.php

Lines changed: 53 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,9 +331,61 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
331331
$policy->addAllowedFrameDomain('\'self\'');
332332
$response->setContentSecurityPolicy($policy);
333333

334+
$this->provideInitialState($dir, $openfile);
335+
334336
return $response;
335337
}
336338

339+
/**
340+
* Add openFileInfo in initialState if $openfile is set.
341+
* @param string $dir - the ?dir= URL param
342+
* @param string $openfile - the ?openfile= URL param
343+
* @return void
344+
*/
345+
private function provideInitialState($dir, $openfile) {
346+
if ($openfile === null) {
347+
return;
348+
}
349+
350+
$user = $this->userSession->getUser();
351+
352+
if ($user === null) {
353+
return;
354+
}
355+
356+
$uid = $user->getUID();
357+
$userFolder = $this->rootFolder->getUserFolder($uid);
358+
$nodes = $userFolder->getById((int) $openfile);
359+
$node = array_shift($nodes);
360+
361+
if ($node === null) {
362+
return;
363+
}
364+
365+
// properly format full path and make sure
366+
// we're relative to the user home folder
367+
$isRoot = $node === $userFolder;
368+
$path = $userFolder->getRelativePath($node->getPath());
369+
$directory = $userFolder->getRelativePath($node->getParent()->getPath());
370+
371+
// Prevent opening a file from another folder.
372+
if ($dir !== $directory) {
373+
return;
374+
}
375+
376+
$this->initialState->provideInitialState(
377+
'openFileInfo', [
378+
'id' => $node->getId(),
379+
'name' => $isRoot ? '' : $node->getName(),
380+
'path' => $path,
381+
'directory' => $directory,
382+
'mime' => $node->getMimetype(),
383+
'type' => $node->getType(),
384+
'permissions' => $node->getPermissions(),
385+
]
386+
);
387+
}
388+
337389
/**
338390
* Redirects to the file list and highlight the given file id
339391
*

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)