Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool form section tag #35

Merged
merged 16 commits into from Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions client/galaxy/scripts/mvc/form/form-data.js
Expand Up @@ -96,9 +96,9 @@ return Backbone.Model.extend({
convert(job_input_id, head[input.id + '-section-' + selectedCase]);
}
break;
// handle custom sub sections
// handle sections
case 'section':
convert('', node);
convert(job_input_id, node);
break;
default:
// get field
Expand Down Expand Up @@ -191,6 +191,9 @@ return Backbone.Model.extend({
search (index, node.cases[selectedCase].inputs);
}
break;
case 'section':
search (index, node.inputs);
break;
default:
var input_id = self.map_dict[index];
if (input_id) {
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/form/form-section.js
Expand Up @@ -286,7 +286,7 @@ define(['utils/utils',
});

// show sub section if requested
if (input_def.expand) {
if (input_def.expanded) {
portlet.$header.trigger('click');
}

Expand Down
7 changes: 7 additions & 0 deletions client/galaxy/scripts/mvc/form/form-view.js
Expand Up @@ -200,6 +200,13 @@ define(['utils/utils', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc',
inputs : this.options.inputs
});

// switch to classic tool form mako if the form definition is incompatible
if (this.incompatible) {
this.$el.hide();
$('#tool-form-classic').show();
return;
}

// create portlet
this.portlet = new Portlet.View({
icon : 'fa-wrench',
Expand Down
47 changes: 46 additions & 1 deletion lib/galaxy/tools/__init__.py
Expand Up @@ -40,7 +40,7 @@
DataToolParameter, DataCollectionToolParameter, HiddenToolParameter, LibraryDatasetToolParameter,
SelectToolParameter, ToolParameter, UnvalidatedValue,
IntegerToolParameter, FloatToolParameter)
from galaxy.tools.parameters.grouping import Conditional, ConditionalWhen, Repeat, UploadDataset
from galaxy.tools.parameters.grouping import Conditional, ConditionalWhen, Repeat, Section, UploadDataset
from galaxy.tools.parameters.input_translation import ToolInputTranslator
from galaxy.tools.parameters.output import ToolOutputActionGroup
from galaxy.tools.parameters.validation import LateValidationError
Expand Down Expand Up @@ -972,6 +972,15 @@ def parse_input_elem( self, page_source, enctypes, context=None ):
case.inputs = odict()
group.cases.append( case )
rval[group.name] = group
elif input_type == "section":
group = Section()
group.name = input_source.get( "name" )
group.title = input_source.get( "title" )
group.help = input_source.get( "help", None )
group.expanded = input_source.get_bool( "expanded", False )
page_source = input_source.parse_nested_inputs_source()
group.inputs = self.parse_input_elem( page_source, enctypes, context )
rval[group.name] = group
elif input_type == "upload_dataset":
elem = input_source.elem()
group = UploadDataset()
Expand Down Expand Up @@ -1505,6 +1514,20 @@ def populate_state( self, trans, inputs, state, incoming, history=None, source="
group_state['__current_case__'] = current_case
# Store the value of the test element
group_state[ input.test_param.name ] = value
elif isinstance( input, Section ):
group_state = state[input.name]
group_prefix = "%s|" % ( key )
self.fill_in_new_state( trans, input.inputs, group_state, context, history=history )
group_errors = self.populate_state( trans,
input.inputs,
group_state,
incoming,
history,
source,
prefix=group_prefix,
context=context )
if group_errors:
errors[ input.name ] = group_errors
elif isinstance( input, UploadDataset ):
group_state = state[input.name]
group_errors = []
Expand Down Expand Up @@ -1714,6 +1737,22 @@ def update_state( self, trans, inputs, state, incoming, source='html', prefix=""
group_state['__current_case__'] = current_case
# Store the value of the test element
group_state[ input.test_param.name ] = value
elif isinstance( input, Section ):
group_state = state[input.name]
group_old_errors = old_errors.get( input.name, {} )
group_prefix = "%s|" % ( key )
group_errors = self.update_state( trans,
input.inputs,
group_state,
incoming,
prefix=group_prefix,
context=context,
source=source,
update_only=update_only,
old_errors=group_old_errors,
item_callback=item_callback )
if group_errors:
errors[ input.name ] = group_errors
elif isinstance( input, UploadDataset ):
group_state = state[input.name]
group_errors = []
Expand Down Expand Up @@ -2383,6 +2422,10 @@ def populate_state(trans, inputs, state, errors, incoming, prefix="", context=No
errors[test_param_key] = 'The selected case is unavailable/invalid.'
pass
group_state[input.test_param.name] = value
elif input.type == 'section':
group_state = state[input.name]
group_prefix = "%s|" % ( key )
populate_state(trans, input.inputs, group_state, errors, incoming, prefix=group_prefix, context=context)
else:
default_value = incoming.get(key, state.get(input.name, None))
value, error = check_state(trans, input, default_value, context)
Expand Down Expand Up @@ -2417,6 +2460,8 @@ def iterate(group_inputs, inputs, state_inputs, other_values=None):
if i == group_state.get('__current_case__', None):
current_state = group_state
iterate(tool_dict['cases'][i]['inputs'], input.cases[i].inputs, current_state, other_values)
elif input.type == 'section':
iterate( tool_dict['inputs'], input.inputs, group_state, other_values )
else:
# create input dictionary, try to pass other_values if to_dict function supports it e.g. dynamic options
try:
Expand Down
5 changes: 4 additions & 1 deletion lib/galaxy/tools/evaluation.py
Expand Up @@ -22,7 +22,7 @@
LibraryDatasetToolParameter,
SelectToolParameter,
)
from galaxy.tools.parameters.grouping import Conditional, Repeat
from galaxy.tools.parameters.grouping import Conditional, Repeat, Section
from galaxy.jobs.datasets import dataset_path_rewrites

import logging
Expand Down Expand Up @@ -143,6 +143,9 @@ def do_walk( inputs, input_values ):
values = input_values[ input.name ]
current = values["__current_case__"]
do_walk( input.cases[current].inputs, values )
elif isinstance( input, Section ):
values = input_values[ input.name ]
do_walk( input.inputs, values )
else:
func( input_values, input )

Expand Down
9 changes: 9 additions & 0 deletions lib/galaxy/tools/parameters/__init__.py
Expand Up @@ -33,6 +33,11 @@ def visit_input_values( inputs, input_values, callback, name_prefix="", label_pr
label_prefix = label_prefix
new_name_prefix = name_prefix + input.name + "|"
visit_input_values( input.cases[current].inputs, values, callback, new_name_prefix, label_prefix )
elif isinstance( input, Section ):
values = input_values[ input.name ]
label_prefix = label_prefix
new_name_prefix = name_prefix + input.name + "|"
visit_input_values( input.inputs, values, callback, new_name_prefix, label_prefix )
else:
new_value = callback( input,
input_values[input.name],
Expand Down Expand Up @@ -124,6 +129,10 @@ def params_to_incoming( incoming, inputs, input_values, app, name_prefix="", to_
new_name_prefix = name_prefix + input.name + "|"
incoming[ new_name_prefix + input.test_param.name ] = values[ input.test_param.name ]
params_to_incoming( incoming, input.cases[current].inputs, values, app, new_name_prefix, to_html=to_html )
elif isinstance( input, Section ):
values = input_values[ input.name ]
new_name_prefix = name_prefix + input.name + "|"
params_to_incoming( incoming, input.inputs, values, app, new_name_prefix, to_html=to_html )
else:
value = input_values.get( input.name )
if to_html:
Expand Down
49 changes: 49 additions & 0 deletions lib/galaxy/tools/parameters/grouping.py
Expand Up @@ -129,6 +129,55 @@ def input_to_dict( input ):
repeat_dict[ "inputs" ] = map( input_to_dict, self.inputs.values() )
return repeat_dict

class Section( Group ):

dict_collection_visible_keys = ( 'name', 'type', 'title', 'help', 'expanded')

type = "section"
def __init__( self ):
Group.__init__( self )
self.title = None
self.inputs = None
self.help = None
self.expanded = False
@property
def title_plural( self ):
return inflector.pluralize( self.title )
def label( self ):
return "Section (%s)" % self.title
def value_to_basic( self, value, app ):
rval = {}
for input in self.inputs.itervalues():
rval[ input.name ] = input.value_to_basic( value[input.name], app )
return rval
def value_from_basic( self, value, app, ignore_errors=False ):
rval = {}
try:
for input in self.inputs.itervalues():
if not ignore_errors or input.name in value:
rval[ input.name ] = input.value_from_basic( value[ input.name ], app, ignore_errors )
except Exception, e:
if not ignore_errors:
raise e
return rval
def visit_inputs( self, prefix, value, callback ):
for input in self.inputs.itervalues():
if isinstance( input, ToolParameter ):
callback( prefix, input, value[input.name], parent = value )
else:
input.visit_inputs( prefix, value[input.name], callback )
def get_initial_value( self, trans, context, history=None ):
rval = {}
child_context = ExpressionContext( rval, context )
for child_input in self.inputs.itervalues():
rval[ child_input.name ] = child_input.get_initial_value( trans, child_context, history=history )
return rval
def to_dict( self, trans, view='collection', value_mapper=None ):
section_dict = super( Section, self ).to_dict( trans, view=view, value_mapper=value_mapper )
def input_to_dict( input ):
return input.to_dict( trans, view=view, value_mapper=value_mapper )
section_dict[ "inputs" ] = map( input_to_dict, self.inputs.values() )
return section_dict

class UploadDataset( Group ):
type = "upload_dataset"
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/tools/parameters/wrapped.py
Expand Up @@ -8,6 +8,7 @@
from galaxy.tools.parameters.grouping import (
Repeat,
Conditional,
Section
)
PARAMS_UNWRAPPED = object()

Expand Down Expand Up @@ -44,6 +45,9 @@ def wrap_values( self, inputs, input_values, skip_missing_values=False ):
values = input_values[ input.name ]
current = values[ "__current_case__" ]
self.wrap_values( input.cases[current].inputs, values, skip_missing_values=skip_missing_values )
elif isinstance( input, Section ):
values = input_values[ input.name ]
self.wrap_values( input.inputs, values, skip_missing_values=skip_missing_values )
elif isinstance( input, DataToolParameter ) and input.multiple:
input_values[ input.name ] = \
galaxy.tools.DatasetListWrapper( input_values[ input.name ],
Expand Down
7 changes: 7 additions & 0 deletions lib/galaxy/tools/parser/xml.py
Expand Up @@ -422,6 +422,13 @@ def __expand_input_elems( root_elem, prefix="" ):
__pull_up_params( root_elem, cond_elem )
root_elem.remove( cond_elem )

section_elems = root_elem.findall( 'section' )
for section_elem in section_elems:
new_prefix = __prefix_join( prefix, section_elem.get( "name" ) )
__expand_input_elems( section_elem, new_prefix )
__pull_up_params( root_elem, section_elem )
root_elem.remove( section_elem )


def __append_prefix_to_params( elem, prefix ):
for param_elem in elem.findall( 'param' ):
Expand Down
7 changes: 6 additions & 1 deletion lib/galaxy/tools/test.py
Expand Up @@ -166,7 +166,12 @@ def __process_raw_inputs( self, tool_inputs, raw_inputs, parent_context=None ):
# an infinite loop - hence the "case_value is not None"
# check.
expanded_inputs[ case_context.for_state() ] = expanded_case_value

elif isinstance( value, galaxy.tools.parameters.grouping.Section ):
context = ParamContext( name=value.name, parent_context=parent_context )
for r_name, r_value in value.inputs.iteritems():
expanded_input = self.__process_raw_inputs( { context.for_state(): r_value }, raw_inputs, parent_context=context )
if expanded_input:
expanded_inputs.update( expanded_input )
elif isinstance( value, galaxy.tools.parameters.grouping.Repeat ):
repeat_index = 0
while True:
Expand Down