Skip to content

Commit

Permalink
Merge branch 'revise_visit_000' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed May 16, 2016
2 parents 0c78c27 + 9969330 commit a5f6195
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 71 deletions.
87 changes: 37 additions & 50 deletions client/galaxy/scripts/mvc/form/form-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ define([ 'utils/utils' ], function( Utils ) {
/** Matches a new tool model to the current input elements e.g. used to update dynamic options
*/
matchModel: function( model, callback ) {
return matchIds( model.inputs, this.flat_dict, callback );
var self = this;
visitInputs( model.inputs, function( input, name ) {
self.flat_dict[ name ] && callback ( input, self.flat_dict[ name ] );
});
},

/** Matches identifier from api response to input elements e.g. used to display validation errors
Expand Down Expand Up @@ -191,66 +194,50 @@ define([ 'utils/utils' ], function( Utils ) {
return -1;
};

/** Match context
* @param{dict} inputs - Dictionary of input elements
* @param{dict} key - Reference key which is matched to an input name e.g. data_ref
* @param{dict} callback - Called with matched context i.e. callback( input, referenced_input )
/** Visits tool inputs
* @param{dict} inputs - Nested dictionary of input elements
* @param{dict} callback - Called with the mapped dictionary object and corresponding model node
*/
var matchContext = function( inputs, key, callback, context ) {
var visitInputs = function( inputs, callback, prefix, context ) {
context = $.extend( true, {}, context );
_.each( inputs, function ( input ) {
input && input.type && ( context[ input.name ] = input );
});
_.each( inputs, function ( input ) {
if ( _.isObject( input ) ) {
if ( input.type && context[ input[ key ] ] ) {
callback ( input, context[ input[ key ] ] );
} else {
matchContext( input, key, callback, context );
}
if ( input && input.type && input.name ) {
context[ input.name ] = input;
}
});
};

/** Matches a tool model to a dictionary, indexed with flat ids
* @param{dict} inputs - Dictionary of input elements
* @param{dict} mapping - Dictionary containing flat ids
* @param{dict} callback - Called with the mapped dictionary object and corresponding model node
*/
var matchIds = function( inputs, mapping, callback ) {
var result = {};
var self = this;
function search ( id, head ) {
for ( var i in head ) {
var node = head[ i ];
var index = node.name;
id != '' && ( index = id + '|' + index );
switch ( node.type ) {
case 'repeat':
for ( var j in node.cache ) {
search ( index + '_' + j, node.cache[ j ] );
for ( var i in inputs ) {
var node = inputs[ i ];
var name = prefix ? prefix + '|' + node.name : node.name;
switch ( node.type ) {
case 'repeat':
_.each( node.cache, function( cache, j ) {
visitInputs( cache, callback, name + '_' + j, context );
});
break;
case 'conditional':
if ( node.test_param ) {
callback( node.test_param, name + '|' + node.test_param.name, context );
var selectedCase = matchCase( node, node.test_param.value );
if ( selectedCase != -1 ) {
visitInputs( node.cases[ selectedCase ].inputs, callback, name, context );
} else {
Galaxy.emit.debug( 'form-data::visitInputs() - Invalid case for ' + name + '.' );
}
break;
case 'conditional':
var selectedCase = matchCase( node, node.test_param && node.test_param.value );
selectedCase != -1 && search ( index, node.cases[ selectedCase ].inputs );
break;
case 'section':
search ( index, node.inputs );
break;
default:
var mapped = mapping[ index ];
mapped && callback( mapped, node );
}
} else {
Galaxy.emit.debug( 'form-data::visitInputs() - Conditional test parameter missing for ' + name + '.' );
}
break;
case 'section':
visitInputs( node.inputs, callback, name, context )
break;
default:
callback( node, name, context );
}
}
search( '', inputs );
return result;
};

return {
Manager : Manager,
matchIds : matchIds,
matchContext : matchContext
visitInputs : visitInputs
}
});
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/form/form-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define(['utils/utils', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', 'mvc/form/form-sec
/** Update available options */
update: function(new_model){
var self = this;
this.data.matchModel(new_model, function(input_id, node) {
this.data.matchModel(new_model, function(node, input_id) {
var input = self.input_list[input_id];
if (input && input.options) {
if (!_.isEqual(input.options, node.options)) {
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/tool/tool-form-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
large : true
})).$el);
} else {
Galaxy.modal.show({
Galaxy.modal && Galaxy.modal.show({
title : 'Tool request failed',
body : error_message,
buttons : {
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/form/form-data.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a5f6195

Please sign in to comment.