Skip to content

Commit

Permalink
Emit sidebar events
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>

Emit sidebar events

Signed-off-by: Louis Chemineau <louis@chmn.me>

Trigger click event when scrollTo is set

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Jun 1, 2021
1 parent 92bf189 commit 9a7aad8
Show file tree
Hide file tree
Showing 30 changed files with 63,916 additions and 40 deletions.
1 change: 1 addition & 0 deletions apps/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
fileActions: fileActions,
allowLegacyActions: true,
scrollTo: urlParams.scrollto,
openFile: urlParams.openfile,
filesClient: OC.Files.getClient(),
multiSelectMenu: [
{
Expand Down
6 changes: 3 additions & 3 deletions apps/files/js/dist/sidebar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files/js/dist/sidebar.js.map

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions apps/files/js/fileactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,19 @@
permissions: OC.PERMISSION_READ,
icon: '',
actionHandler: function (filename, context) {
var dir = context.$file.attr('data-path') || context.fileList.getCurrentDirectory();
let dir, id
if (context.$file) {
dir = context.$file.attr('data-path')
id = context.$file.attr('data-id')
} else{
dir = context.fileList.getCurrentDirectory()
id = context.objectId
}
if (OCA.Files.App && OCA.Files.App.getActiveView() !== 'files') {
OCA.Files.App.setActiveView('files', {silent: true});
OCA.Files.App.fileList.changeDirectory(OC.joinPaths(dir, filename), true, true);
} else {
context.fileList.changeDirectory(OC.joinPaths(dir, filename), true, false, parseInt(context.$file.attr('data-id'), 10));
context.fileList.changeDirectory(OC.joinPaths(dir, filename), true, false, parseInt(id, 10));
}
},
displayName: t('files', 'Open')
Expand Down
51 changes: 26 additions & 25 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,32 @@
});
}

if(options.openFile) {
// Wait for some initialisation process to be over before triggering the default action.
_.defer(() => {
try {
const fileInfo = JSON.parse(atob($('#initial-state-files-openFileInfo').val()))
var spec = this.fileActions.getDefaultFileAction(fileInfo.mime, fileInfo.type, fileInfo.permissions)
if (spec && spec.action) {
spec.action(fileInfo.name, {
objectId: fileInfo.id,
fileList: this,
fileActions: this.fileActions,
dir: fileInfo.directory
});
}
else {
var url = this.getDownloadUrl(fileInfo.name, fileInfo.dir, true);
OCA.Files.Files.handleDownload(url);
}

OCA.Files.Sidebar.open(fileInfo.path);
} catch (error) {
console.error(`Failed to trigger default action on the file for URL: ${location.href}`, error)
}
})
}

this._operationProgressBar = new OCA.Files.OperationProgressBar();
this._operationProgressBar.render();
this.$el.find('#uploadprogresswrapper').replaceWith(this._operationProgressBar.$el);
Expand Down Expand Up @@ -1320,31 +1346,6 @@
}, 0);
}

if(!this.triedActionOnce) {
var id = OC.Util.History.parseUrlQuery().openfile;
if (id) {
var $tr = this.$fileList.children().filterAttr('data-id', '' + id);
var filename = $tr.attr('data-file');
this.fileActions.currentFile = $tr.find('td');
var dir = $tr.attr('data-path') || this.getCurrentDirectory();
var spec = this.fileActions.getCurrentDefaultFileAction();
if (spec && spec.action) {
spec.action(filename, {
$file: $tr,
fileList: this,
fileActions: this.fileActions,
dir: dir
});

}
else {
var url = this.getDownloadUrl(filename, dir, true);
OCA.Files.Files.handleDownload(url);
}
}
this.triedActionOnce = true;
}

return newTrs;
},

Expand Down
37 changes: 35 additions & 2 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Share\IManager;
use OC\Files\View;

/**
* Class ViewController
Expand Down Expand Up @@ -89,6 +90,8 @@ class ViewController extends Controller {
private $templateManager;
/** @var IManager */
private $shareManager;
/** @var View */
protected $fileView;

