commit/galaxy-central: guerler: ToolForm: Improve collection handling
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a979bd1bb194/ Changeset: a979bd1bb194 User: guerler Date: 2014-10-08 18:32:48+00:00 Summary: ToolForm: Improve collection handling Affected #: 18 files diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa client/galaxy/scripts/mvc/tools/tools-content.js --- /dev/null +++ b/client/galaxy/scripts/mvc/tools/tools-content.js @@ -0,0 +1,132 @@ +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 = {}; + 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; + + // 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. + */ + 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]; + + // 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); + } + } + return result; + }, + + /** Get details of a content by id. + */ + getDetails: function(options) { + var api_url = this.base_url + '/datasets/' + options.id; + if (options.src == 'hdca') { + api_url = this.base_url + '/dataset_collections/' + options.id; + } + Utils.get({ + url : api_url, + success : function(response) { + options.success && options.success(response); + }, + error : function(response) { + console.debug('tools-content::getDetails() - Ajax request for content failed.'); + 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 -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa client/galaxy/scripts/mvc/tools/tools-datasets.js --- a/client/galaxy/scripts/mvc/tools/tools-datasets.js +++ /dev/null @@ -1,117 +0,0 @@ -define(['utils/utils'], function(Utils){ - return Backbone.Model.extend({ - // initialize - initialize: function(options) { - // prepare datasets obects - this.datatypes = {}; - 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 : galaxy_config.root + 'api/histories/' + options.history_id + '/contents?deleted=false', - success : function(response) { - // backup summary - self.summary = response; - - // log - console.debug('tools-datasets::initialize() - Completed.'); - - // callback - options.success && options.success(); - }, - error : function(response) { - // log request failure - console.debug('tools-datasets::initialize() - Ajax request for summary failed.'); - console.debug(response); - } - }); - }, - error : function(response) { - // log request failure - console.debug('tools-datasets::initialize() - Ajax request for datatypes failed.'); - console.debug(response); - } - }); - }, - - /** - * Filters datasets by data type. - */ - filterType: function(options) { - options = options || {}; - var result = []; - for (var i in this.summary) { - var dataset = this.summary[i]; - - // match datatypes - var found = false; - for (var i in options.data_types) { - if (this._matchType(options.data_types[i], dataset.extension)) { - found = true; - break; - } - } - - // final match result - if ((dataset.history_content_type === options.content_type || !options.content_type) && (found || !options.data_types)) { - result.push(dataset); - } - } - return result; - }, - - /** Get details of a dataset by id. - * @param{String} Dataset id - */ - getDetails: function(dataset_id, callback) { - Utils.get({ - url : galaxy_config.root + 'api/datasets/' + dataset_id, - success : function(response) { - callback && callback(response); - }, - error : function(response) { - console.debug('tools-datasets::getDetails() - Ajax request for dataset failed.'); - 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-datasets::_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-datasets::_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 -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa client/galaxy/scripts/mvc/tools/tools-form.js --- a/client/galaxy/scripts/mvc/tools/tools-form.js +++ b/client/galaxy/scripts/mvc/tools/tools-form.js @@ -3,9 +3,9 @@ */ define(['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-datasets', 'mvc/tools/tools-section', 'mvc/tools/tools-tree', 'mvc/tools/tools-jobs'], + 'mvc/tools', 'mvc/tools/tools-template', 'mvc/tools/tools-content', 'mvc/tools/tools-section', 'mvc/tools/tools-tree', 'mvc/tools/tools-jobs'], function(Portlet, Ui, CitationModel, CitationView, - Tools, ToolTemplate, ToolDatasets, ToolSection, ToolTree, ToolJobs) { + Tools, ToolTemplate, ToolContent, ToolSection, ToolTree, ToolJobs) { // create tool model var Model = Backbone.Model.extend({ @@ -61,8 +61,8 @@ // reset input element list, which contains the dom elements of each input element (includes also the input field) this.element_list = {}; - // initialize datasets - this.datasets = new ToolDatasets({ + // initialize contents + this.content = new ToolContent({ history_id : this.options.history_id, success : function() { self._initializeToolForm(); diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa client/galaxy/scripts/mvc/tools/tools-section.js --- a/client/galaxy/scripts/mvc/tools/tools-section.js +++ b/client/galaxy/scripts/mvc/tools/tools-section.js @@ -1,8 +1,8 @@ /** This class creates a tool form section and populates it with input elements. It also handles repeat blocks and conditionals by recursively creating new sub sections. New input elements can be plugged in by adding cases to the switch block defined in the _addRow() function. */ -define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/tools/tools-repeat', 'mvc/tools/tools-select-dataset'], - function(Utils, Table, Ui, Repeat, SelectDataset) { +define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/tools/tools-repeat', 'mvc/tools/tools-select-content'], + function(Utils, Table, Ui, Repeat, SelectContent) { // input field element wrapper var InputElement = Backbone.View.extend({ @@ -268,12 +268,12 @@ field = this._fieldSelect(input_def); break; - // dataset + // data selector case 'data': field = this._fieldData(input_def); break; - // dataset column + // data column case 'data_column': field = this._fieldSelect(input_def); break; @@ -417,13 +417,15 @@ var id = input_def.id; // select field - return new SelectDataset.View(this.app, { + return new SelectContent.View(this.app, { id : 'field-' + id, extensions : input_def.extensions, multiple : input_def.multiple, onchange : function(dict) { - // pick the first dataset only (todo: maybe collect multiple meta information) - var value = dict.values[0].id; + // pick the first content only (todo: maybe collect multiple meta information) + var content_def = dict.values[0]; + var content_id = content_def.id; + var content_src = content_def.src; // get referenced columns var column_list = self.app.tree.references(id, 'data_column'); @@ -440,71 +442,80 @@ column_field.wait && column_field.wait(); } - // find selected dataset - self.app.datasets.getDetails(value, function(dataset) { - // meta data - var meta = null; - - // check dataset - if (dataset) { - // log selection - console.debug('tool-form::field_data() - Selected dataset ' + value + '.'); - - // get meta data - meta = dataset.metadata_column_types; - - // check meta data - if (!meta) { - console.debug('tool-form::field_data() - FAILED: Could not find metadata for dataset ' + value + '.'); + // find selected content + self.app.content.getDetails({ + id : content_id, + src : content_src, + success : function(content) { + // select the first dataset to represent collections + if (content_src == 'hdca' && content.elements && content.elements.length > 0) { + content = content.elements[0].object; } - } else { - console.debug('tool-form::field_data() - FAILED: Could not find dataset ' + value + '.'); - } - - // update referenced columns - for (var i in column_list) { - // get column input/field - var column_input = self.app.input_list[column_list[i]]; - var column_field = self.app.field_list[column_list[i]]; - if (!column_input || !column_field) { - console.debug('tool-form::field_data() - FAILED: Column not found.'); + + // meta data + var meta = null; + + // check content + if (content) { + // log selection + console.debug('tool-form::field_data() - Selected content ' + content_id + '.'); + + // get meta data + meta = content.metadata_column_types; + + // check meta data + if (!meta) { + console.debug('tool-form::field_data() - FAILED: Could not find metadata for content ' + content_id + '.'); + } + } else { + console.debug('tool-form::field_data() - FAILED: Could not find content ' + content_id + '.'); } - - // is numerical? - var numerical = column_input.numerical; - // identify column options - var columns = []; - for (var key in meta) { - // get column type - var column_type = meta[key]; + // update referenced columns + for (var i in column_list) { + // get column input/field + var column_input = self.app.input_list[column_list[i]]; + var column_field = self.app.field_list[column_list[i]]; + if (!column_input || !column_field) { + console.debug('tool-form::field_data() - FAILED: Column not found.'); + } + + // is numerical? + var numerical = column_input.numerical; - // column index - var column_index = (parseInt(key) + 1); - - // column type label - var column_label = 'Text'; - if (column_type == 'int' || column_type == 'float') { - column_label = 'Number'; + // identify column options + var columns = []; + for (var key in meta) { + // get column type + var column_type = meta[key]; + + // column index + var column_index = (parseInt(key) + 1); + + // column type label + var column_label = 'Text'; + if (column_type == 'int' || column_type == 'float') { + column_label = 'Number'; + } + + // add to selection + if (column_type == 'int' || column_type == 'float' || !numerical) { + columns.push({ + 'label' : 'Column: ' + column_index + ' [' + column_label + ']', + 'value' : column_index + }); + } } - // add to selection - if (column_type == 'int' || column_type == 'float' || !numerical) { - columns.push({ - 'label' : 'Column: ' + column_index + ' [' + column_label + ']', - 'value' : column_index - }); + // update field + if (column_field) { + column_field.update(columns); + if (!column_field.exists(column_field.value())) { + column_field.value(column_field.first()); + } + column_field.show(); } } - - // update field - if (column_field) { - column_field.update(columns); - if (!column_field.exists(column_field.value())) { - column_field.value(column_field.first()); - } - column_field.show(); - } } }); } diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa client/galaxy/scripts/mvc/tools/tools-select-content.js --- /dev/null +++ b/client/galaxy/scripts/mvc/tools/tools-select-content.js @@ -0,0 +1,172 @@ +// dependencies +define(['utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs', 'mvc/tools/tools-template'], function(Utils, Ui, Tabs, ToolTemplate) { + +var View = Backbone.View.extend({ + // initialize + initialize : function(app, options) { + // configure options + this.options = options; + + // link this + var self = this; + + // add element + this.setElement('<div/>'); + + // current selection + this.current = 'hda'; + + // create button + this.button_new = 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' }], + onchange: function(value) { + self.current = value; + self.refresh(); + self.trigger('change'); + } + }); + + // + // datasets + // + var datasets = app.content.filterType({ + src : 'hda', + extensions : options.extensions + }); + + // configure options fields + var dataset_options = []; + for (var i in datasets) { + dataset_options.push({ + label: datasets[i].name, + value: datasets[i].id + }); + } + + // select field + this.select_datasets = 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].name, + value: collections[i].id + }); + } + + // create select field for collections + this.select_collection = new Ui.Select.View({ + data : collection_options, + value : collection_options[0] && collection_options[0].value, + onchange : function() { + self.trigger('change'); + } + }); + + // 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()); + } + + // refresh view + this.refresh(); + + // add change event. fires on trigger + this.on('change', function() { + if (options.onchange) { + options.onchange(self.value()); + } + }); + }, + + /** Return the currently selected dataset values */ + value : function () { + // identify select element + var select = null; + switch(this.current) { + case 'hda': + select = this.select_datasets; + break; + case 'hdca': + select = this.select_collection; + break; + } + + // transform into an array + var id_list = select.value(); + if (!(id_list instanceof Array)) { + id_list = [id_list]; + } + + // prepare result dict + var result = { + batch : !this.options.multiple, + values : [] + } + + // append to dataset ids + for (var i in id_list) { + result.values.push({ + id : id_list[i], + src : this.current + }); + } + + // return + return result; + }, + + /** Validate current selection + */ + validate: function() { + switch(this.current) { + case 'hda': + return this.select_datasets.validate(); + case 'hdca': + return this.select_collection.validate(); + } + }, + + /** 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; + } + } +}); + +return { + View: View +} + +}); diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa client/galaxy/scripts/mvc/tools/tools-select-dataset.js --- a/client/galaxy/scripts/mvc/tools/tools-select-dataset.js +++ /dev/null @@ -1,172 +0,0 @@ -// dependencies -define(['utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs', 'mvc/tools/tools-template'], function(Utils, Ui, Tabs, ToolTemplate) { - -var View = Backbone.View.extend({ - // initialize - initialize : function(app, options) { - // configure options - this.options = options; - - // link this - var self = this; - - // add element - this.setElement('<div/>'); - - // current selection - this.current = 'hda'; - - // create button - this.button_new = 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' }], - onchange: function(value) { - self.current = value; - self.refresh(); - self.trigger('change'); - } - }); - - // - // datasets - // - var datasets = app.datasets.filterType({ - content_type : 'dataset', - data_types : options.extensions - }); - - // configure options fields - var dataset_options = []; - for (var i in datasets) { - dataset_options.push({ - label: datasets[i].name, - value: datasets[i].id - }); - } - - // select field - this.select_datasets = 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.datasets.filterType({ - content_type : 'collection', - data_types : options.extensions - }); - - // configure options fields - var collection_options = []; - for (var i in collections) { - collection_options.push({ - label: collections[i].name, - value: collections[i].id - }); - } - - // create select field for collections - this.select_collection = new Ui.Select.View({ - data : collection_options, - value : collection_options[0] && collection_options[0].value, - onchange : function() { - self.trigger('change'); - } - }); - - // 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()); - } - - // refresh view - this.refresh(); - - // add change event. fires on trigger - this.on('change', function() { - if (options.onchange) { - options.onchange(self.value()); - } - }); - }, - - /** Return the currently selected dataset values */ - value : function () { - // identify select element - var select = null; - switch(this.current) { - case 'hda': - select = this.select_datasets; - break; - case 'hdca': - select = this.select_collection; - break; - } - - // transform into an array - var id_list = select.value(); - if (!(id_list instanceof Array)) { - id_list = [id_list]; - } - - // prepare result dict - var result = { - batch : !this.options.multiple, - values : [] - } - - // append to dataset ids - for (var i in id_list) { - result.values.push({ - id : id_list[i], - src : this.current - }); - } - - // return - return result; - }, - - /** Validate current selection - */ - validate: function() { - switch(this.current) { - case 'hda': - return this.select_datasets.validate(); - case 'hdca': - return this.select_collection.validate(); - } - }, - - /** 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; - } - } -}); - -return { - View: View -} - -}); diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/mvc/tools/tools-content.js --- /dev/null +++ b/static/scripts/mvc/tools/tools-content.js @@ -0,0 +1,132 @@ +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 = {}; + 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; + + // 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. + */ + 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]; + + // 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); + } + } + return result; + }, + + /** Get details of a content by id. + */ + getDetails: function(options) { + var api_url = this.base_url + '/datasets/' + options.id; + if (options.src == 'hdca') { + api_url = this.base_url + '/dataset_collections/' + options.id; + } + Utils.get({ + url : api_url, + success : function(response) { + options.success && options.success(response); + }, + error : function(response) { + console.debug('tools-content::getDetails() - Ajax request for content failed.'); + 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 -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/mvc/tools/tools-datasets.js --- a/static/scripts/mvc/tools/tools-datasets.js +++ /dev/null @@ -1,117 +0,0 @@ -define(['utils/utils'], function(Utils){ - return Backbone.Model.extend({ - // initialize - initialize: function(options) { - // prepare datasets obects - this.datatypes = {}; - 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 : galaxy_config.root + 'api/histories/' + options.history_id + '/contents?deleted=false', - success : function(response) { - // backup summary - self.summary = response; - - // log - console.debug('tools-datasets::initialize() - Completed.'); - - // callback - options.success && options.success(); - }, - error : function(response) { - // log request failure - console.debug('tools-datasets::initialize() - Ajax request for summary failed.'); - console.debug(response); - } - }); - }, - error : function(response) { - // log request failure - console.debug('tools-datasets::initialize() - Ajax request for datatypes failed.'); - console.debug(response); - } - }); - }, - - /** - * Filters datasets by data type. - */ - filterType: function(options) { - options = options || {}; - var result = []; - for (var i in this.summary) { - var dataset = this.summary[i]; - - // match datatypes - var found = false; - for (var i in options.data_types) { - if (this._matchType(options.data_types[i], dataset.extension)) { - found = true; - break; - } - } - - // final match result - if ((dataset.history_content_type === options.content_type || !options.content_type) && (found || !options.data_types)) { - result.push(dataset); - } - } - return result; - }, - - /** Get details of a dataset by id. - * @param{String} Dataset id - */ - getDetails: function(dataset_id, callback) { - Utils.get({ - url : galaxy_config.root + 'api/datasets/' + dataset_id, - success : function(response) { - callback && callback(response); - }, - error : function(response) { - console.debug('tools-datasets::getDetails() - Ajax request for dataset failed.'); - 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-datasets::_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-datasets::_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 -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/mvc/tools/tools-form.js --- a/static/scripts/mvc/tools/tools-form.js +++ b/static/scripts/mvc/tools/tools-form.js @@ -3,9 +3,9 @@ */ define(['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-datasets', 'mvc/tools/tools-section', 'mvc/tools/tools-tree', 'mvc/tools/tools-jobs'], + 'mvc/tools', 'mvc/tools/tools-template', 'mvc/tools/tools-content', 'mvc/tools/tools-section', 'mvc/tools/tools-tree', 'mvc/tools/tools-jobs'], function(Portlet, Ui, CitationModel, CitationView, - Tools, ToolTemplate, ToolDatasets, ToolSection, ToolTree, ToolJobs) { + Tools, ToolTemplate, ToolContent, ToolSection, ToolTree, ToolJobs) { // create tool model var Model = Backbone.Model.extend({ @@ -61,8 +61,8 @@ // reset input element list, which contains the dom elements of each input element (includes also the input field) this.element_list = {}; - // initialize datasets - this.datasets = new ToolDatasets({ + // initialize contents + this.content = new ToolContent({ history_id : this.options.history_id, success : function() { self._initializeToolForm(); diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/mvc/tools/tools-section.js --- a/static/scripts/mvc/tools/tools-section.js +++ b/static/scripts/mvc/tools/tools-section.js @@ -1,8 +1,8 @@ /** This class creates a tool form section and populates it with input elements. It also handles repeat blocks and conditionals by recursively creating new sub sections. New input elements can be plugged in by adding cases to the switch block defined in the _addRow() function. */ -define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/tools/tools-repeat', 'mvc/tools/tools-select-dataset'], - function(Utils, Table, Ui, Repeat, SelectDataset) { +define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/tools/tools-repeat', 'mvc/tools/tools-select-content'], + function(Utils, Table, Ui, Repeat, SelectContent) { // input field element wrapper var InputElement = Backbone.View.extend({ @@ -268,12 +268,12 @@ field = this._fieldSelect(input_def); break; - // dataset + // data selector case 'data': field = this._fieldData(input_def); break; - // dataset column + // data column case 'data_column': field = this._fieldSelect(input_def); break; @@ -417,13 +417,15 @@ var id = input_def.id; // select field - return new SelectDataset.View(this.app, { + return new SelectContent.View(this.app, { id : 'field-' + id, extensions : input_def.extensions, multiple : input_def.multiple, onchange : function(dict) { - // pick the first dataset only (todo: maybe collect multiple meta information) - var value = dict.values[0].id; + // pick the first content only (todo: maybe collect multiple meta information) + var content_def = dict.values[0]; + var content_id = content_def.id; + var content_src = content_def.src; // get referenced columns var column_list = self.app.tree.references(id, 'data_column'); @@ -440,71 +442,80 @@ column_field.wait && column_field.wait(); } - // find selected dataset - self.app.datasets.getDetails(value, function(dataset) { - // meta data - var meta = null; - - // check dataset - if (dataset) { - // log selection - console.debug('tool-form::field_data() - Selected dataset ' + value + '.'); - - // get meta data - meta = dataset.metadata_column_types; - - // check meta data - if (!meta) { - console.debug('tool-form::field_data() - FAILED: Could not find metadata for dataset ' + value + '.'); + // find selected content + self.app.content.getDetails({ + id : content_id, + src : content_src, + success : function(content) { + // select the first dataset to represent collections + if (content_src == 'hdca' && content.elements && content.elements.length > 0) { + content = content.elements[0].object; } - } else { - console.debug('tool-form::field_data() - FAILED: Could not find dataset ' + value + '.'); - } - - // update referenced columns - for (var i in column_list) { - // get column input/field - var column_input = self.app.input_list[column_list[i]]; - var column_field = self.app.field_list[column_list[i]]; - if (!column_input || !column_field) { - console.debug('tool-form::field_data() - FAILED: Column not found.'); + + // meta data + var meta = null; + + // check content + if (content) { + // log selection + console.debug('tool-form::field_data() - Selected content ' + content_id + '.'); + + // get meta data + meta = content.metadata_column_types; + + // check meta data + if (!meta) { + console.debug('tool-form::field_data() - FAILED: Could not find metadata for content ' + content_id + '.'); + } + } else { + console.debug('tool-form::field_data() - FAILED: Could not find content ' + content_id + '.'); } - - // is numerical? - var numerical = column_input.numerical; - // identify column options - var columns = []; - for (var key in meta) { - // get column type - var column_type = meta[key]; + // update referenced columns + for (var i in column_list) { + // get column input/field + var column_input = self.app.input_list[column_list[i]]; + var column_field = self.app.field_list[column_list[i]]; + if (!column_input || !column_field) { + console.debug('tool-form::field_data() - FAILED: Column not found.'); + } + + // is numerical? + var numerical = column_input.numerical; - // column index - var column_index = (parseInt(key) + 1); - - // column type label - var column_label = 'Text'; - if (column_type == 'int' || column_type == 'float') { - column_label = 'Number'; + // identify column options + var columns = []; + for (var key in meta) { + // get column type + var column_type = meta[key]; + + // column index + var column_index = (parseInt(key) + 1); + + // column type label + var column_label = 'Text'; + if (column_type == 'int' || column_type == 'float') { + column_label = 'Number'; + } + + // add to selection + if (column_type == 'int' || column_type == 'float' || !numerical) { + columns.push({ + 'label' : 'Column: ' + column_index + ' [' + column_label + ']', + 'value' : column_index + }); + } } - // add to selection - if (column_type == 'int' || column_type == 'float' || !numerical) { - columns.push({ - 'label' : 'Column: ' + column_index + ' [' + column_label + ']', - 'value' : column_index - }); + // update field + if (column_field) { + column_field.update(columns); + if (!column_field.exists(column_field.value())) { + column_field.value(column_field.first()); + } + column_field.show(); } } - - // update field - if (column_field) { - column_field.update(columns); - if (!column_field.exists(column_field.value())) { - column_field.value(column_field.first()); - } - column_field.show(); - } } }); } diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/mvc/tools/tools-select-content.js --- /dev/null +++ b/static/scripts/mvc/tools/tools-select-content.js @@ -0,0 +1,172 @@ +// dependencies +define(['utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs', 'mvc/tools/tools-template'], function(Utils, Ui, Tabs, ToolTemplate) { + +var View = Backbone.View.extend({ + // initialize + initialize : function(app, options) { + // configure options + this.options = options; + + // link this + var self = this; + + // add element + this.setElement('<div/>'); + + // current selection + this.current = 'hda'; + + // create button + this.button_new = 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' }], + onchange: function(value) { + self.current = value; + self.refresh(); + self.trigger('change'); + } + }); + + // + // datasets + // + var datasets = app.content.filterType({ + src : 'hda', + extensions : options.extensions + }); + + // configure options fields + var dataset_options = []; + for (var i in datasets) { + dataset_options.push({ + label: datasets[i].name, + value: datasets[i].id + }); + } + + // select field + this.select_datasets = 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].name, + value: collections[i].id + }); + } + + // create select field for collections + this.select_collection = new Ui.Select.View({ + data : collection_options, + value : collection_options[0] && collection_options[0].value, + onchange : function() { + self.trigger('change'); + } + }); + + // 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()); + } + + // refresh view + this.refresh(); + + // add change event. fires on trigger + this.on('change', function() { + if (options.onchange) { + options.onchange(self.value()); + } + }); + }, + + /** Return the currently selected dataset values */ + value : function () { + // identify select element + var select = null; + switch(this.current) { + case 'hda': + select = this.select_datasets; + break; + case 'hdca': + select = this.select_collection; + break; + } + + // transform into an array + var id_list = select.value(); + if (!(id_list instanceof Array)) { + id_list = [id_list]; + } + + // prepare result dict + var result = { + batch : !this.options.multiple, + values : [] + } + + // append to dataset ids + for (var i in id_list) { + result.values.push({ + id : id_list[i], + src : this.current + }); + } + + // return + return result; + }, + + /** Validate current selection + */ + validate: function() { + switch(this.current) { + case 'hda': + return this.select_datasets.validate(); + case 'hdca': + return this.select_collection.validate(); + } + }, + + /** 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; + } + } +}); + +return { + View: View +} + +}); diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/mvc/tools/tools-select-dataset.js --- a/static/scripts/mvc/tools/tools-select-dataset.js +++ /dev/null @@ -1,172 +0,0 @@ -// dependencies -define(['utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs', 'mvc/tools/tools-template'], function(Utils, Ui, Tabs, ToolTemplate) { - -var View = Backbone.View.extend({ - // initialize - initialize : function(app, options) { - // configure options - this.options = options; - - // link this - var self = this; - - // add element - this.setElement('<div/>'); - - // current selection - this.current = 'hda'; - - // create button - this.button_new = 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' }], - onchange: function(value) { - self.current = value; - self.refresh(); - self.trigger('change'); - } - }); - - // - // datasets - // - var datasets = app.datasets.filterType({ - content_type : 'dataset', - data_types : options.extensions - }); - - // configure options fields - var dataset_options = []; - for (var i in datasets) { - dataset_options.push({ - label: datasets[i].name, - value: datasets[i].id - }); - } - - // select field - this.select_datasets = 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.datasets.filterType({ - content_type : 'collection', - data_types : options.extensions - }); - - // configure options fields - var collection_options = []; - for (var i in collections) { - collection_options.push({ - label: collections[i].name, - value: collections[i].id - }); - } - - // create select field for collections - this.select_collection = new Ui.Select.View({ - data : collection_options, - value : collection_options[0] && collection_options[0].value, - onchange : function() { - self.trigger('change'); - } - }); - - // 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()); - } - - // refresh view - this.refresh(); - - // add change event. fires on trigger - this.on('change', function() { - if (options.onchange) { - options.onchange(self.value()); - } - }); - }, - - /** Return the currently selected dataset values */ - value : function () { - // identify select element - var select = null; - switch(this.current) { - case 'hda': - select = this.select_datasets; - break; - case 'hdca': - select = this.select_collection; - break; - } - - // transform into an array - var id_list = select.value(); - if (!(id_list instanceof Array)) { - id_list = [id_list]; - } - - // prepare result dict - var result = { - batch : !this.options.multiple, - values : [] - } - - // append to dataset ids - for (var i in id_list) { - result.values.push({ - id : id_list[i], - src : this.current - }); - } - - // return - return result; - }, - - /** Validate current selection - */ - validate: function() { - switch(this.current) { - case 'hda': - return this.select_datasets.validate(); - case 'hdca': - return this.select_collection.validate(); - } - }, - - /** 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; - } - } -}); - -return { - View: View -} - -}); diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/packed/mvc/tools/tools-content.js --- /dev/null +++ b/static/scripts/packed/mvc/tools/tools-content.js @@ -0,0 +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;console.debug("tools-content::initialize() - Completed.");c.success&&c.success()},error:function(e){console.debug("tools-content::initialize() - Ajax request for summary failed.");console.debug(e)}})},error:function(d){console.debug("tools-content::initialize() - Ajax request for datatypes failed.");console.debug(d)}})},filterType:function(c){c=c||{};var b=[];var g="dataset";if(c.src=="hdca"){g="dataset_collection"}for(var d in this.summary){var e=this.summary[d];var f=false;for(var d in c.extensions){if(this._matchType(c.extensions[d],e.extension)){f=true;break}}if((e.history_content_type===g)&&(f||!c.extensions)){b.push(e)}}return b},getDetails:function(b){var c=this.base_url+"/datasets/"+b.id;if(b.src=="hdca"){c=this.base_url+"/dataset_collections/"+b.id}a.get({url:c,success:function(d){b.success&&b.success(d)},error:function(d){console.debug("tools-content::getDetails() - Ajax request for content failed.");console.debug(d)}})},_matchType:function(f,b){var c=this.datatypes.ext_to_class_name[f];if(!c){console.debug("tools-content::_matchType() - Specific target class unavailable. Accepting all formats.");return true}var d=this.datatypes.ext_to_class_name[b];if(!d){console.debug("tools-content::_matchType() - Specific reference class unavailable. Accepting all formats.");return true}var e=this.datatypes.class_to_classes[d];if(e[c]){return true}return false}})}); \ No newline at end of file diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/packed/mvc/tools/tools-datasets.js --- a/static/scripts/packed/mvc/tools/tools-datasets.js +++ /dev/null @@ -1,1 +0,0 @@ -define(["utils/utils"],function(a){return Backbone.Model.extend({initialize:function(c){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:galaxy_config.root+"api/histories/"+c.history_id+"/contents?deleted=false",success:function(e){b.summary=e;console.debug("tools-datasets::initialize() - Completed.");c.success&&c.success()},error:function(e){console.debug("tools-datasets::initialize() - Ajax request for summary failed.");console.debug(e)}})},error:function(d){console.debug("tools-datasets::initialize() - Ajax request for datatypes failed.");console.debug(d)}})},filterType:function(c){c=c||{};var b=[];for(var d in this.summary){var f=this.summary[d];var e=false;for(var d in c.data_types){if(this._matchType(c.data_types[d],f.extension)){e=true;break}}if((f.history_content_type===c.content_type||!c.content_type)&&(e||!c.data_types)){b.push(f)}}return b},getDetails:function(b,c){a.get({url:galaxy_config.root+"api/datasets/"+b,success:function(d){c&&c(d)},error:function(d){console.debug("tools-datasets::getDetails() - Ajax request for dataset failed.");console.debug(d)}})},_matchType:function(f,b){var c=this.datatypes.ext_to_class_name[f];if(!c){console.debug("tools-datasets::_matchType() - Specific target class unavailable. Accepting all formats.");return true}var d=this.datatypes.ext_to_class_name[b];if(!d){console.debug("tools-datasets::_matchType() - Specific reference class unavailable. Accepting all formats.");return true}var e=this.datatypes.class_to_classes[d];if(e[c]){return true}return false}})}); \ No newline at end of file diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/packed/mvc/tools/tools-form.js --- a/static/scripts/packed/mvc/tools/tools-form.js +++ b/static/scripts/packed/mvc/tools/tools-form.js @@ -1,1 +1,1 @@ -define(["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-datasets","mvc/tools/tools-section","mvc/tools/tools-tree","mvc/tools/tools-jobs"],function(h,l,j,a,f,d,i,k,c,g){var e=Backbone.Model.extend({initialize:function(m){this.url=galaxy_config.root+"api/tools/"+m.id+"?io_details=true"}});var b=Backbone.View.extend({container:"body",initialize:function(n){var m=this;if(parent.Galaxy&&parent.Galaxy.modal){this.modal=parent.Galaxy.modal}else{this.modal=new l.Modal.View()}this.options=n;this.setElement("<div/>");$(this.container).append(this.$el);this.model=new e({id:n.id,job_id:n.job_id});this.tree=new c(this);this.job_handler=new g(this);this.field_list={};this.input_list={};this.element_list={};this.datasets=new i({history_id:this.options.history_id,success:function(){m._initializeToolForm()}})},message:function(m){$(this.container).empty();$(this.container).append(m)},reset:function(){for(var m in this.element_list){this.element_list[m].reset()}},refresh:function(){this.tree.refresh();for(var m in this.field_list){this.field_list[m].trigger("change")}console.debug("tools-form::refresh() - Recreated data structure. Refresh.")},_initializeToolForm:function(){var n=this;var p=new l.ButtonIcon({icon:"fa-question-circle",title:"Question?",tooltip:"Ask a question about this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/p/new/post/")}});var q=new l.ButtonIcon({icon:"fa-search",title:"Search",tooltip:"Search help for this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/t/"+n.options.id+"/")}});var m=new l.ButtonIcon({icon:"fa-share",title:"Share",tooltip:"Share this tool",onclick:function(){prompt("Copy to clipboard: Ctrl+C, Enter",galaxy_config.root+"root?tool_id="+n.options.id)}});var o={button_question:p,button_search:q,button_share:m};if(Galaxy.currUser.get("is_admin")){o.button_download=new l.ButtonIcon({icon:"fa-download",title:"Download",tooltip:"Download this tool",onclick:function(){window.location.href=galaxy_config.root+"api/tools/"+n.options.id+"/download"}})}this.model.fetch({error:function(r){console.debug("tools-form::_initializeToolForm() : Attempt to fetch tool model failed.")},success:function(){n.section=new k.View(n,{inputs:n.model.get("inputs"),cls:"ui-table-plain"});if(n.incompatible){n.$el.hide();$("#tool-form-classic").show();return}n.portlet=new h.View({icon:"fa-wrench",title:"<b>"+n.model.get("name")+"</b> "+n.model.get("description"),operations:o,buttons:{execute:new l.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){n.job_handler.submit()}})}});if(!n.options.biostar_url){p.$el.hide();q.$el.hide()}n.$el.append(n.portlet.$el);if(n.options.help!=""){n.$el.append(d.help(n.options.help))}if(n.options.citations){n.$el.append(d.citations());var r=new j.ToolCitationCollection();r.tool_id=n.options.id;var s=new a.CitationListView({collection:r});s.render();r.fetch()}n.portlet.append(n.section.$el);n.refresh()}})}});return{View:b}}); \ No newline at end of file +define(["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,l,j,a,f,d,g,k,c,h){var e=Backbone.Model.extend({initialize:function(m){this.url=galaxy_config.root+"api/tools/"+m.id+"?io_details=true"}});var b=Backbone.View.extend({container:"body",initialize:function(n){var m=this;if(parent.Galaxy&&parent.Galaxy.modal){this.modal=parent.Galaxy.modal}else{this.modal=new l.Modal.View()}this.options=n;this.setElement("<div/>");$(this.container).append(this.$el);this.model=new e({id:n.id,job_id:n.job_id});this.tree=new c(this);this.job_handler=new h(this);this.field_list={};this.input_list={};this.element_list={};this.content=new g({history_id:this.options.history_id,success:function(){m._initializeToolForm()}})},message:function(m){$(this.container).empty();$(this.container).append(m)},reset:function(){for(var m in this.element_list){this.element_list[m].reset()}},refresh:function(){this.tree.refresh();for(var m in this.field_list){this.field_list[m].trigger("change")}console.debug("tools-form::refresh() - Recreated data structure. Refresh.")},_initializeToolForm:function(){var n=this;var p=new l.ButtonIcon({icon:"fa-question-circle",title:"Question?",tooltip:"Ask a question about this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/p/new/post/")}});var q=new l.ButtonIcon({icon:"fa-search",title:"Search",tooltip:"Search help for this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/t/"+n.options.id+"/")}});var m=new l.ButtonIcon({icon:"fa-share",title:"Share",tooltip:"Share this tool",onclick:function(){prompt("Copy to clipboard: Ctrl+C, Enter",galaxy_config.root+"root?tool_id="+n.options.id)}});var o={button_question:p,button_search:q,button_share:m};if(Galaxy.currUser.get("is_admin")){o.button_download=new l.ButtonIcon({icon:"fa-download",title:"Download",tooltip:"Download this tool",onclick:function(){window.location.href=galaxy_config.root+"api/tools/"+n.options.id+"/download"}})}this.model.fetch({error:function(r){console.debug("tools-form::_initializeToolForm() : Attempt to fetch tool model failed.")},success:function(){n.section=new k.View(n,{inputs:n.model.get("inputs"),cls:"ui-table-plain"});if(n.incompatible){n.$el.hide();$("#tool-form-classic").show();return}n.portlet=new i.View({icon:"fa-wrench",title:"<b>"+n.model.get("name")+"</b> "+n.model.get("description"),operations:o,buttons:{execute:new l.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){n.job_handler.submit()}})}});if(!n.options.biostar_url){p.$el.hide();q.$el.hide()}n.$el.append(n.portlet.$el);if(n.options.help!=""){n.$el.append(d.help(n.options.help))}if(n.options.citations){n.$el.append(d.citations());var r=new j.ToolCitationCollection();r.tool_id=n.options.id;var s=new a.CitationListView({collection:r});s.render();r.fetch()}n.portlet.append(n.section.$el);n.refresh()}})}});return{View:b}}); \ No newline at end of file diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/packed/mvc/tools/tools-section.js --- a/static/scripts/packed/mvc/tools/tools-section.js +++ b/static/scripts/packed/mvc/tools/tools-section.js @@ -1,1 +1,1 @@ -define(["utils/utils","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/tools/tools-repeat","mvc/tools/tools-select-dataset"],function(d,a,g,c,b){var e=Backbone.View.extend({initialize:function(h){this.setElement(this._template(h))},error:function(h){this.$el.find(".ui-table-form-error-text").html(h);this.$el.find(".ui-table-form-error").fadeIn();this.$el.addClass("ui-error")},reset:function(){this.$el.find(".ui-table-form-error").hide();this.$el.removeClass("ui-error")},_template:function(h){var i=$('<div class="ui-table-element"/>');i.append('<div class="ui-table-form-error ui-error"><span class="fa fa-arrow-down"/><span class="ui-table-form-error-text"></div>');if(h.label){i.append('<div class="ui-table-form-title-strong">'+h.label+"</div>")}i.append(h.$el);if(h.help){i.append('<div class="ui-table-form-info">'+h.help+"</div>")}return i}});var f=Backbone.View.extend({initialize:function(i,h){this.app=i;this.inputs=h.inputs;h.cls_tr="section-row";this.table=new a.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=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(k,h)}},_addConditional:function(h){h.label=h.test_param.label;h.value=h.test_param.value;var j=this._addRow("conditional",h);for(var l in h.cases){var k=h.id+"-section-"+l;var m=new f(this.app,{inputs:h.cases[l].inputs,cls:"ui-table-plain"});m.$el.addClass("ui-table-form-section");this.table.add(m.$el);this.table.append(k)}},_addRepeat:function(h){var j=this;var n=0;var m=new c.View({title_new:h.title,max:h.max,onnew:function(){var i=h.id+"-section-"+(n++);var q=new f(j.app,{inputs:h.inputs,cls:"ui-table-plain"});m.add({id:i,title:h.title,$el:q.$el,ondel:function(){m.del(i);m.retitle(h.title);j.app.refresh()}});m.retitle(h.title);j.app.refresh()}});for(var l=0;l<h.min;l++){var k=h.id+"-section-"+(n++);var p=new f(j.app,{inputs:h.inputs,cls:"ui-table-plain"});m.add({id:k,title:h.title,$el:p.$el})}m.retitle(h.title);var o=new e({label:h.title,help:h.help,$el:m.$el});o.$el.addClass("ui-table-form-section");this.table.add(o.$el);this.table.append(h.id)},_addRow:function(j,h){var l=h.id;var i=null;switch(j){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"conditional":i=this._fieldConditional(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 ("+j+").")}if(h.value!==undefined){i.value(h.value)}this.app.field_list[l]=i;var k=new e({label:h.label,help:h.help,$el:i.$el});this.app.element_list[l]=k;this.table.add(k.$el);this.table.append(l);return this.table.get(l)},_fieldConditional:function(h){var j=this;var k=[];for(var l in h.test_param.options){var m=h.test_param.options[l];k.push({label:m[0],value:m[1]})}return new g.Select.View({id:"field-"+h.id,data:k,onchange:function(u){for(var s in h.cases){var o=h.cases[s];var r=h.id+"-section-"+s;var n=j.table.get(r);var q=false;for(var p in o.inputs){var t=o.inputs[p].type;if(t&&t!=="hidden"){q=true;break}}if(o.value==u&&q){n.fadeIn("fast")}else{n.hide()}}}})},_fieldData:function(h){var i=this;var j=h.id;return new b.View(this.app,{id:"field-"+j,extensions:h.extensions,multiple:h.multiple,onchange:function(o){var n=o.values[0].id;var l=i.app.tree.references(j,"data_column");if(l.length<=0){console.debug("tool-form::field_data() - Data column parameters unavailable.");return}for(var m in l){var k=i.app.field_list[l[m]];k.wait&&k.wait()}i.app.datasets.getDetails(n,function(r){var z=null;if(r){console.debug("tool-form::field_data() - Selected dataset "+n+".");z=r.metadata_column_types;if(!z){console.debug("tool-form::field_data() - FAILED: Could not find metadata for dataset "+n+".")}}else{console.debug("tool-form::field_data() - FAILED: Could not find dataset "+n+".")}for(var t in l){var v=i.app.input_list[l[t]];var w=i.app.field_list[l[t]];if(!v||!w){console.debug("tool-form::field_data() - FAILED: Column not found.")}var s=v.numerical;var q=[];for(var y in z){var x=z[y];var p=(parseInt(y)+1);var u="Text";if(x=="int"||x=="float"){u="Number"}if(x=="int"||x=="float"||!s){q.push({label:"Column: "+p+" ["+u+"]",value:p})}}if(w){w.update(q);if(!w.exists(w.value())){w.value(w.first())}w.show()}}})}})},_fieldSelect:function(h){var j=[];for(var k in h.options){var l=h.options[k];j.push({label:l[0],value:l[1]})}var m=g.Select;switch(h.display){case"checkboxes":m=g.Checkbox;break;case"radio":m=g.Radio;break}return new m.View({id:"field-"+h.id,data:j,multiple:h.multiple})},_fieldText:function(h){return new g.Input({id:"field-"+h.id,area:h.area})},_fieldSlider:function(h){h.min=h.min||0;h.max=h.max||100000;var i=1;if(h.type=="float"){i=(h.max-h.min)/10000}return new g.Slider.View({id:"field-"+h.id,min:h.min,max:h.max,step:i})},_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"],function(d,b,g,c,a){var e=Backbone.View.extend({initialize:function(h){this.setElement(this._template(h))},error:function(h){this.$el.find(".ui-table-form-error-text").html(h);this.$el.find(".ui-table-form-error").fadeIn();this.$el.addClass("ui-error")},reset:function(){this.$el.find(".ui-table-form-error").hide();this.$el.removeClass("ui-error")},_template:function(h){var i=$('<div class="ui-table-element"/>');i.append('<div class="ui-table-form-error ui-error"><span class="fa fa-arrow-down"/><span class="ui-table-form-error-text"></div>');if(h.label){i.append('<div class="ui-table-form-title-strong">'+h.label+"</div>")}i.append(h.$el);if(h.help){i.append('<div class="ui-table-form-info">'+h.help+"</div>")}return i}});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=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(k,h)}},_addConditional:function(h){h.label=h.test_param.label;h.value=h.test_param.value;var j=this._addRow("conditional",h);for(var l in h.cases){var k=h.id+"-section-"+l;var m=new f(this.app,{inputs:h.cases[l].inputs,cls:"ui-table-plain"});m.$el.addClass("ui-table-form-section");this.table.add(m.$el);this.table.append(k)}},_addRepeat:function(h){var j=this;var n=0;var m=new c.View({title_new:h.title,max:h.max,onnew:function(){var i=h.id+"-section-"+(n++);var q=new f(j.app,{inputs:h.inputs,cls:"ui-table-plain"});m.add({id:i,title:h.title,$el:q.$el,ondel:function(){m.del(i);m.retitle(h.title);j.app.refresh()}});m.retitle(h.title);j.app.refresh()}});for(var l=0;l<h.min;l++){var k=h.id+"-section-"+(n++);var p=new f(j.app,{inputs:h.inputs,cls:"ui-table-plain"});m.add({id:k,title:h.title,$el:p.$el})}m.retitle(h.title);var o=new e({label:h.title,help:h.help,$el:m.$el});o.$el.addClass("ui-table-form-section");this.table.add(o.$el);this.table.append(h.id)},_addRow:function(j,h){var l=h.id;var i=null;switch(j){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"conditional":i=this._fieldConditional(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 ("+j+").")}if(h.value!==undefined){i.value(h.value)}this.app.field_list[l]=i;var k=new e({label:h.label,help:h.help,$el:i.$el});this.app.element_list[l]=k;this.table.add(k.$el);this.table.append(l);return this.table.get(l)},_fieldConditional:function(h){var j=this;var k=[];for(var l in h.test_param.options){var m=h.test_param.options[l];k.push({label:m[0],value:m[1]})}return new g.Select.View({id:"field-"+h.id,data:k,onchange:function(u){for(var s in h.cases){var o=h.cases[s];var r=h.id+"-section-"+s;var n=j.table.get(r);var q=false;for(var p in o.inputs){var t=o.inputs[p].type;if(t&&t!=="hidden"){q=true;break}}if(o.value==u&&q){n.fadeIn("fast")}else{n.hide()}}}})},_fieldData:function(h){var i=this;var j=h.id;return new a.View(this.app,{id:"field-"+j,extensions:h.extensions,multiple:h.multiple,onchange:function(q){var o=q.values[0];var m=o.id;var p=o.src;var l=i.app.tree.references(j,"data_column");if(l.length<=0){console.debug("tool-form::field_data() - Data column parameters unavailable.");return}for(var n in l){var k=i.app.field_list[l[n]];k.wait&&k.wait()}i.app.content.getDetails({id:m,src:p,success:function(y){if(p=="hdca"&&y.elements&&y.elements.length>0){y=y.elements[0].object}var B=null;if(y){console.debug("tool-form::field_data() - Selected content "+m+".");B=y.metadata_column_types;if(!B){console.debug("tool-form::field_data() - FAILED: Could not find metadata for content "+m+".")}}else{console.debug("tool-form::field_data() - FAILED: Could not find content "+m+".")}for(var u in l){var w=i.app.input_list[l[u]];var x=i.app.field_list[l[u]];if(!w||!x){console.debug("tool-form::field_data() - FAILED: Column not found.")}var t=w.numerical;var s=[];for(var A in B){var z=B[A];var r=(parseInt(A)+1);var v="Text";if(z=="int"||z=="float"){v="Number"}if(z=="int"||z=="float"||!t){s.push({label:"Column: "+r+" ["+v+"]",value:r})}}if(x){x.update(s);if(!x.exists(x.value())){x.value(x.first())}x.show()}}}})}})},_fieldSelect:function(h){var j=[];for(var k in h.options){var l=h.options[k];j.push({label:l[0],value:l[1]})}var m=g.Select;switch(h.display){case"checkboxes":m=g.Checkbox;break;case"radio":m=g.Radio;break}return new m.View({id:"field-"+h.id,data:j,multiple:h.multiple})},_fieldText:function(h){return new g.Input({id:"field-"+h.id,area:h.area})},_fieldSlider:function(h){h.min=h.min||0;h.max=h.max||100000;var i=1;if(h.type=="float"){i=(h.max-h.min)/10000}return new g.Slider.View({id:"field-"+h.id,min:h.min,max:h.max,step:i})},_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 -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/packed/mvc/tools/tools-select-content.js --- /dev/null +++ b/static/scripts/packed/mvc/tools/tools-select-content.js @@ -0,0 +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("<div/>");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].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].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(){var g=null;switch(this.current){case"hda":g=this.select_datasets;break;case"hdca":g=this.select_collection;break}var j=g.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(){switch(this.current){case"hda":return this.select_datasets.validate();case"hdca":return this.select_collection.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}}});return{View:d}}); \ No newline at end of file diff -r 0e99c30878af56e23f447854a7ae70b412a9d627 -r a979bd1bb19498aa93eb7da56f7a392bea14dfaa static/scripts/packed/mvc/tools/tools-select-dataset.js --- a/static/scripts/packed/mvc/tools/tools-select-dataset.js +++ /dev/null @@ -1,1 +0,0 @@ -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("<div/>");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.datasets.filterType({content_type:"dataset",data_types:h.extensions});var k=[];for(var j in l){k.push({label: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.datasets.filterType({content_type:"collection",data_types:h.extensions});var f=[];for(var j in m){f.push({label: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(){var g=null;switch(this.current){case"hda":g=this.select_datasets;break;case"hdca":g=this.select_collection;break}var j=g.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(){switch(this.current){case"hda":return this.select_datasets.validate();case"hdca":return this.select_collection.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}}});return{View:d}}); \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org