Skip to main content

progressive.nodes.command

ProgressiveNodesCommand : d2/sdk/commands/progressive.nodes.command

Interface for classes that implements business actions over one or more NodeModel such that progress of the action is collectively portrayed on a UI component called ProgressPanel.

Normal behavior flow is as follows:

  1. The progress panel is displayed, and progress gets updated based on the completion of individual node processing.
  2. In case the processing for any node fails, or if user aborts the processing (either using Stop button for all pending items, or using Cancel icon against each item), or if doneCommand options are enabled and there are multiple nodes and at least one node is not within the commandContainer, then the progress panel will remain visible after all processing is complete. User can expand it to see individual item status.
  3. In case the processing is successful, then progress panel is removed, and toast message is displayed with success details. If it was a single node and doneCommand was applicable, then the toast message will also include done command link.

An implementation should be registered with the command collection.

Extends: CommandModel
Example (A sample implementation delete.js could look like)

define([
'nuc/lib/jquery',
'd2/sdk/commands/progressive.nodes.command',
'i18n!mybundle/commands/commands.lang'
], function($, ProgressiveNodesCommand, lang){
var DeleteCommand = ProgressiveNodesCommand.extend({
defaults: {
signature: 'Delete',
command_key: 'Delete',
name: lang.CommandNameDelete,
pageLeavingWarning: lang.DeletePageLeavingWarning,
scope: 'multiple'
},

preProcess: function (status, options) {
options || (options = {});
var me = this,
deferred = $.Deferred();

// Do something...

me._confirmAction(status, options).done(function (deleteOptions) {
options.deleteOptions = deleteOptions;
deferred.resolve();
}).fail(function () {
deferred.reject();
});

return deferred.promise();
},

doAction: function (node, options) {
var deferred = $.Deferred();
node.destroy({
wait: true,
deleteOptions: options.deleteOptions,
container: options.container
}).done(function () {
deferred.resolve(node);
}).fail(deferred.reject);

return deferred.promise();
},

handleResults: function (results, options) {
var sourceCollection = options.originatingView && options.originatingView.collection,
deletedIds = _.compact(_.map(results || [], function (result) {
if (result instanceof Backbone.Model) {
return result.get('id');
}
}));

if (deletedIds.length > 0) {
options.context.trigger('d2:objects:deleted', deletedIds);
}

return sourceCollection.fetch({reload: true});
},

getMessageOptions: function () {
return {
oneFilePending: lang.DeletingOneItem,
multiFilePending: lang.DeletingManyItems,
oneFileSuccess: lang.DeleteOneItemSuccessMessage,
multiFileSuccess: lang.DeleteManyItemsSuccessMessage,
oneFileFailure: lang.DeleteOneItemFailMessage,
multiFileOneFailure: lang.DeleteManyItemsOneFailMessage,
multiFileFailure: lang.DeleteManyItemsFailMessage,
someItemsStopped: lang.DeleteStopped,
actionType: 'DELETE'
};
},

// Other methods...
});
});

Example ( to register the command with command collection, in extension.json )

{
"d2/sdk/utils/commands": {
"extensions": {
"mybundle": {
"mybundle/commands/delete"
}
}
}
}

progressiveNodesCommand.preProcess(status, options) ⇒ PromiseReturnType

Apply a preprocessing logic before starting off the actual business action to any node

Kind: instance abstract method of ProgressiveNodesCommand
See: CommandModel#execute

ParamTypeDescription
statusCommandStatus

Object hash containing the contextual data

optionsobject

Additional options that are not part of contextual data like settings

progressiveNodesCommand.doAction(node, options) ⇒ PromiseReturnType

Execute the business action on a single node from within the status.nodes of preProcess

Kind: instance abstract method of ProgressiveNodesCommand

ParamTypeDescription
nodeNodeModel

The curent NodeModel being processed

optionsobject

Combined status and options from preProcess

progressiveNodesCommand.handleResults(results, options) ⇒ PromiseReturnType

Apply post processing

Kind: instance abstract method of ProgressiveNodesCommand

ParamTypeDescription
resultsArray.<object>

Elements of the argument correspond to each input node. The element is of type NodeModel if the command execution for this node was successful. It is undefined if the command execution was aborted. In case of failure the type depends on whatever type was used to reject() the associated jQuery.Promise from doAction

optionsobject

Combined status and options from preProcess

progressiveNodesCommand.getMessageOptions(options) ⇒ MessageOptionsType

Customize different messages shown in the progress panel UI.

Kind: instance abstract method of ProgressiveNodesCommand

ParamTypeDescription
optionsobject

Combined status and options from preProcess

ProgressiveNodesCommand.extend(protoProperties, staticProperties) ⇒ function

To define a derived type from ProgressiveNodesCommand.

Kind: static method of ProgressiveNodesCommand
Returns: function - The derived type.

ParamTypeDescription
protoPropertiesobject

Properties attached to the prototype of derived type.

protoProperties.constructorfunction

The function to be used to construct instance of the derived type.

staticPropertiesobject

Properties statically attached to the derived type.

ProgressiveNodesCommand~DoneCommandOption : Object

Kind: inner typedef of ProgressiveNodesCommand
Properties

NameTypeDescription
signaturestring

Signature of command to execute on click

labelstring

Label to be shown for the link.

tooltipstring

Tooltip for the link.

ProgressiveNodesCommand~CommandStatus : Object

Type of data passed as first argument for any command execution.

Kind: inner typedef of ProgressiveNodesCommand
Properties

NameTypeDefaultDescription
[hideSuccessMessage]booleanfalse

Setting it to true suppresses display of a success toast when this command execution completes successfully.

[hideFailureMessage]booleanfalse

Setting it to true suppresses display of any error toast even if the command completes with error.

[suppressProgress]booleanfalse

Setting it to true hides the progress panel UI.

[doneCommand]DoneCommandOption

To show additional link on the success toast message upon command completion.

[commandContainer]NodeModel

This must be provided if doneCommand link has to be shown. The link is displayed if given node is not within this container.

nodesNodeCollection

Instance of NodeCollection, on which node object(s) this command is being executed.

[context]Context

Active application context

[toolitem]ToolitemModel

The menu behind this action, if any.

[originatingView]Marionette.View

The associated UI component where this command is being executed.

ProgressiveNodesCommand~PromiseReturnType : jQuery.Promise

Return type. Associated jQuery.Promise instance should be resolve()-ed or reject()-ed to mark either successful completion or failed completion respectively.

Kind: inner typedef of ProgressiveNodesCommand

ProgressiveNodesCommand~MessageOptionsType : Object

Formattable message to be used in progress panel.

Kind: inner typedef of ProgressiveNodesCommand
Properties

NameTypeDescription
oneFilePendingstring

Message to be shown for single scoped command during processing, {0} is substituted with node name.

actionTypestring

To group several executions of the same command into a single progress panel UI whereever applicable. It is a future scoped option.