Repository navigation
Closed
Milestone
Description
In order to fulfil the following requirements:
- undoable file actions: Make undo deletion work again #119 Notification and undo for moving files/folders #7058
- retriable file actions in case of conflict: Feature Request: File conflict dialog opens on drag and drop #24885
- ability for any file view to execute actions without having a FileList available (ex: gallery integration in file list, etc).
We need to move the file actions to a more abstract level, decoupled from the file lists.
The idea is to use the command pattern.
Defining a file action, based on the existing FileActions, for example favoriting a file:
fileActions.registerAction({
name: 'Favorite',
displayName: t('files', 'Favorite'),
mime: 'all',
permissions: OC.PERMISSION_READ,
type: OCA.Files.FileActions.TYPE_INLINE,
render: function(actionSpec, isDefault, context) { ... },
actionHandler: function(fileName, context) {
// this is new: return a FileActionCommand instance
return new FavoriteFileActionCommand(context);
});Very crude example, most of the code should be moved to a FileActionCommand base class:
FavoriteFileActionCommand = function(context) { ... };
FavoriteFileActionCommand.prototype = {
context: context,
// promise
state: null,
// previous state, for undo
_previousFavoriteState: null,
// performs the action, returns a promise
execute: function() {
if (this._hasRun) {
throw "Command already ran";
}
this._hasRun = false;
// code to execute the action based on the context which contains arguments
return this.state = $.ajax({
...
data: {favorite: !context.isFavorite},
...
});
},
revert: function() {
if (this._hasRun) {
throw "Cannot revert action that was not run yet";
}
// executes the opposite
this._hasRun = false;
return this.state = $.ajax({
...
data: {favorite: this._previousFavoriteState},
...
});
}
}Because of the use of promises, it would also be possible to defer execution to later and show an undo notification first, and run the action a few seconds later. This logic could potentially be added into the base class as well FileActionCommand.
- Whenever a piece of code from the files app or a files app plugin (ex: sidebar tab) wants to perform a file action:
context = {
fileName: '/somedir/somefile.txt'
};
var action = this.fileActions.getFileActionCommand(context);
// add to the action runner
FileActionsCommandRunner.add(action);- The file action command runner would be a globally accessible (or restricted scope ?) class in which the actions to execute must be added. They will then be executed in order.
- In case of bulk actions, for example when deleting multiple files at once, a composite action
FileActionCompositeCommandis created with a list of individualFileActionCommandcommands to execute in bulk. This means that undoing a composite command would undo all of the sub-commands. - If a single action failed, for example moving a single file within a bulk command failed because of file name conflict, we need a mechanism to pop up the conflict dialog in a way that will make it reset and rerun the command with a resolution parameter (or modified context like target file name).
Open questions:
- do we really need that level of complexity with "revert()" or would an undo notification + delayed action would be enough ? delayed action would remove the need for composite commands
- how to deal with "move + conflict dialog", should it be implemented inside the action or should the command runner be able to trigger such dialog.
Activity
DeepDiver1975 commentedon Oct 7, 2016
from my understanding notification and delay should be enough
DeepDiver1975 commentedon Oct 7, 2016
I'd do that within the action - or would that be tooo complex?
PVince81 commentedon Oct 7, 2016
Within the action is probably the simplest way, especially considering that the action itself knows better in which way it needs to resolve itself (like rename target file) after conflict resolution choice. So far can't think of any better way.
ownclouders commentedon Dec 21, 2017
Hey, this issue has been closed because the label
status/STALEis set and there were no updates for 7 days. Feel free to reopen this issue if you deem it appropriate.(This is an automated comment from GitMate.io.