public function __construct(string $appName,
IRequest $request,
Expand All @@ -102,7 +105,8 @@ public function __construct(string $appName,
Helper $activityHelper,
IInitialState $initialState,
ITemplateManager $templateManager,
IManager $shareManager
IManager $shareManager,
View $view
) {
parent::__construct($appName, $request);
$this->appName = $appName;
Expand All @@ -118,6 +122,7 @@ public function __construct(string $appName,
$this->initialState = $initialState;
$this->templateManager = $templateManager;
$this->shareManager = $shareManager;
$this->fileView = $view;
}

/**
Expand Down Expand Up @@ -181,7 +186,7 @@ public function showFile(string $fileid = null): Response {
* @return TemplateResponse|RedirectResponse
* @throws NotFoundException
*/
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) {
if ($fileid !== null) {
try {
return $this->redirectToFile($fileid);
Expand Down Expand Up @@ -330,6 +335,34 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$policy->addAllowedFrameDomain('\'self\'');
$response->setContentSecurityPolicy($policy);

$user = $this->userSession->getUser();
if ($openfile !== null && $user != null) {
$uid = $user->getUID();
$userFolder = $this->rootFolder->getUserFolder($uid);
$node = $userFolder->getById($openfile)[0];

// properly format full path and make sure
// we're relative to the user home folder
$isRoot = $node === $userFolder;
$path = $userFolder->getRelativePath($node->getPath());
$directory = $userFolder->getRelativePath($node->getParent()->getPath());

// Prevent opening a file from another folder.
if ($dir === $directory) {
$this->initialState->provideInitialState(
'openFileInfo', [
'id' => $node->getId(),
'name' => $isRoot ? '' : $node->getName(),
'path' => $path,
'directory' => $directory,
'mime' => $node->getMimetype(),
'type' => $node->getType(),
'permissions' => $node->getPermissions(),
]
);
}
}

return $response;
}

Expand Down
1 change: 1 addition & 0 deletions apps/files/lib/Search/FilesSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
[
'dir' => dirname($path),
'scrollto' => $result->getName(),
'openfile' => $result->getId(),
]
);

Expand Down
1 change: 1 addition & 0 deletions apps/files/src/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ window.addEventListener('DOMContentLoaded', function() {
AppSidebar.$mount('#app-sidebar')
window.OCA.Files.Sidebar.open = AppSidebar.open
window.OCA.Files.Sidebar.close = AppSidebar.close
window.OCA.Files.Sidebar.setFullScreenMode = AppSidebar.setFullScreenMode
})
21 changes: 20 additions & 1 deletion apps/files/src/views/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export default {
loading: true,
fileInfo: null,
starLoading: false,
isFullScreen: false,
}
},
Expand Down Expand Up @@ -206,7 +207,10 @@ export default {
'star-loading': this.starLoading,
active: this.activeTab,
background: this.background,
class: { 'has-preview': this.fileInfo.hasPreview },
class: {
'has-preview': this.fileInfo.hasPreview,
'app-sidebar--full': this.isFullScreen,
},
compact: !this.fileInfo.hasPreview,
loading: this.loading,
starred: this.fileInfo.isFavourited,
Expand Down Expand Up @@ -432,6 +436,14 @@ export default {
this.resetData()
},
/**
* Allow to set the Sidebar as fullscreen from OCA.Files.Sidebar
* @param {boolean} isFullScreen - Wether or not to render the Sidebar in fullscreen.
*/
setFullScreenMode(isFullScreen) {
this.isFullScreen = isFullScreen
},
/**
* Emit SideBar events.
*/
Expand Down Expand Up @@ -464,5 +476,12 @@ export default {
}
}
}
&--full {
position: fixed !important;
z-index: 2025 !important;
top: 0 !important;
height: 100% !important;
}
}
</style>
2 changes: 2 additions & 0 deletions apps/settings/js/vue-settings-apps-386d0abb9a2fd20f7b19.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 9a7aad8

Please sign in to comment.