adding action.filename to FileActions

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/29101/head
Maxence Lange 2021-10-08 08:27:33 +07:00
parent 9187e986e1
commit 9e78b01f3a
4 changed files with 39 additions and 16 deletions

@ -142,6 +142,7 @@
name: name, name: name,
displayName: action.displayName, displayName: action.displayName,
mime: mime, mime: mime,
filename: action.filename,
order: action.order || 0, order: action.order || 0,
icon: action.icon, icon: action.icon,
iconClass: action.iconClass, iconClass: action.iconClass,
@ -191,11 +192,12 @@
* @param {string} mime mime type * @param {string} mime mime type
* @param {string} type "dir" or "file" * @param {string} type "dir" or "file"
* @param {int} permissions permissions * @param {int} permissions permissions
* @param {string} filename filename
* *
* @return {Object.<string,OCA.Files.FileActions~actionHandler>} map of action name to action spec * @return {Object.<string,OCA.Files.FileActions~actionHandler>} map of action name to action spec
*/ */
get: function (mime, type, permissions) { get: function(mime, type, permissions, filename) {
var actions = this.getActions(mime, type, permissions); var actions = this.getActions(mime, type, permissions, filename);
var filteredActions = {}; var filteredActions = {};
$.each(actions, function (name, action) { $.each(actions, function (name, action) {
filteredActions[name] = action.action; filteredActions[name] = action.action;
@ -209,10 +211,11 @@
* @param {string} mime mime type * @param {string} mime mime type
* @param {string} type "dir" or "file" * @param {string} type "dir" or "file"
* @param {int} permissions permissions * @param {int} permissions permissions
* @param {string} filename filename
* *
* @return {Array.<OCA.Files.FileAction>} array of action specs * @return {Array.<OCA.Files.FileAction>} array of action specs
*/ */
getActions: function (mime, type, permissions) { getActions: function(mime, type, permissions, filename) {
var actions = {}; var actions = {};
if (this.actions.all) { if (this.actions.all) {
actions = $.extend(actions, this.actions.all); actions = $.extend(actions, this.actions.all);
@ -231,15 +234,29 @@
actions = $.extend(actions, this.actions[mime]); actions = $.extend(actions, this.actions[mime]);
} }
} }
var filteredActions = {}; var filteredActions = {};
$.each(actions, function (name, action) { var self = this;
if ((action.permissions === OC.PERMISSION_NONE) || (action.permissions & permissions)) { $.each(actions, function(name, action) {
if (self.allowedPermissions(action.permissions, permissions) &&
self.allowedFilename(action.filename, filename)) {
filteredActions[name] = action; filteredActions[name] = action;
} }
}); });
return filteredActions; return filteredActions;
}, },
allowedPermissions: function(actionPermissions, permissions) {
return (actionPermissions === OC.PERMISSION_NONE || (actionPermissions & permissions));
},
allowedFilename: function(actionFilename, filename) {
return (!filename || filename === '' || !actionFilename
|| actionFilename === '' || actionFilename === filename);
},
/** /**
* Returns the default file action handler for the given conditions * Returns the default file action handler for the given conditions
* *
@ -470,7 +487,8 @@
var actions = this.get( var actions = this.get(
fileInfoModel.get('mimetype'), fileInfoModel.get('mimetype'),
fileInfoModel.isDirectory() ? 'dir' : 'file', fileInfoModel.isDirectory() ? 'dir' : 'file',
fileInfoModel.get('permissions') fileInfoModel.get('permissions'),
fileInfoModel.get('name')
); );
if (actionName) { if (actionName) {
@ -528,7 +546,8 @@
var actions = this.getActions( var actions = this.getActions(
this.getCurrentMimeType(), this.getCurrentMimeType(),
this.getCurrentType(), this.getCurrentType(),
this.getCurrentPermissions() this.getCurrentPermissions(),
this.getCurrentFile()
); );
var nameLinks; var nameLinks;
if ($tr.data('renaming')) { if ($tr.data('renaming')) {
@ -673,11 +692,11 @@
if (type === OC.dialogs.FILEPICKER_TYPE_COPY) { if (type === OC.dialogs.FILEPICKER_TYPE_COPY) {
context.fileList.copy(filename, targetPath, false, context.dir); context.fileList.copy(filename, targetPath, false, context.dir);
} }
if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) { if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) {
context.fileList.move(filename, targetPath, false, context.dir); context.fileList.move(filename, targetPath, false, context.dir);
} }
context.fileList.dirInfo.dirLastCopiedTo = targetPath; context.fileList.dirInfo.dirLastCopiedTo = targetPath;
}, false, "httpd/unix-directory", true, actions, dialogDir); }, false, "httpd/unix-directory", true, actions, dialogDir);
} }
}); });
@ -777,6 +796,7 @@
* display name string for the action, or function that returns the display name. * display name string for the action, or function that returns the display name.
* Defaults to the name given in name property * Defaults to the name given in name property
* @property {String} mime mime type * @property {String} mime mime type
* @property {String} filename filename
* @property {int} permissions permissions * @property {int} permissions permissions
* @property {(Function|String)} icon icon path to the icon or function that returns it (deprecated, use iconClass instead) * @property {(Function|String)} icon icon path to the icon or function that returns it (deprecated, use iconClass instead)
* @property {(String|OCA.Files.FileActions~iconClassFunction)} iconClass class name of the icon (recommended for theming) * @property {(String|OCA.Files.FileActions~iconClassFunction)} iconClass class name of the icon (recommended for theming)

@ -49,7 +49,8 @@
var actions = fileActions.getActions( var actions = fileActions.getActions(
fileActions.getCurrentMimeType(), fileActions.getCurrentMimeType(),
fileActions.getCurrentType(), fileActions.getCurrentType(),
fileActions.getCurrentPermissions() fileActions.getCurrentPermissions(),
fileActions.getCurrentFile()
); );
var actionSpec = actions[actionName]; var actionSpec = actions[actionName];
var fileName = this._context.$file.attr('data-file'); var fileName = this._context.$file.attr('data-file');
@ -74,7 +75,8 @@
var actions = fileActions.getActions( var actions = fileActions.getActions(
fileActions.getCurrentMimeType(), fileActions.getCurrentMimeType(),
fileActions.getCurrentType(), fileActions.getCurrentType(),
fileActions.getCurrentPermissions() fileActions.getCurrentPermissions(),
fileActions.getCurrentFile()
); );
var defaultAction = fileActions.getCurrentDefaultFileAction(); var defaultAction = fileActions.getCurrentDefaultFileAction();

@ -945,7 +945,7 @@
var mime = this.fileActions.getCurrentMimeType(); var mime = this.fileActions.getCurrentMimeType();
var type = this.fileActions.getCurrentType(); var type = this.fileActions.getCurrentType();
var permissions = this.fileActions.getCurrentPermissions(); var permissions = this.fileActions.getCurrentPermissions();
var action = this.fileActions.get(mime, type, permissions)['Details']; var action = this.fileActions.get(mime, type, permissions, filename)['Details'];
if (action) { if (action) {
action(filename, { action(filename, {
$file: $tr, $file: $tr,

@ -154,7 +154,8 @@
var availableActions = this._fileActions.get( var availableActions = this._fileActions.get(
this.model.get('mimetype'), this.model.get('mimetype'),
this.model.get('type'), this.model.get('type'),
this.model.get('permissions') this.model.get('permissions'),
this.model.get('name')
); );
var hasFavoriteAction = 'Favorite' in availableActions; var hasFavoriteAction = 'Favorite' in availableActions;
this.$el.html(this.template({ this.$el.html(this.template({