Skip to content

Commit

Permalink
Use underscore to distinguish internal parameters, separate postchang…
Browse files Browse the repository at this point in the history
…e actions
  • Loading branch information
guerler committed Jan 11, 2017
1 parent 54573f0 commit dadd6ee
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 97 deletions.
63 changes: 9 additions & 54 deletions client/galaxy/scripts/mvc/tool/tool-form-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,13 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
// listen to history panel
if ( options.listen_to_history && parent.Galaxy && parent.Galaxy.currHistoryPanel ) {
this.listenTo( parent.Galaxy.currHistoryPanel.collection, 'change', function() {
this.refresh();
self.trigger( 'change' );
});
}
// destroy dom elements
this.$el.on( 'remove', function() { self.remove() } );
},

/** Listen to history panel changes and update the tool form */
refresh: function() {
var self = this;
self.deferred.reset();
this.deferred.execute( function (process){
self._updateModel( process)
});
},

/** Wait for deferred build processes before removal */
remove: function() {
var self = this;
Expand All @@ -54,7 +45,10 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
title : '<b>' + options.name + '</b> ' + options.description + ' (Galaxy Version ' + options.version + ')',
operations : !this.options.hide_operations && this._operations(),
onchange : function() {
self.refresh();
self.deferred.reset();
self.deferred.execute( function ( process ) {
self.options.postchange( process, self );
});
}
}, this.options);
this.options.customize && this.options.customize( this.options );
Expand All @@ -64,8 +58,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
}
},

/** Builds a new model through api call and recreates the entire form
*/
/** Builds a new model through api call and recreates the entire form */
_buildModel: function(process, options, hide_message) {
var self = this;
this.options.id = options.id;
Expand Down Expand Up @@ -131,43 +124,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
});
},

/** Request a new model for an already created tool form and updates the form inputs
*/
_updateModel: function(process) {
// link this
var self = this;
var model_url = this.options.update_url || Galaxy.root + 'api/tools/' + this.options.id + '/build';
var current_state = {
tool_id : this.options.id,
tool_version : this.options.version,
inputs : $.extend(true, {}, self.data.create())
}
this.wait(true);

// log tool state
Galaxy.emit.debug('tool-form-base::_updateModel()', 'Sending current state.', current_state);

// post job
Utils.request({
type : 'POST',
url : model_url,
data : current_state,
success : function(new_model) {
self.update(new_model['tool_model'] || new_model);
self.options.update && self.options.update(new_model);
self.wait(false);
Galaxy.emit.debug('tool-form-base::_updateModel()', 'Received new model.', new_model);
process.resolve();
},
error : function(response) {
Galaxy.emit.debug('tool-form-base::_updateModel()', 'Refresh request failed.', response);
process.reject();
}
});
},

/** Create tool operation menu
*/
/** Create tool operation menu */
_operations: function() {
var self = this;
var options = this.options;
Expand Down Expand Up @@ -315,8 +272,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
}
},

/** Create footer
*/
/** Create footer */
_footer: function() {
var options = this.options;
var $el = $( '<div/>' ).append( this._templateHelp( options ) );
Expand All @@ -332,8 +288,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
return $el;
},

