diff --git a/client/galaxy/scripts/mvc/tools/tools-content.js b/client/galaxy/scripts/mvc/tools/tools-content.js index bab819e2587..c8ccb52fb33 100644 --- a/client/galaxy/scripts/mvc/tools/tools-content.js +++ b/client/galaxy/scripts/mvc/tools/tools-content.js @@ -1,96 +1,23 @@ define(['utils/utils'], function(Utils){ return Backbone.Model.extend({ // initialize - initialize: function(options) { - // backup basic url - this.base_url = galaxy_config.root + 'api/histories/' + options.history_id + '/contents'; - - // prepare content obects - this.datatypes = {}; + initialize: function(app) { this.summary = {}; - - // link this - var self = this; - - // request datatypes - Utils.get({ - url : galaxy_config.root + 'api/datatypes/mapping', - cache : true, - success : function(response) { - // backup datatype dictionary - self.datatypes = response; - - // get history summary - Utils.get({ - url : self.base_url + '?deleted=false', - success : function(response) { - // backup summary - self.summary = response; - - // sort by id - self.summary.sort(function(a, b) { - return a.hid > b.hid ? -1 : (a.hid < b.hid ? 1 : 0); - }); - - // log - console.debug('tools-content::initialize() - Completed.'); - - // callback - options.success && options.success(); - }, - error : function(response) { - // log request failure - console.debug('tools-content::initialize() - Ajax request for summary failed.'); - console.debug(response); - } - }); - }, - error : function(response) { - // log request failure - console.debug('tools-content::initialize() - Ajax request for datatypes failed.'); - console.debug(response); - } - }); }, - /** - * Filters contents by data type. + /** Add new content elements */ - filterType: function(options) { - // initialize parameters - options = options || {}; - var result = []; - - // identify content type - var history_content_type = 'dataset'; - if (options.src== 'hdca') { - history_content_type = 'dataset_collection'; - } - - // search in summary - for (var i in this.summary) { - var content = this.summary[i]; - - // check ok state (TODO: should be implemented in the api) - if (content.history_content_type === 'dataset' && content.state !== 'ok') { - continue; - } - - // match datatypes - var found = false; - for (var i in options.extensions) { - if (this._matchType(options.extensions[i], content.extension)) { - found = true; - break; - } - } - - // final match result - if ((content.history_content_type === history_content_type) && (found || !options.extensions)) { - result.push(content); + add: function(content_list) { + // add/update content in summary list + for (var i in content_list) { + for (var j in content_list[i]) { + var c = content_list[i][j]; + this.summary[c.id + '_' + c.src] = c; } } - return result; + + // log + console.debug('tools-content::initialize() - Completed.'); }, /** Returns matched content from summary. @@ -126,33 +53,6 @@ define(['utils/utils'], function(Utils){ console.debug(response); } }); - }, - - /** Check if datatypes match - */ - _matchType: function(target, reference) { - // check if target class is available - var target_class = this.datatypes.ext_to_class_name[target]; - if (!target_class) { - console.debug('tools-content::_matchType() - Specific target class unavailable. Accepting all formats.'); - return true; - } - - // check if reference class is available - var reference_class = this.datatypes.ext_to_class_name[reference]; - if (!reference_class) { - console.debug('tools-content::_matchType() - Specific reference class unavailable. Accepting all formats.'); - return true; - } - - // check reference group - var reference_group = this.datatypes.class_to_classes[reference_class]; - if (reference_group[target_class]) { - return true; - } - - // classes do not match - return false; } }); }); \ No newline at end of file diff --git a/client/galaxy/scripts/mvc/tools/tools-form.js b/client/galaxy/scripts/mvc/tools/tools-form.js index b3c5b594bfb..12480b35339 100644 --- a/client/galaxy/scripts/mvc/tools/tools-form.js +++ b/client/galaxy/scripts/mvc/tools/tools-form.js @@ -21,11 +21,19 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', var self = this; // link galaxy modal or create one - if (parent.Galaxy && parent.Galaxy.modal) { - this.modal = parent.Galaxy.modal; + var galaxy = parent.Galaxy; + if (galaxy && galaxy.modal) { + this.modal = galaxy.modal; } else { this.modal = new Ui.Modal.View(); } + + // check if the user is an admin + if (galaxy && galaxy.currUser) { + this.is_admin = galaxy.currUser.get('is_admin') + } else { + this.is_admin = false; + } // link options this.options = options; @@ -47,12 +55,10 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', this.job_handler = new ToolJobs(this); // request history content and build form - this.content = new ToolContent({ - history_id : self.options.history_id, - success : function() { - self._buildForm(self.options); - } - }); + this.content = new ToolContent(this); + + // build this form + this._buildForm(options); }, // message @@ -72,7 +78,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', // this happens i.e. when repeat blocks are added or removed and on initialization rebuild: function() { this.tree.refresh(); - console.debug('tools-form::refresh() - Refreshed form structure.'); + console.debug('tools-form::rebuild() - Rebuilding data structures.'); }, // refreshes input states i.e. for dynamic parameters @@ -142,7 +148,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', var current_state = this.tree.finalize({ data : function(dict) { if (dict.values.length > 0 && dict.values[0] && dict.values[0].src === 'hda') { - return self.content.get({id: dict.values[0].id}).dataset_id; + return self.content.get({id: dict.values[0].id, src: 'hda'}).dataset_id; } return null; } @@ -215,16 +221,22 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', // get/update field var field = self.field_list[input_id]; - if (field.update && input.type != 'data') { + if (field.update) { var new_options = []; - for (var i in node.options) { - var opt = node.options[i]; - if (opt.length > 2) { - new_options.push({ - 'label': opt[0], - 'value': opt[1] - }); - } + switch (input.type) { + case 'data': + new_options = input.options; + break; + default: + for (var i in node.options) { + var opt = node.options[i]; + if (opt.length > 2) { + new_options.push({ + 'label': opt[0], + 'value': opt[1] + }); + } + } } field.update(new_options); console.debug('Updating options for ' + input_id); @@ -292,7 +304,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', }); // add admin operations - if (Galaxy.currUser.get('is_admin')) { + if (this.is_admin) { // create download button menu.addMenu({ icon : 'fa-download', diff --git a/client/galaxy/scripts/mvc/tools/tools-jobs.js b/client/galaxy/scripts/mvc/tools/tools-jobs.js index 8ffdb037f81..fe1f157bfd3 100644 --- a/client/galaxy/scripts/mvc/tools/tools-jobs.js +++ b/client/galaxy/scripts/mvc/tools/tools-jobs.js @@ -142,8 +142,8 @@ return Backbone.Model.extend({ if (batch_n === -1) { batch_n = n; } else { - if (batch_n !== n && n != 1) { - this._foundError(input_id, 'Please make sure that you select a single input or the same number of inputs for all batch mode fields. This field contains ' + n + ' selection(s) while a previous field contains ' + batch_n + '.'); + if (batch_n !== n) { + this._foundError(input_id, 'Please make sure that you select the same number of inputs for all batch mode fields. This field contains ' + n + ' selection(s) while a previous field contains ' + batch_n + '.'); return false; } } diff --git a/client/galaxy/scripts/mvc/tools/tools-section.js b/client/galaxy/scripts/mvc/tools/tools-section.js index cb78711b619..53930af608c 100644 --- a/client/galaxy/scripts/mvc/tools/tools-section.js +++ b/client/galaxy/scripts/mvc/tools/tools-section.js @@ -372,6 +372,7 @@ define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/tools/tools-rep id : 'field-' + input_def.id, extensions : input_def.extensions, multiple : input_def.multiple, + data : input_def.options, onchange : function() { self.app.refresh(); } diff --git a/client/galaxy/scripts/mvc/tools/tools-select-content.js b/client/galaxy/scripts/mvc/tools/tools-select-content.js index 1803ac8ec72..c1ae64c93a4 100644 --- a/client/galaxy/scripts/mvc/tools/tools-select-content.js +++ b/client/galaxy/scripts/mvc/tools/tools-select-content.js @@ -4,7 +4,8 @@ define(['utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs', 'mvc/tools/tools-temp var View = Backbone.View.extend({ // initialize initialize : function(app, options) { - // configure options + // link app and options + this.app = app; this.options = options; // link this @@ -14,13 +15,14 @@ var View = Backbone.View.extend({ this.setElement('
'); // current selection - this.current = 'hda'; + this.current = 'single'; // create button - this.button_new = new Ui.RadioButton.View({ + this.button_type = new Ui.RadioButton.View({ value : this.current, - data : [ { icon: 'fa-file-o', label : 'Select datasets', value : 'hda' }, - { icon: 'fa-files-o', label : 'Select a collection', value : 'hdca' }], + data : [ { icon: 'fa-file-o', label : 'Single dataset', value : 'single' }, + { icon: 'fa-files-o', label : 'Multiple datasets', value : 'multiple' }, + { icon: 'fa-folder-o', label : 'List of datasets', value : 'collection' }], onchange: function(value) { self.current = value; self.refresh(); @@ -28,68 +30,56 @@ var View = Backbone.View.extend({ } }); - // - // datasets - // - var datasets = app.content.filterType({ - src : 'hda', - extensions : options.extensions + // single dataset select field + this.select_single = new Ui.Select.View({ + onchange : function() { + self.trigger('change'); + } }); - - // configure options fields - var dataset_options = []; - for (var i in datasets) { - dataset_options.push({ - label: datasets[i].hid + ': ' + datasets[i].name, - value: datasets[i].id - }); - } - // select field - this.select_datasets = new Ui.Select.View({ + // multiple datasets select field + this.select_multiple = new Ui.Select.View({ multiple : true, - data : dataset_options, - value : dataset_options[0] && dataset_options[0].value, onchange : function() { self.trigger('change'); } }); - // - // collections - // - var collections = app.content.filterType({ - src : 'hdca', - extensions : options.extensions - }); - - // configure options fields - var collection_options = []; - for (var i in collections) { - collection_options.push({ - label: collections[i].hid + ': ' + collections[i].name, - value: collections[i].id - }); - } - - // create select field for collections + // collection select field this.select_collection = new Ui.Select.View({ - data : collection_options, - value : collection_options[0] && collection_options[0].value, onchange : function() { self.trigger('change'); } }); + // list of all select fields + this.list = { + 'single' : { + field: this.select_single, + type : 'hda' + }, + 'multiple' : { + field: this.select_multiple, + type : 'hda' + }, + 'collection' : { + field: this.select_collection, + type : 'hdca' + } + }; + + // add batch mode information + this.$batch = $(ToolTemplate.batchMode()); + // add elements to dom - this.$el.append(Utils.wrap(this.button_new.$el)); - this.$el.append(this.select_datasets.$el); - this.$el.append(this.select_collection.$el); - - // check for batch mode - if (!this.options.multiple) { - this.$el.append(ToolTemplate.batchMode()); + this.$el.append(Utils.wrap(this.button_type.$el)); + for (var i in this.list) { + this.$el.append(this.list[i].field.$el); } + this.$el.append(this.$batch); + + // update options + this.update(options.data); // refresh view this.refresh(); @@ -102,31 +92,77 @@ var View = Backbone.View.extend({ }); }, + /** Indicate that select fields are being updated */ + wait: function() { + for (var i in this.list) { + this.list[i].field.wait(); + } + }, + + /** Indicate that the options update has been completed */ + unwait: function() { + for (var i in this.list) { + this.list[i].field.unwait(); + } + }, + + /** Update content selector */ + update: function(options) { + // identify dataset options + var dataset_options = []; + for (var i in options.hda) { + var hda = options.hda[i]; + dataset_options.push({ + label: hda.hid + ': ' + hda.name, + value: hda.id + }); + } + + // identify collection options + var collection_options = []; + for (var i in options.hdca) { + var hdca = options.hdca[i]; + collection_options.push({ + label: hdca.hid + ': ' + hdca.name, + value: hdca.id + }); + } + + // update selection fields + this.select_single.update(dataset_options); + this.select_multiple.update(dataset_options); + this.select_collection.update(collection_options); + + // add to content list + this.app.content.add(options); + }, + /** Return the currently selected dataset values */ value : function (dict) { // update current value if (dict !== undefined) { try { - // set source - this.current = dict.values[0].src; - this.refresh(); - // create list var list = []; for (var i in dict.values) { list.push(dict.values[i].id); } - // identify select element - switch(this.current) { - case 'hda': - this.select_datasets.value(list); - break; - case 'hdca': - this.select_collection.value(list[0]); - break; + // identify suitable select field + if (dict && dict.values.length > 0 && dict.values[0].src == 'hcda') { + this.current = 'collection'; + this.select_collection.value(list[0]); + } else { + if (list.length > 1) { + this.current = 'multiple'; + this.select_multiple.value(list); + } else { + this.current = 'single'; + this.select_single.value(list[0]); + } } - + this.refresh(); + // check if value has been set var select = this._select(); if (!select.validate()) { @@ -153,7 +189,7 @@ var View = Backbone.View.extend({ for (var i in id_list) { result.values.push({ id : id_list[i], - src : this.current + src : this.list[this.current].type }); } @@ -169,26 +205,24 @@ var View = Backbone.View.extend({ /** Refreshes data selection view */ refresh: function() { - switch (this.current) { - case 'hda': - this.select_datasets.$el.fadeIn(); - this.select_collection.$el.hide(); - break; - case 'hdca': - this.select_datasets.$el.hide(); - this.select_collection.$el.fadeIn(); - break; + for (var i in this.list) { + var $el = this.list[i].field.$el; + if (this.current == i) { + $el.show(); + } else { + $el.hide(); + } + } + if (this.current != 'single' && !this.options.multiple) { + this.$batch.show(); + } else { + this.$batch.hide(); } }, /** Assists in selecting the current field */ _select: function() { - switch(this.current) { - case 'hdca': - return this.select_collection; - default: - return this.select_datasets; - } + return this.list[this.current].field; } }); diff --git a/client/galaxy/scripts/mvc/tools/tools-template.js b/client/galaxy/scripts/mvc/tools/tools-template.js index bd480f7cb01..3b3e920daa5 100644 --- a/client/galaxy/scripts/mvc/tools/tools-template.js +++ b/client/galaxy/scripts/mvc/tools/tools-template.js @@ -56,7 +56,7 @@ return { batchMode: function() { return '
' + '' + - 'This is a batch mode input field. A separate job will be triggered for each dataset.' + 'This is a batch mode input field. A separate job will be triggered for each dataset.' + '
'; } }; diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 7bde121c45b..c947b00da06 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -2067,22 +2067,49 @@ class DataToolParameter( BaseDataToolParameter ): return ref def to_dict( self, trans, view='collection', value_mapper=None, other_values=None ): + # create dictionary and fill default parameters d = super( DataToolParameter, self ).to_dict( trans ) d['extensions'] = self.extensions d['multiple'] = self.multiple + d['is_dynamic'] = True + d['options'] = {'hda': [], 'hdca': []} + + # return default content if context is not available if other_values is None: - # No need to produce lists of datasets for history. return d + # prepare dataset/collection matching dataset_matcher = DatasetMatcher( trans, self, None, other_values ) history = trans.history multiple = self.multiple - for hda_match, hid in self.match_datasets( history, dataset_matcher ): - # hda_match not an hda - it is a description of the match, may - # describe match after implicit conversion. - pass - for history_dataset_collection in self.match_collections( history, dataset_matcher, reduction=multiple ): - pass + + # add datasets + for hda in history.active_datasets_children_and_roles: + if dataset_matcher.hda_match( hda ): + d['options']['hda'].append({ + 'id' : trans.security.encode_id( hda.id ), + 'hid' : hda.hid, + 'name' : hda.name, + 'src' : 'hda', + 'dataset_id' : hda.dataset_id + }) + + # add dataset collections + dataset_collection_matcher = DatasetCollectionMatcher( dataset_matcher ) + for hdca in history.active_dataset_collections: + if dataset_collection_matcher.hdca_match( hdca, reduction=multiple ): + d['options']['hdca'].append({ + 'id' : trans.security.encode_id( hdca.id ), + 'hid' : hdca.hid, + 'name' : hdca.name, + 'src' : 'hdca' + }) + + # sort both lists + d['options']['hda'] = sorted(d['options']['hda'], key=lambda k: k['hid'], reverse=True) + d['options']['hdca'] = sorted(d['options']['hdca'], key=lambda k: k['hid'], reverse=True) + + # return final dictionary return d diff --git a/lib/galaxy/webapps/galaxy/api/history_contents.py b/lib/galaxy/webapps/galaxy/api/history_contents.py index 3a195bed07d..aad48044c68 100644 --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -131,12 +131,13 @@ class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociatio """ api_type = "file" encoded_id = trans.security.encode_id( hda.id ) + encoded_dataset_id = trans.security.encode_id( hda.dataset_id ); # TODO: handle failed_metadata here as well return { 'id' : encoded_id, 'history_id' : encoded_history_id, - 'dataset_id' : hda.dataset_id, + 'dataset_id' : encoded_dataset_id, 'name' : hda.name, 'type' : api_type, 'state' : hda.dataset.state, diff --git a/lib/galaxy/webapps/galaxy/api/tools.py b/lib/galaxy/webapps/galaxy/api/tools.py index 28974bc2794..95bf3528aaa 100644 --- a/lib/galaxy/webapps/galaxy/api/tools.py +++ b/lib/galaxy/webapps/galaxy/api/tools.py @@ -575,11 +575,13 @@ class ToolsController( BaseAPIController, UsesVisualizationMixin, UsesHistoryMix dict['value'] = value return dict - # populate state + # initialize state using default parameters def initialize_state(trans, inputs, state, context=None): context = ExpressionContext(state, context) for input in inputs.itervalues(): state[input.name] = input.get_initial_value(trans, context) + + # populates state with incoming url parameters def populate_state(trans, inputs, state, incoming, prefix="", context=None ): errors = dict() context = ExpressionContext(state, context) @@ -630,12 +632,14 @@ class ToolsController( BaseAPIController, UsesVisualizationMixin, UsesHistoryMix state[input.name] = value return errors - # build model + # builds tool model including all attributes def iterate(group_inputs, inputs, tool_state, errors, other_values=None): other_values = ExpressionContext( tool_state, other_values ) for input_index, input in enumerate( inputs.itervalues() ): # create model dictionary group_inputs[input_index] = input.to_dict(trans) + if group_inputs[input_index] is None: + continue # identify stat for subsection/group group_state = tool_state[input.name] diff --git a/static/scripts/mvc/tools/tools-content.js b/static/scripts/mvc/tools/tools-content.js index bab819e2587..c8ccb52fb33 100644 --- a/static/scripts/mvc/tools/tools-content.js +++ b/static/scripts/mvc/tools/tools-content.js @@ -1,96 +1,23 @@ define(['utils/utils'], function(Utils){ return Backbone.Model.extend({ // initialize - initialize: function(options) { - // backup basic url - this.base_url = galaxy_config.root + 'api/histories/' + options.history_id + '/contents'; - - // prepare content obects - this.datatypes = {}; + initialize: function(app) { this.summary = {}; - - // link this - var self = this; - - // request datatypes - Utils.get({ - url : galaxy_config.root + 'api/datatypes/mapping', - cache : true, - success : function(response) { - // backup datatype dictionary - self.datatypes = response; - - // get history summary - Utils.get({ - url : self.base_url + '?deleted=false', - success : function(response) { - // backup summary - self.summary = response; - - // sort by id - self.summary.sort(function(a, b) { - return a.hid > b.hid ? -1 : (a.hid < b.hid ? 1 : 0); - }); - - // log - console.debug('tools-content::initialize() - Completed.'); - - // callback - options.success && options.success(); - }, - error : function(response) { - // log request failure - console.debug('tools-content::initialize() - Ajax request for summary failed.'); - console.debug(response); - } - }); - }, - error : function(response) { - // log request failure - console.debug('tools-content::initialize() - Ajax request for datatypes failed.'); - console.debug(response); - } - }); }, - /** - * Filters contents by data type. + /** Add new content elements */ - filterType: function(options) { - // initialize parameters - options = options || {}; - var result = []; - - // identify content type - var history_content_type = 'dataset'; - if (options.src== 'hdca') { - history_content_type = 'dataset_collection'; - } - - // search in summary - for (var i in this.summary) { - var content = this.summary[i]; - - // check ok state (TODO: should be implemented in the api) - if (content.history_content_type === 'dataset' && content.state !== 'ok') { - continue; - } - - // match datatypes - var found = false; - for (var i in options.extensions) { - if (this._matchType(options.extensions[i], content.extension)) { - found = true; - break; - } - } - - // final match result - if ((content.history_content_type === history_content_type) && (found || !options.extensions)) { - result.push(content); + add: function(content_list) { + // add/update content in summary list + for (var i in content_list) { + for (var j in content_list[i]) { + var c = content_list[i][j]; + this.summary[c.id + '_' + c.src] = c; } } - return result; + + // log + console.debug('tools-content::initialize() - Completed.'); }, /** Returns matched content from summary. @@ -126,33 +53,6 @@ define(['utils/utils'], function(Utils){ console.debug(response); } }); - }, - - /** Check if datatypes match - */ - _matchType: function(target, reference) { - // check if target class is available - var target_class = this.datatypes.ext_to_class_name[target]; - if (!target_class) { - console.debug('tools-content::_matchType() - Specific target class unavailable. Accepting all formats.'); - return true; - } - - // check if reference class is available - var reference_class = this.datatypes.ext_to_class_name[reference]; - if (!reference_class) { - console.debug('tools-content::_matchType() - Specific reference class unavailable. Accepting all formats.'); - return true; - } - - // check reference group - var reference_group = this.datatypes.class_to_classes[reference_class]; - if (reference_group[target_class]) { - return true; - } - - // classes do not match - return false; } }); }); \ No newline at end of file diff --git a/static/scripts/mvc/tools/tools-form.js b/static/scripts/mvc/tools/tools-form.js index b3c5b594bfb..12480b35339 100644 --- a/static/scripts/mvc/tools/tools-form.js +++ b/static/scripts/mvc/tools/tools-form.js @@ -21,11 +21,19 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', var self = this; // link galaxy modal or create one - if (parent.Galaxy && parent.Galaxy.modal) { - this.modal = parent.Galaxy.modal; + var galaxy = parent.Galaxy; + if (galaxy && galaxy.modal) { + this.modal = galaxy.modal; } else { this.modal = new Ui.Modal.View(); } + + // check if the user is an admin + if (galaxy && galaxy.currUser) { + this.is_admin = galaxy.currUser.get('is_admin') + } else { + this.is_admin = false; + } // link options this.options = options; @@ -47,12 +55,10 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', this.job_handler = new ToolJobs(this); // request history content and build form - this.content = new ToolContent({ - history_id : self.options.history_id, - success : function() { - self._buildForm(self.options); - } - }); + this.content = new ToolContent(this); + + // build this form + this._buildForm(options); }, // message @@ -72,7 +78,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', // this happens i.e. when repeat blocks are added or removed and on initialization rebuild: function() { this.tree.refresh(); - console.debug('tools-form::refresh() - Refreshed form structure.'); + console.debug('tools-form::rebuild() - Rebuilding data structures.'); }, // refreshes input states i.e. for dynamic parameters @@ -142,7 +148,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', var current_state = this.tree.finalize({ data : function(dict) { if (dict.values.length > 0 && dict.values[0] && dict.values[0].src === 'hda') { - return self.content.get({id: dict.values[0].id}).dataset_id; + return self.content.get({id: dict.values[0].id, src: 'hda'}).dataset_id; } return null; } @@ -215,16 +221,22 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', // get/update field var field = self.field_list[input_id]; - if (field.update && input.type != 'data') { + if (field.update) { var new_options = []; - for (var i in node.options) { - var opt = node.options[i]; - if (opt.length > 2) { - new_options.push({ - 'label': opt[0], - 'value': opt[1] - }); - } + switch (input.type) { + case 'data': + new_options = input.options; + break; + default: + for (var i in node.options) { + var opt = node.options[i]; + if (opt.length > 2) { + new_options.push({ + 'label': opt[0], + 'value': opt[1] + }); + } + } } field.update(new_options); console.debug('Updating options for ' + input_id); @@ -292,7 +304,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-portlet', 'mvc/ui/ui-misc', }); // add admin operations - if (Galaxy.currUser.get('is_admin')) { + if (this.is_admin) { // create download button menu.addMenu({ icon : 'fa-download', diff --git a/static/scripts/mvc/tools/tools-jobs.js b/static/scripts/mvc/tools/tools-jobs.js index 8ffdb037f81..fe1f157bfd3 100644 --- a/static/scripts/mvc/tools/tools-jobs.js +++ b/static/scripts/mvc/tools/tools-jobs.js @@ -142,8 +142,8 @@ return Backbone.Model.extend({ if (batch_n === -1) { batch_n = n; } else { - if (batch_n !== n && n != 1) { - this._foundError(input_id, 'Please make sure that you select a single input or the same number of inputs for all batch mode fields. This field contains ' + n + ' selection(s) while a previous field contains ' + batch_n + '.'); + if (batch_n !== n) { + this._foundError(input_id, 'Please make sure that you select the same number of inputs for all batch mode fields. This field contains ' + n + ' selection(s) while a previous field contains ' + batch_n + '.'); return false; } } diff --git a/static/scripts/mvc/tools/tools-section.js b/static/scripts/mvc/tools/tools-section.js index cb78711b619..53930af608c 100644 --- a/static/scripts/mvc/tools/tools-section.js +++ b/static/scripts/mvc/tools/tools-section.js @@ -372,6 +372,7 @@ define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/tools/tools-rep id : 'field-' + input_def.id, extensions : input_def.extensions, multiple : input_def.multiple, + data : input_def.options, onchange : function() { self.app.refresh(); } diff --git a/static/scripts/mvc/tools/tools-select-content.js b/static/scripts/mvc/tools/tools-select-content.js index 1803ac8ec72..c1ae64c93a4 100644 --- a/static/scripts/mvc/tools/tools-select-content.js +++ b/static/scripts/mvc/tools/tools-select-content.js @@ -4,7 +4,8 @@ define(['utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs', 'mvc/tools/tools-temp var View = Backbone.View.extend({ // initialize initialize : function(app, options) { - // configure options + // link app and options + this.app = app; this.options = options; // link this @@ -14,13 +15,14 @@ var View = Backbone.View.extend({ this.setElement('
'); // current selection - this.current = 'hda'; + this.current = 'single'; // create button - this.button_new = new Ui.RadioButton.View({ + this.button_type = new Ui.RadioButton.View({ value : this.current, - data : [ { icon: 'fa-file-o', label : 'Select datasets', value : 'hda' }, - { icon: 'fa-files-o', label : 'Select a collection', value : 'hdca' }], + data : [ { icon: 'fa-file-o', label : 'Single dataset', value : 'single' }, + { icon: 'fa-files-o', label : 'Multiple datasets', value : 'multiple' }, + { icon: 'fa-folder-o', label : 'List of datasets', value : 'collection' }], onchange: function(value) { self.current = value; self.refresh(); @@ -28,68 +30,56 @@ var View = Backbone.View.extend({ } }); - // - // datasets - // - var datasets = app.content.filterType({ - src : 'hda', - extensions : options.extensions + // single dataset select field + this.select_single = new Ui.Select.View({ + onchange : function() { + self.trigger('change'); + } }); - - // configure options fields - var dataset_options = []; - for (var i in datasets) { - dataset_options.push({ - label: datasets[i].hid + ': ' + datasets[i].name, - value: datasets[i].id - }); - } - // select field - this.select_datasets = new Ui.Select.View({ + // multiple datasets select field + this.select_multiple = new Ui.Select.View({ multiple : true, - data : dataset_options, - value : dataset_options[0] && dataset_options[0].value, onchange : function() { self.trigger('change'); } }); - // - // collections - // - var collections = app.content.filterType({ - src : 'hdca', - extensions : options.extensions - }); - - // configure options fields - var collection_options = []; - for (var i in collections) { - collection_options.push({ - label: collections[i].hid + ': ' + collections[i].name, - value: collections[i].id - }); - } - - // create select field for collections + // collection select field this.select_collection = new Ui.Select.View({ - data : collection_options, - value : collection_options[0] && collection_options[0].value, onchange : function() { self.trigger('change'); } }); + // list of all select fields + this.list = { + 'single' : { + field: this.select_single, + type : 'hda' + }, + 'multiple' : { + field: this.select_multiple, + type : 'hda' + }, + 'collection' : { + field: this.select_collection, + type : 'hdca' + } + }; + + // add batch mode information + this.$batch = $(ToolTemplate.batchMode()); + // add elements to dom - this.$el.append(Utils.wrap(this.button_new.$el)); - this.$el.append(this.select_datasets.$el); - this.$el.append(this.select_collection.$el); - - // check for batch mode - if (!this.options.multiple) { - this.$el.append(ToolTemplate.batchMode()); + this.$el.append(Utils.wrap(this.button_type.$el)); + for (var i in this.list) { + this.$el.append(this.list[i].field.$el); } + this.$el.append(this.$batch); + + // update options + this.update(options.data); // refresh view this.refresh(); @@ -102,31 +92,77 @@ var View = Backbone.View.extend({ }); }, + /** Indicate that select fields are being updated */ + wait: function() { + for (var i in this.list) { + this.list[i].field.wait(); + } + }, + + /** Indicate that the options update has been completed */ + unwait: function() { + for (var i in this.list) { + this.list[i].field.unwait(); + } + }, + + /** Update content selector */ + update: function(options) { + // identify dataset options + var dataset_options = []; + for (var i in options.hda) { + var hda = options.hda[i]; + dataset_options.push({ + label: hda.hid + ': ' + hda.name, + value: hda.id + }); + } + + // identify collection options + var collection_options = []; + for (var i in options.hdca) { + var hdca = options.hdca[i]; + collection_options.push({ + label: hdca.hid + ': ' + hdca.name, + value: hdca.id + }); + } + + // update selection fields + this.select_single.update(dataset_options); + this.select_multiple.update(dataset_options); + this.select_collection.update(collection_options); + + // add to content list + this.app.content.add(options); + }, + /** Return the currently selected dataset values */ value : function (dict) { // update current value if (dict !== undefined) { try { - // set source - this.current = dict.values[0].src; - this.refresh(); - // create list var list = []; for (var i in dict.values) { list.push(dict.values[i].id); } - // identify select element - switch(this.current) { - case 'hda': - this.select_datasets.value(list); - break; - case 'hdca': - this.select_collection.value(list[0]); - break; + // identify suitable select field + if (dict && dict.values.length > 0 && dict.values[0].src == 'hcda') { + this.current = 'collection'; + this.select_collection.value(list[0]); + } else { + if (list.length > 1) { + this.current = 'multiple'; + this.select_multiple.value(list); + } else { + this.current = 'single'; + this.select_single.value(list[0]); + } } - + this.refresh(); + // check if value has been set var select = this._select(); if (!select.validate()) { @@ -153,7 +189,7 @@ var View = Backbone.View.extend({ for (var i in id_list) { result.values.push({ id : id_list[i], - src : this.current + src : this.list[this.current].type }); } @@ -169,26 +205,24 @@ var View = Backbone.View.extend({ /** Refreshes data selection view */ refresh: function() { - switch (this.current) { - case 'hda': - this.select_datasets.$el.fadeIn(); - this.select_collection.$el.hide(); - break; - case 'hdca': - this.select_datasets.$el.hide(); - this.select_collection.$el.fadeIn(); - break; + for (var i in this.list) { + var $el = this.list[i].field.$el; + if (this.current == i) { + $el.show(); + } else { + $el.hide(); + } + } + if (this.current != 'single' && !this.options.multiple) { + this.$batch.show(); + } else { + this.$batch.hide(); } }, /** Assists in selecting the current field */ _select: function() { - switch(this.current) { - case 'hdca': - return this.select_collection; - default: - return this.select_datasets; - } + return this.list[this.current].field; } }); diff --git a/static/scripts/mvc/tools/tools-template.js b/static/scripts/mvc/tools/tools-template.js index bd480f7cb01..3b3e920daa5 100644 --- a/static/scripts/mvc/tools/tools-template.js +++ b/static/scripts/mvc/tools/tools-template.js @@ -56,7 +56,7 @@ return { batchMode: function() { return '
' + '' + - 'This is a batch mode input field. A separate job will be triggered for each dataset.' + 'This is a batch mode input field. A separate job will be triggered for each dataset.' + '
'; } }; diff --git a/static/scripts/packed/mvc/tools/tools-content.js b/static/scripts/packed/mvc/tools/tools-content.js index 6b8bfde5571..8af497de600 100644 --- a/static/scripts/packed/mvc/tools/tools-content.js +++ b/static/scripts/packed/mvc/tools/tools-content.js @@ -1 +1 @@ -define(["utils/utils"],function(a){return Backbone.Model.extend({initialize:function(c){this.base_url=galaxy_config.root+"api/histories/"+c.history_id+"/contents";this.datatypes={};this.summary={};var b=this;a.get({url:galaxy_config.root+"api/datatypes/mapping",cache:true,success:function(d){b.datatypes=d;a.get({url:b.base_url+"?deleted=false",success:function(e){b.summary=e;b.summary.sort(function(g,f){return g.hid>f.hid?-1:(g.hid");$(this.container).append(this.$el);this.tree=new c(this);this.job_handler=new g(this);this.content=new f({history_id:n.options.history_id,success:function(){n._buildForm(n.options)}})},message:function(n){$(this.container).empty();$(this.container).append(n)},reset:function(){for(var n in this.element_list){this.element_list[n].reset()}},rebuild:function(){this.tree.refresh();console.debug("tools-form::refresh() - Refreshed form structure.")},refresh:function(){if(!this.is_dynamic){return}var n=this;this.deferred.reset();this.deferred.execute(function(){n._updateModel()})},_buildModel:function(){var n=this;var o=galaxy_config.root+"api/tools/"+this.options.id+"/build?";if(this.options.job_id){o+="job_id="+this.options.job_id}else{if(this.options.dataset_id){o+="dataset_id="+this.options.dataset_id}else{var p=top.location.href;var q=p.indexOf("?");if(p.indexOf("tool_id=")!=-1&&q!==-1){o+=p.slice(q+1)}}}i.request({type:"GET",url:o,success:function(r){n.options=$.extend(n.options,r);n.model=r;n.inputs=r.inputs;console.debug("tools-form::initialize() - Initial tool model ready.");console.debug(r);n._buildForm()},error:function(r){console.debug("tools-form::initialize() - Initial tool model request failed.");console.debug(r)}})},_updateModel:function(){var n=this;var o=this.tree.finalize({data:function(r){if(r.values.length>0&&r.values[0]&&r.values[0].src==="hda"){return n.content.get({id:r.values[0].id}).dataset_id}return null}});console.debug("tools-form::_refreshForm() - Refreshing states.");console.debug(o);function q(u){for(var s in n.input_list){var t=n.field_list[s];var r=n.input_list[s];if(r.is_dynamic&&t.wait&&t.unwait){if(u){t.wait()}else{t.unwait()}}}}q(true);var p=this.deferred.register();i.request({type:"GET",url:galaxy_config.root+"api/tools/"+this.options.id+"/build",data:o,success:function(r){n._updateForm(r);q(false);n.deferred.done(p);console.debug("tools-form::_refreshForm() - States refreshed.");console.debug(r)},error:function(r){n.deferred.done(p);console.debug("tools-form::_refreshForm() - Refresh request failed.");console.debug(r)}})},_updateForm:function(n){var o=this;this.tree.matchModel(n,function(q,u){var p=o.input_list[q];if(p&&p.options){if(JSON.stringify(p.options)!=JSON.stringify(u.options)){p.options=u.options;var v=o.field_list[q];if(v.update&&p.type!="data"){var t=[];for(var s in u.options){var r=u.options[s];if(r.length>2){t.push({label:r[0],value:r[1]})}}v.update(t);console.debug("Updating options for "+q)}}}})},_buildForm:function(p){var o=this;this.field_list={};this.input_list={};this.element_list={};this.model=p;this.inputs=p.inputs;var r=new m.ButtonMenu({icon:"fa-gear",tooltip:"Click to see a list of options."});if(p.biostar_url){r.addMenu({icon:"fa-question-circle",title:"Question?",tooltip:"Ask a question about this tool (Biostar)",onclick:function(){window.open(o.options.biostar_url+"/p/new/post/")}});r.addMenu({icon:"fa-search",title:"Search",tooltip:"Search help for this tool (Biostar)",onclick:function(){window.open(o.options.biostar_url+"/t/"+o.options.id+"/")}})}r.addMenu({icon:"fa-share",title:"Share",tooltip:"Share this tool",onclick:function(){prompt("Copy to clipboard: Ctrl+C, Enter",window.location.origin+galaxy_config.root+"root?tool_id="+o.options.id)}});if(Galaxy.currUser.get("is_admin")){r.addMenu({icon:"fa-download",title:"Download",tooltip:"Download this tool",onclick:function(){window.location.href=galaxy_config.root+"api/tools/"+o.options.id+"/download"}})}this.section=new l.View(o,{inputs:this.inputs,cls:"ui-table-plain"});if(this.incompatible){this.$el.hide();$("#tool-form-classic").show();return}this.portlet=new h.View({icon:"fa-wrench",title:""+this.model.name+" "+this.model.description,operations:{menu:r},buttons:{execute:new m.Button({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",cls:"btn btn-primary",floating:"clear",onclick:function(){o.job_handler.submit()}})}});this.$el.empty();this.$el.append(this.portlet.$el);if(p.help!=""){this.$el.append(d.help(p.help))}if(p.citations){var n=new k.ToolCitationCollection();n.tool_id=p.id;var q=new a.CitationListView({collection:n});q.render();n.fetch();this.$el.append(q.$el)}this.portlet.append(this.section.$el);this.rebuild()}});return{View:b}}); \ No newline at end of file +define(["utils/utils","utils/deferred","mvc/ui/ui-portlet","mvc/ui/ui-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-content","mvc/tools/tools-section","mvc/tools/tools-tree","mvc/tools/tools-jobs"],function(i,j,h,m,k,a,e,d,f,l,c,g){var b=Backbone.View.extend({container:"body",initialize:function(o){console.debug(o);var n=this;var p=parent.Galaxy;if(p&&p.modal){this.modal=p.modal}else{this.modal=new m.Modal.View()}if(p&&p.currUser){this.is_admin=p.currUser.get("is_admin")}else{this.is_admin=false}this.options=o;this.deferred=new j();this.setElement("
");$(this.container).append(this.$el);this.tree=new c(this);this.job_handler=new g(this);this.content=new f(this);this._buildForm(o)},message:function(n){$(this.container).empty();$(this.container).append(n)},reset:function(){for(var n in this.element_list){this.element_list[n].reset()}},rebuild:function(){this.tree.refresh();console.debug("tools-form::rebuild() - Rebuilding data structures.")},refresh:function(){if(!this.is_dynamic){return}var n=this;this.deferred.reset();this.deferred.execute(function(){n._updateModel()})},_buildModel:function(){var n=this;var o=galaxy_config.root+"api/tools/"+this.options.id+"/build?";if(this.options.job_id){o+="job_id="+this.options.job_id}else{if(this.options.dataset_id){o+="dataset_id="+this.options.dataset_id}else{var p=top.location.href;var q=p.indexOf("?");if(p.indexOf("tool_id=")!=-1&&q!==-1){o+=p.slice(q+1)}}}i.request({type:"GET",url:o,success:function(r){n.options=$.extend(n.options,r);n.model=r;n.inputs=r.inputs;console.debug("tools-form::initialize() - Initial tool model ready.");console.debug(r);n._buildForm()},error:function(r){console.debug("tools-form::initialize() - Initial tool model request failed.");console.debug(r)}})},_updateModel:function(){var n=this;var o=this.tree.finalize({data:function(r){if(r.values.length>0&&r.values[0]&&r.values[0].src==="hda"){return n.content.get({id:r.values[0].id,src:"hda"}).dataset_id}return null}});console.debug("tools-form::_refreshForm() - Refreshing states.");console.debug(o);function q(u){for(var s in n.input_list){var t=n.field_list[s];var r=n.input_list[s];if(r.is_dynamic&&t.wait&&t.unwait){if(u){t.wait()}else{t.unwait()}}}}q(true);var p=this.deferred.register();i.request({type:"GET",url:galaxy_config.root+"api/tools/"+this.options.id+"/build",data:o,success:function(r){n._updateForm(r);q(false);n.deferred.done(p);console.debug("tools-form::_refreshForm() - States refreshed.");console.debug(r)},error:function(r){n.deferred.done(p);console.debug("tools-form::_refreshForm() - Refresh request failed.");console.debug(r)}})},_updateForm:function(n){var o=this;this.tree.matchModel(n,function(q,u){var p=o.input_list[q];if(p&&p.options){if(JSON.stringify(p.options)!=JSON.stringify(u.options)){p.options=u.options;var v=o.field_list[q];if(v.update){var t=[];switch(p.type){case"data":t=p.options;break;default:for(var s in u.options){var r=u.options[s];if(r.length>2){t.push({label:r[0],value:r[1]})}}}v.update(t);console.debug("Updating options for "+q)}}}})},_buildForm:function(p){var o=this;this.field_list={};this.input_list={};this.element_list={};this.model=p;this.inputs=p.inputs;var r=new m.ButtonMenu({icon:"fa-gear",tooltip:"Click to see a list of options."});if(p.biostar_url){r.addMenu({icon:"fa-question-circle",title:"Question?",tooltip:"Ask a question about this tool (Biostar)",onclick:function(){window.open(o.options.biostar_url+"/p/new/post/")}});r.addMenu({icon:"fa-search",title:"Search",tooltip:"Search help for this tool (Biostar)",onclick:function(){window.open(o.options.biostar_url+"/t/"+o.options.id+"/")}})}r.addMenu({icon:"fa-share",title:"Share",tooltip:"Share this tool",onclick:function(){prompt("Copy to clipboard: Ctrl+C, Enter",window.location.origin+galaxy_config.root+"root?tool_id="+o.options.id)}});if(this.is_admin){r.addMenu({icon:"fa-download",title:"Download",tooltip:"Download this tool",onclick:function(){window.location.href=galaxy_config.root+"api/tools/"+o.options.id+"/download"}})}this.section=new l.View(o,{inputs:this.inputs,cls:"ui-table-plain"});if(this.incompatible){this.$el.hide();$("#tool-form-classic").show();return}this.portlet=new h.View({icon:"fa-wrench",title:""+this.model.name+" "+this.model.description,operations:{menu:r},buttons:{execute:new m.Button({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",cls:"btn btn-primary",floating:"clear",onclick:function(){o.job_handler.submit()}})}});this.$el.empty();this.$el.append(this.portlet.$el);if(p.help!=""){this.$el.append(d.help(p.help))}if(p.citations){var n=new k.ToolCitationCollection();n.tool_id=p.id;var q=new a.CitationListView({collection:n});q.render();n.fetch();this.$el.append(q.$el)}this.portlet.append(this.section.$el);this.rebuild()}});return{View:b}}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/tools/tools-jobs.js b/static/scripts/packed/mvc/tools/tools-jobs.js index c112ee3900d..eea10ad50fe 100644 --- a/static/scripts/packed/mvc/tools/tools-jobs.js +++ b/static/scripts/packed/mvc/tools/tools-jobs.js @@ -1 +1 @@ -define(["utils/utils","mvc/tools/tools-template"],function(b,a){return Backbone.Model.extend({initialize:function(d,c){this.app=d;this.options=b.merge(c,this.optionsDefault)},submit:function(){var c=this;var d={tool_id:this.app.options.id,inputs:this.app.tree.finalize()};this.app.reset();if(!this._validation(d)){console.debug("tools-jobs::submit - Submission canceled. Validation failed.");return}console.debug(d);this.app.modal.show({title:"Please wait...",body:"progress",closing_events:true,buttons:{Close:function(){c.app.modal.hide()}}});b.request({type:"POST",url:galaxy_config.root+"api/tools",data:d,success:function(e){c.app.modal.hide();c.app.message(a.success(e));c._refreshHdas()},error:function(e,g){c.app.modal.hide();if(e&&e.message&&e.message.data){var h=c.app.tree.matchResponse(e.message.data);for(var f in h){c._foundError(f,h[f]);break}}else{console.debug(e);c.app.modal.show({title:"Job submission failed",body:a.error(d),buttons:{Close:function(){c.app.modal.hide()}}})}}})},_foundError:function(c,d){var e=this.app.element_list[c];e.error(d||"Please verify this parameter.");$(this.app.container).animate({scrollTop:e.$el.offset().top-20},500)},_validation:function(h){var d=h.inputs;var m=-1;var i=null;for(var k in d){var f=d[k];var l=this.app.tree.match(k);var e=this.app.field_list[l];var j=this.app.input_list[l];if(j&&e&&e.validate&&!e.validate()){this._foundError(l);return false}if(f.batch){var g=f.values.length;var c=null;if(g>0){c=f.values[0]&&f.values[0].src}if(c){if(i===null){i=c}else{if(i!==c){this._foundError(l,"Please select either dataset or dataset list fields for all batch mode fields.");return false}}}if(m===-1){m=g}else{if(m!==g&&g!=1){this._foundError(l,"Please make sure that you select a single input or the same number of inputs for all batch mode fields. This field contains "+g+" selection(s) while a previous field contains "+m+".");return false}}}}return true},_refreshHdas:function(){if(parent.Galaxy&&parent.Galaxy.currHistoryPanel){parent.Galaxy.currHistoryPanel.refreshContents()}}})}); \ No newline at end of file +define(["utils/utils","mvc/tools/tools-template"],function(b,a){return Backbone.Model.extend({initialize:function(d,c){this.app=d;this.options=b.merge(c,this.optionsDefault)},submit:function(){var c=this;var d={tool_id:this.app.options.id,inputs:this.app.tree.finalize()};this.app.reset();if(!this._validation(d)){console.debug("tools-jobs::submit - Submission canceled. Validation failed.");return}console.debug(d);this.app.modal.show({title:"Please wait...",body:"progress",closing_events:true,buttons:{Close:function(){c.app.modal.hide()}}});b.request({type:"POST",url:galaxy_config.root+"api/tools",data:d,success:function(e){c.app.modal.hide();c.app.message(a.success(e));c._refreshHdas()},error:function(e,g){c.app.modal.hide();if(e&&e.message&&e.message.data){var h=c.app.tree.matchResponse(e.message.data);for(var f in h){c._foundError(f,h[f]);break}}else{console.debug(e);c.app.modal.show({title:"Job submission failed",body:a.error(d),buttons:{Close:function(){c.app.modal.hide()}}})}}})},_foundError:function(c,d){var e=this.app.element_list[c];e.error(d||"Please verify this parameter.");$(this.app.container).animate({scrollTop:e.$el.offset().top-20},500)},_validation:function(h){var d=h.inputs;var m=-1;var i=null;for(var k in d){var f=d[k];var l=this.app.tree.match(k);var e=this.app.field_list[l];var j=this.app.input_list[l];if(j&&e&&e.validate&&!e.validate()){this._foundError(l);return false}if(f.batch){var g=f.values.length;var c=null;if(g>0){c=f.values[0]&&f.values[0].src}if(c){if(i===null){i=c}else{if(i!==c){this._foundError(l,"Please select either dataset or dataset list fields for all batch mode fields.");return false}}}if(m===-1){m=g}else{if(m!==g){this._foundError(l,"Please make sure that you select the same number of inputs for all batch mode fields. This field contains "+g+" selection(s) while a previous field contains "+m+".");return false}}}}return true},_refreshHdas:function(){if(parent.Galaxy&&parent.Galaxy.currHistoryPanel){parent.Galaxy.currHistoryPanel.refreshContents()}}})}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/tools/tools-section.js b/static/scripts/packed/mvc/tools/tools-section.js index ae49dd56ebe..4d2f57b6596 100644 --- a/static/scripts/packed/mvc/tools/tools-section.js +++ b/static/scripts/packed/mvc/tools/tools-section.js @@ -1 +1 @@ -define(["utils/utils","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/tools/tools-repeat","mvc/tools/tools-select-content","mvc/tools/tools-input"],function(d,b,g,c,a,e){var f=Backbone.View.extend({initialize:function(i,h){this.app=i;this.inputs=h.inputs;h.cls_tr="section-row";this.table=new b.View(h);this.setElement(this.table.$el);this.render()},render:function(){this.table.delAll();for(var h in this.inputs){this._add(this.inputs[h])}},_add:function(j){var i=this;var h=jQuery.extend(true,{},j);h.id=j.id=d.uuid();this.app.input_list[h.id]=h;var k=h.type;switch(k){case"conditional":this._addConditional(h);break;case"repeat":this._addRepeat(h);break;default:this._addRow(h)}},_addConditional:function(h){var j=this;h.test_param.id=h.id;var m=this._addRow(h.test_param);m.options.onchange=function(t){var p=j.app.tree.matchCase(h,t);for(var r in h.cases){var w=h.cases[r];var u=h.id+"-section-"+r;var o=j.table.get(u);var v=false;for(var q in w.inputs){var s=w.inputs[q].type;if(s&&s!=="hidden"){v=true;break}}if(r==p&&v){o.fadeIn("fast")}else{o.hide()}}j.app.refresh()};for(var l in h.cases){var k=h.id+"-section-"+l;var n=new f(this.app,{inputs:h.cases[l].inputs,cls:"ui-table-plain"});n.$el.addClass("ui-table-form-section");this.table.add(n.$el);this.table.append(k)}m.trigger("change")},_addRepeat:function(o){var r=this;var p=0;function m(i,t){var s=o.id+"-section-"+(p++);var u=null;if(t){u=function(){k.del(s);k.retitle(o.title);r.app.rebuild();r.app.refresh()}}var v=new f(r.app,{inputs:i,cls:"ui-table-plain"});k.add({id:s,title:o.title,$el:v.$el,ondel:u});k.retitle(o.title)}var k=new c.View({title_new:o.title,max:o.max,onnew:function(){m(o.inputs,true);r.app.rebuild();r.app.refresh()}});var h=o.min;var q=_.size(o.cache);for(var l=0;l=h)}var j=new e(this.app,{label:o.title,help:o.help,field:k});j.$el.addClass("ui-table-form-section");this.table.add(j.$el);this.table.append(o.id)},_addRow:function(h){var k=h.id;var i=this._createField(h);if(h.is_dynamic){this.app.is_dynamic=true}this.app.field_list[k]=i;var j=new e(this.app,{label:h.label,optional:h.optional,help:h.help,field:i});this.app.element_list[k]=j;this.table.add(j.$el);this.table.append(k);return i},_createField:function(h){var i=null;switch(h.type){case"text":i=this._fieldText(h);break;case"select":i=this._fieldSelect(h);break;case"data":i=this._fieldData(h);break;case"data_column":i=this._fieldSelect(h);break;case"hidden":i=this._fieldHidden(h);break;case"integer":i=this._fieldSlider(h);break;case"float":i=this._fieldSlider(h);break;case"boolean":i=this._fieldBoolean(h);break;case"genomebuild":i=this._fieldSelect(h);break;default:this.app.incompatible=true;if(h.options){i=this._fieldSelect(h)}else{i=this._fieldText(h)}console.debug("tools-form::_addRow() : Auto matched field type ("+h.type+").")}if(h.value!==undefined){i.value(h.value)}return i},_fieldData:function(h){var i=this;return new a.View(this.app,{id:"field-"+h.id,extensions:h.extensions,multiple:h.multiple,onchange:function(){i.app.refresh()}})},_fieldSelect:function(h){var k=[];for(var l in h.options){var m=h.options[l];k.push({label:m[0],value:m[1]})}var n=g.Select;switch(h.display){case"checkboxes":n=g.Checkbox;break;case"radio":n=g.Radio;break}var j=this;return new n.View({id:"field-"+h.id,data:k,multiple:h.multiple,onchange:function(){j.app.refresh()}})},_fieldText:function(h){var i=this;return new g.Input({id:"field-"+h.id,area:h.area,onchange:function(){i.app.refresh()}})},_fieldSlider:function(h){return new g.Slider.View({id:"field-"+h.id,precise:h.type=="float",min:h.min,max:h.max})},_fieldHidden:function(h){return new g.Hidden({id:"field-"+h.id})},_fieldBoolean:function(h){return new g.RadioButton.View({id:"field-"+h.id,data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]})}});return{View:f}}); \ No newline at end of file +define(["utils/utils","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/tools/tools-repeat","mvc/tools/tools-select-content","mvc/tools/tools-input"],function(d,b,g,c,a,e){var f=Backbone.View.extend({initialize:function(i,h){this.app=i;this.inputs=h.inputs;h.cls_tr="section-row";this.table=new b.View(h);this.setElement(this.table.$el);this.render()},render:function(){this.table.delAll();for(var h in this.inputs){this._add(this.inputs[h])}},_add:function(j){var i=this;var h=jQuery.extend(true,{},j);h.id=j.id=d.uuid();this.app.input_list[h.id]=h;var k=h.type;switch(k){case"conditional":this._addConditional(h);break;case"repeat":this._addRepeat(h);break;default:this._addRow(h)}},_addConditional:function(h){var j=this;h.test_param.id=h.id;var m=this._addRow(h.test_param);m.options.onchange=function(t){var p=j.app.tree.matchCase(h,t);for(var r in h.cases){var w=h.cases[r];var u=h.id+"-section-"+r;var o=j.table.get(u);var v=false;for(var q in w.inputs){var s=w.inputs[q].type;if(s&&s!=="hidden"){v=true;break}}if(r==p&&v){o.fadeIn("fast")}else{o.hide()}}j.app.refresh()};for(var l in h.cases){var k=h.id+"-section-"+l;var n=new f(this.app,{inputs:h.cases[l].inputs,cls:"ui-table-plain"});n.$el.addClass("ui-table-form-section");this.table.add(n.$el);this.table.append(k)}m.trigger("change")},_addRepeat:function(o){var r=this;var p=0;function m(i,t){var s=o.id+"-section-"+(p++);var u=null;if(t){u=function(){k.del(s);k.retitle(o.title);r.app.rebuild();r.app.refresh()}}var v=new f(r.app,{inputs:i,cls:"ui-table-plain"});k.add({id:s,title:o.title,$el:v.$el,ondel:u});k.retitle(o.title)}var k=new c.View({title_new:o.title,max:o.max,onnew:function(){m(o.inputs,true);r.app.rebuild();r.app.refresh()}});var h=o.min;var q=_.size(o.cache);for(var l=0;l=h)}var j=new e(this.app,{label:o.title,help:o.help,field:k});j.$el.addClass("ui-table-form-section");this.table.add(j.$el);this.table.append(o.id)},_addRow:function(h){var k=h.id;var i=this._createField(h);if(h.is_dynamic){this.app.is_dynamic=true}this.app.field_list[k]=i;var j=new e(this.app,{label:h.label,optional:h.optional,help:h.help,field:i});this.app.element_list[k]=j;this.table.add(j.$el);this.table.append(k);return i},_createField:function(h){var i=null;switch(h.type){case"text":i=this._fieldText(h);break;case"select":i=this._fieldSelect(h);break;case"data":i=this._fieldData(h);break;case"data_column":i=this._fieldSelect(h);break;case"hidden":i=this._fieldHidden(h);break;case"integer":i=this._fieldSlider(h);break;case"float":i=this._fieldSlider(h);break;case"boolean":i=this._fieldBoolean(h);break;case"genomebuild":i=this._fieldSelect(h);break;default:this.app.incompatible=true;if(h.options){i=this._fieldSelect(h)}else{i=this._fieldText(h)}console.debug("tools-form::_addRow() : Auto matched field type ("+h.type+").")}if(h.value!==undefined){i.value(h.value)}return i},_fieldData:function(h){var i=this;return new a.View(this.app,{id:"field-"+h.id,extensions:h.extensions,multiple:h.multiple,data:h.options,onchange:function(){i.app.refresh()}})},_fieldSelect:function(h){var k=[];for(var l in h.options){var m=h.options[l];k.push({label:m[0],value:m[1]})}var n=g.Select;switch(h.display){case"checkboxes":n=g.Checkbox;break;case"radio":n=g.Radio;break}var j=this;return new n.View({id:"field-"+h.id,data:k,multiple:h.multiple,onchange:function(){j.app.refresh()}})},_fieldText:function(h){var i=this;return new g.Input({id:"field-"+h.id,area:h.area,onchange:function(){i.app.refresh()}})},_fieldSlider:function(h){return new g.Slider.View({id:"field-"+h.id,precise:h.type=="float",min:h.min,max:h.max})},_fieldHidden:function(h){return new g.Hidden({id:"field-"+h.id})},_fieldBoolean:function(h){return new g.RadioButton.View({id:"field-"+h.id,data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]})}});return{View:f}}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/tools/tools-select-content.js b/static/scripts/packed/mvc/tools/tools-select-content.js index 596c30e3b5c..d3b3fb40169 100644 --- a/static/scripts/packed/mvc/tools/tools-select-content.js +++ b/static/scripts/packed/mvc/tools/tools-select-content.js @@ -1 +1 @@ -define(["utils/utils","mvc/ui/ui-misc","mvc/ui/ui-tabs","mvc/tools/tools-template"],function(c,e,b,a){var d=Backbone.View.extend({initialize:function(n,h){this.options=h;var g=this;this.setElement("
");this.current="hda";this.button_new=new e.RadioButton.View({value:this.current,data:[{icon:"fa-file-o",label:"Select datasets",value:"hda"},{icon:"fa-files-o",label:"Select a collection",value:"hdca"}],onchange:function(i){g.current=i;g.refresh();g.trigger("change")}});var l=n.content.filterType({src:"hda",extensions:h.extensions});var k=[];for(var j in l){k.push({label:l[j].hid+": "+l[j].name,value:l[j].id})}this.select_datasets=new e.Select.View({multiple:true,data:k,value:k[0]&&k[0].value,onchange:function(){g.trigger("change")}});var m=n.content.filterType({src:"hdca",extensions:h.extensions});var f=[];for(var j in m){f.push({label:m[j].hid+": "+m[j].name,value:m[j].id})}this.select_collection=new e.Select.View({data:f,value:f[0]&&f[0].value,onchange:function(){g.trigger("change")}});this.$el.append(c.wrap(this.button_new.$el));this.$el.append(this.select_datasets.$el);this.$el.append(this.select_collection.$el);if(!this.options.multiple){this.$el.append(a.batchMode())}this.refresh();this.on("change",function(){if(h.onchange){h.onchange(g.value())}})},value:function(m){if(m!==undefined){try{this.current=m.values[0].src;this.refresh();var l=[];for(var h in m.values){l.push(m.values[h].id)}switch(this.current){case"hda":this.select_datasets.value(l);break;case"hdca":this.select_collection.value(l[0]);break}var g=this._select();if(!g.validate()){g.value(g.first())}}catch(k){console.debug("tools-select-content::value() - Skipped.")}}var j=this._select().value();if(!(j instanceof Array)){j=[j]}var f={batch:!this.options.multiple,values:[]};for(var h in j){f.values.push({id:j[h],src:this.current})}return f},validate:function(){return this._select().validate()},refresh:function(){switch(this.current){case"hda":this.select_datasets.$el.fadeIn();this.select_collection.$el.hide();break;case"hdca":this.select_datasets.$el.hide();this.select_collection.$el.fadeIn();break}},_select:function(){switch(this.current){case"hdca":return this.select_collection;default:return this.select_datasets}}});return{View:d}}); \ No newline at end of file +define(["utils/utils","mvc/ui/ui-misc","mvc/ui/ui-tabs","mvc/tools/tools-template"],function(c,e,b,a){var d=Backbone.View.extend({initialize:function(j,g){this.app=j;this.options=g;var f=this;this.setElement("
");this.current="single";this.button_type=new e.RadioButton.View({value:this.current,data:[{icon:"fa-file-o",label:"Single dataset",value:"single"},{icon:"fa-files-o",label:"Multiple datasets",value:"multiple"},{icon:"fa-folder-o",label:"List of datasets",value:"collection"}],onchange:function(i){f.current=i;f.refresh();f.trigger("change")}});this.select_single=new e.Select.View({onchange:function(){f.trigger("change")}});this.select_multiple=new e.Select.View({multiple:true,onchange:function(){f.trigger("change")}});this.select_collection=new e.Select.View({onchange:function(){f.trigger("change")}});this.list={single:{field:this.select_single,type:"hda"},multiple:{field:this.select_multiple,type:"hda"},collection:{field:this.select_collection,type:"hdca"}};this.$batch=$(a.batchMode());this.$el.append(c.wrap(this.button_type.$el));for(var h in this.list){this.$el.append(this.list[h].field.$el)}this.$el.append(this.$batch);this.update(g.data);this.refresh();this.on("change",function(){if(g.onchange){g.onchange(f.value())}})},wait:function(){for(var f in this.list){this.list[f].field.wait()}},unwait:function(){for(var f in this.list){this.list[f].field.unwait()}},update:function(g){var l=[];for(var j in g.hda){var k=g.hda[j];l.push({label:k.hid+": "+k.name,value:k.id})}var f=[];for(var j in g.hdca){var h=g.hdca[j];f.push({label:h.hid+": "+h.name,value:h.id})}this.select_single.update(l);this.select_multiple.update(l);this.select_collection.update(f);this.app.content.add(g)},value:function(m){if(m!==undefined){try{var l=[];for(var h in m.values){l.push(m.values[h].id)}if(m&&m.values.length>0&&m.values[0].src=="hcda"){this.current="collection";this.select_collection.value(l[0])}else{if(l.length>1){this.current="multiple";this.select_multiple.value(l)}else{this.current="single";this.select_single.value(l[0])}}this.refresh();var g=this._select();if(!g.validate()){g.value(g.first())}}catch(k){console.debug("tools-select-content::value() - Skipped.")}}var j=this._select().value();if(!(j instanceof Array)){j=[j]}var f={batch:!this.options.multiple,values:[]};for(var h in j){f.values.push({id:j[h],src:this.list[this.current].type})}return f},validate:function(){return this._select().validate()},refresh:function(){for(var g in this.list){var f=this.list[g].field.$el;if(this.current==g){f.show()}else{f.hide()}}if(this.current!="single"&&!this.options.multiple){this.$batch.show()}else{this.$batch.hide()}},_select:function(){return this.list[this.current].field}});return{View:d}}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/tools/tools-template.js b/static/scripts/packed/mvc/tools/tools-template.js index 69f836606a3..f2d1e7d0ee4 100644 --- a/static/scripts/packed/mvc/tools/tools-template.js +++ b/static/scripts/packed/mvc/tools/tools-template.js @@ -1 +1 @@ -define([],function(){return{help:function(a){return'
'+a+"
"},success:function(c){if(!c.jobs||!c.jobs.length){console.debug("tools-template::success() - Failed jobs.");return}var a=c.jobs.length;var d="";if(a==1){d="1 job has"}else{d=a+" jobs have"}var b='

'+d+" been successfully added to the queue - resulting in the following datasets:

";for(var e in c.outputs){b+='

'+(parseInt(e)+1)+": "+c.outputs[e].name+"

"}b+="

You can check the status of queued jobs and view the resulting data by refreshing the History pane. When the job has been run the status will change from 'running' to 'finished' if completed successfully or 'error' if problems were encountered.

";return b},error:function(a){return'

The server could not complete the request. Please contact the Galaxy Team if this error persists.

"},batchMode:function(){return'
This is a batch mode input field. A separate job will be triggered for each dataset.';"
"}}}); \ No newline at end of file +define([],function(){return{help:function(a){return'
'+a+"
"},success:function(c){if(!c.jobs||!c.jobs.length){console.debug("tools-template::success() - Failed jobs.");return}var a=c.jobs.length;var d="";if(a==1){d="1 job has"}else{d=a+" jobs have"}var b='

'+d+" been successfully added to the queue - resulting in the following datasets:

";for(var e in c.outputs){b+='

'+(parseInt(e)+1)+": "+c.outputs[e].name+"

"}b+="

You can check the status of queued jobs and view the resulting data by refreshing the History pane. When the job has been run the status will change from 'running' to 'finished' if completed successfully or 'error' if problems were encountered.

";return b},error:function(a){return'

The server could not complete the request. Please contact the Galaxy Team if this error persists.

"},batchMode:function(){return'
This is a batch mode input field. A separate job will be triggered for each dataset.
'}}}); \ No newline at end of file