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:
- The progress panel is displayed, and progress gets updated based on the completion of individual node processing.
- 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 thecommandContainer
, then the progress panel will remain visible after all processing is complete. User can expand it to see individual item status. - 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 :
d2/sdk/commands/progressive.nodes.command
- instance
- .preProcess(status, options) ⇒
PromiseReturnType
- .doAction(node, options) ⇒
PromiseReturnType
- .handleResults(results, options) ⇒
PromiseReturnType
- .getMessageOptions(options) ⇒
MessageOptionsType
- .preProcess(status, options) ⇒
- static
- .extend(protoProperties, staticProperties) ⇒
function
- .extend(protoProperties, staticProperties) ⇒
- inner
- ~DoneCommandOption :
Object
- ~CommandStatus :
Object
- ~PromiseReturnType :
jQuery.Promise
- ~MessageOptionsType :
Object
- ~DoneCommandOption :
- instance
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
Param | Type | Description |
---|---|---|
status | CommandStatus | Object hash containing the contextual data |
options | object | 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
Param | Type | Description |
---|---|---|
node | NodeModel | The curent NodeModel being processed |
options | object | Combined |
progressiveNodesCommand.handleResults(results, options) ⇒ PromiseReturnType
Apply post processing
Kind: instance abstract method of ProgressiveNodesCommand
Param | Type | Description |
---|---|---|
results | Array.<object> | Elements of the argument correspond to each input node. The element is of type |
options | object | Combined |
progressiveNodesCommand.getMessageOptions(options) ⇒ MessageOptionsType
Customize different messages shown in the progress panel UI.
Kind: instance abstract method of ProgressiveNodesCommand
Param | Type | Description |
---|---|---|
options | object | Combined |
ProgressiveNodesCommand.extend(protoProperties, staticProperties) ⇒ function
To define a derived type from ProgressiveNodesCommand
.
Kind: static method of ProgressiveNodesCommand
Returns: function
- The derived type.
Param | Type | Description |
---|---|---|
protoProperties | object | Properties attached to the prototype of derived type. |
protoProperties.constructor | function | The function to be used to construct instance of the derived type. |
staticProperties | object | Properties statically attached to the derived type. |
ProgressiveNodesCommand~DoneCommandOption : Object
Kind: inner typedef of ProgressiveNodesCommand
Properties
Name | Type | Description |
---|---|---|
signature | string | Signature of command to execute on click |
label | string | Label to be shown for the link. |
tooltip | string | Tooltip for the link. |
ProgressiveNodesCommand~CommandStatus : Object
Type of data passed as first argument for any command execution.
Kind: inner typedef of ProgressiveNodesCommand
Properties
Name | Type | Default | Description |
---|---|---|---|
[hideSuccessMessage] | boolean | false | Setting it to |
[hideFailureMessage] | boolean | false | Setting it to |
[suppressProgress] | boolean | false | Setting it to |
[doneCommand] | DoneCommandOption | To show additional link on the success toast message upon command completion. | |
[commandContainer] | NodeModel | This must be provided if | |
nodes | NodeCollection | 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
Name | Type | Description |
---|---|---|
oneFilePending | string | Message to be shown for |
actionType | string | To group several executions of the same command into a single progress panel UI whereever applicable. It is a future scoped option. |