/** Templates
*/
/** Templates */
_templateHelp: function( options ) {
var $tmpl = $( '<div/>' ).addClass( 'ui-form-help' ).append( options.help );
$tmpl.find( 'a' ).attr( 'target', '_blank' );
Expand Down
27 changes: 26 additions & 1 deletion client/galaxy/scripts/mvc/tool/tool-form-composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ define([ 'utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view'
this.parms = [];
_.each( this.model.get( 'steps' ), function( step, i ) {
Galaxy.emit.debug( 'tool-form-composite::initialize()', i + ' : Preparing workflow step.' );
var icon = WorkflowIcons[step.step_type];
var icon = WorkflowIcons[ step.step_type ];
step = Utils.merge( {
index : i,
name : step.name,
Expand Down Expand Up @@ -261,6 +261,31 @@ define([ 'utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view'
this.deferred.execute( function( promise ) {
self.$steps.addClass( 'ui-steps' );
if ( step.step_type == 'tool' ) {
step.postchange = function( process, form ) {
var self = this;
var current_state = {
tool_id : step.id,
tool_version : step.version,
inputs : $.extend( true, {}, form.data.create() )
}
form.wait( true );
Galaxy.emit.debug( 'tool-form-composite::postchange()', 'Sending current state.', current_state );
Utils.request({
type : 'POST',
url : Galaxy.root + 'api/tools/' + step.id + '/build',
data : current_state,
success : function( data ) {
form.update( data );
form.wait( false );
Galaxy.emit.debug( 'tool-form-composite::postchange()', 'Received new model.', data );
process.resolve();
},
error : function( response ) {
Galaxy.emit.debug( 'tool-form-composite::postchange()', 'Refresh request failed.', response );
process.reject();
}
});
};
form = new ToolFormBase( step );
if ( step.post_job_actions && step.post_job_actions.length ) {
form.portlet.append( $( '<div/>' ).addClass( 'ui-form-element-disabled' )
Expand Down
42 changes: 32 additions & 10 deletions client/galaxy/scripts/mvc/tool/tool-form-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,37 @@ define( [ 'utils/utils', 'mvc/tool/tool-form-base' ],
initial_errors : true,
sustain_version : true,
cls : 'ui-portlet-narrow',
update_url : Galaxy.root + 'api/workflows/build_module',
update : function( data ) {
// This hasn't modified the workflow, just returned
// module information for the tool to update the workflow
// state stored on the client with. User needs to save
// for this to take effect.
self.node.update_field_data( data );
self.form.errors( data && data.tool_model );
}
postchange : function( process, form ) {
var self = this;
var current_state = {
tool_id : form.options.id,
tool_version : form.options.version,
inputs : $.extend( true, {}, form.data.create() ),
label : self.node.label,
annotation : self.node.annotation
}
Galaxy.emit.debug( 'tool-form-workflow::postchange()', 'Sending current state.', current_state );
Utils.request({
type : 'POST',
url : Galaxy.root + 'api/workflows/build_module',
data : current_state,
success : function( data ) {
form.update( data.tool_model );
form.errors( data.tool_model );
// This hasn't modified the workflow, just returned
// module information for the tool to update the workflow
// state stored on the client with. User needs to save
// for this to take effect.
self.node.update_field_data( data );
Galaxy.emit.debug( 'tool-form-workflow::postchange()', 'Received new model.', data );
process.resolve();
},
error : function( response ) {
Galaxy.emit.debug( 'tool-form-workflow::postchange()', 'Refresh request failed.', response );
process.reject();
}
});
},
}));
this.$el.append( this.form.$el );
} else {
Expand All @@ -55,7 +77,7 @@ define( [ 'utils/utils', 'mvc/tool/tool-form-base' ],
var datatypes = options.datatypes;
inputs[ Utils.uid() ] = {
label : 'Annotation / Notes',
name : 'annotation',
name : '__annotation',
type : 'text',
area : true,
help : 'Add an annotation or note for this step. It will be shown with the workflow.',
Expand Down
25 changes: 25 additions & 0 deletions client/galaxy/scripts/mvc/tool/tool-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ define([ 'utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-modal', 'mvc/tool/tool-form
help : 'The previous run of this tool failed and other tools were waiting for it to finish successfully. Use this option to resume those tools using the new output(s) of this tool run.'
}
}
},
postchange : function( process, form ) {
var self = this;
var current_state = {
tool_id : options.id,
tool_version : options.version,
inputs : $.extend(true, {}, form.data.create())
}
form.wait( true );
Galaxy.emit.debug( 'tool-form::ajax()', 'Sending current state.', current_state );
Utils.request({
type : 'POST',
url : Galaxy.root + 'api/tools/' + options.id + '/build',
data : current_state,
success : function( data ) {
form.update( data );
form.wait( false );
Galaxy.emit.debug( 'tool-form::postchange()', 'Received new model.', data );
process.resolve();
},
error : function( response ) {
Galaxy.emit.debug( 'tool-form::postchange()', 'Refresh request failed.', response );
process.reject();
}
});
}
}, options ) );
this.deferred = this.form.deferred;
Expand Down
16 changes: 3 additions & 13 deletions client/galaxy/scripts/mvc/workflow/workflow-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,23 +711,15 @@ define([
name : '__label',
label : 'Label',
value : node.label,
help : 'Add a step label.',
onchange: function( label ) {
node.label = label;
form.trigger( 'change' );
}
help : 'Add a step label.'
});
content.inputs.push({
type : 'text',
name : '__annotation',
label : 'Annotation',
value : node.annotation,
area : true,
help : 'Add an annotation or notes to this step. Annotations are available when a workflow is viewed.',
onchange: function( annotation ) {
node.annotation = annotation;
form.trigger( 'change' );
}
help : 'Add an annotation or notes to this step. Annotations are available when a workflow is viewed.'
});
content.onchange = function() {
Utils.request({
Expand All @@ -736,9 +728,7 @@ define([
data : {
id : node.id,
type : node.type,
inputs : form.data.create(),
label : node.label,
annotation : node.annotation
inputs : form.data.create()
},
success : function( data ) {
node.update_field_data( data );
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/webapps/galaxy/api/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ def build_module( self, trans, payload={} ):
Builds module details including a tool model for the workflow editor.
"""
type = payload.get( 'type' )
inputs = payload.get( 'inputs', {} )
annotation = payload.get( 'annotation', '' )
label = payload.get( 'label', '' )
tool_id = payload.get( 'tool_id' )
content_id = payload.get( 'content_id' )
inputs = payload.get( 'inputs', {} )
annotation = inputs.get( '__annotation', '' )
label = inputs.get( '__label', '' )
if tool_id:
tool_version = payload.get( 'tool_version' )
tool = self._get_tool( tool_id, tool_version=tool_version, user=trans.user )
Expand Down

0 comments on commit dadd6ee

Please sign in to comment.