mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
ToolForm: Add data selector, dynamic column selector and checkboxes, extends json content for basic parameters
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -88,7 +88,7 @@ var View = Backbone.View.extend({
|
||||
break;
|
||||
// radiobox field
|
||||
case 'radiobutton' :
|
||||
field = new Ui.RadioButton({
|
||||
field = new Ui.RadioButton.View({
|
||||
id : 'field-' + id,
|
||||
data : settings_def.data,
|
||||
value : model.get(id),
|
||||
|
||||
@@ -35,7 +35,7 @@ return Backbone.View.extend({
|
||||
$el.append(Utils.wrap((new Ui.Label({ title : 'How many data points would you like to analyze?'})).$el));
|
||||
|
||||
// construct chart type subset selection buttons
|
||||
this.library = new Ui.RadioButton({
|
||||
this.library = new Ui.RadioButton.View({
|
||||
data : [ { label: 'Few (<500)', value: 'small' },
|
||||
{ label: 'Some (<10k)', value: 'medium' },
|
||||
{ label: 'Many (>10k)', value: 'large' }],
|
||||
|
||||
@@ -991,6 +991,8 @@ class SelectToolParameter( ToolParameter ):
|
||||
# Found selected option.
|
||||
value = option[1]
|
||||
d[ 'value' ] = value
|
||||
|
||||
d[ 'display' ] = self.display
|
||||
|
||||
return d
|
||||
|
||||
@@ -1230,6 +1232,8 @@ class ColumnListParameter( SelectToolParameter ):
|
||||
def need_late_validation( self, trans, context ):
|
||||
if super( ColumnListParameter, self ).need_late_validation( trans, context ):
|
||||
return True
|
||||
if self.data_ref not in context:
|
||||
return False
|
||||
# Get the selected dataset if selected
|
||||
dataset = context[ self.data_ref ]
|
||||
if dataset:
|
||||
@@ -1242,6 +1246,16 @@ class ColumnListParameter( SelectToolParameter ):
|
||||
# No late validation
|
||||
return False
|
||||
|
||||
def to_dict( self, trans, view='collection', value_mapper=None ):
|
||||
# call parent to_dict
|
||||
d = super( ColumnListParameter, self ).to_dict( trans )
|
||||
|
||||
# add data reference
|
||||
d[ 'data_ref' ] = self.data_ref
|
||||
|
||||
# return
|
||||
return d
|
||||
|
||||
|
||||
class DrillDownSelectToolParameter( SelectToolParameter ):
|
||||
"""
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
define([ 'mvc/history/history-contents' ], function( HISTORY_CONTENTS ){
|
||||
return Backbone.Model.extend({
|
||||
// initialize
|
||||
initialize: function(options) {
|
||||
// create history contents container
|
||||
this.currHistoryContents = new HISTORY_CONTENTS.HistoryContents({});
|
||||
|
||||
// identify current history id
|
||||
this.currHistoryContents.historyId = "f597429621d6eb2b";//Galaxy.currHistoryPanel.model.id;
|
||||
|
||||
// make request
|
||||
var self = this;
|
||||
var xhr = this.currHistoryContents.fetchAllDetails()
|
||||
.done( function(){
|
||||
// log request success
|
||||
console.debug('tools-datasets::initialize() - Completed.');
|
||||
|
||||
// callback
|
||||
options.success && options.success();
|
||||
})
|
||||
.fail( function(){
|
||||
// log request failure
|
||||
console.debug('tools-datasets::initialize() - Ajax request failed.');
|
||||
});
|
||||
},
|
||||
|
||||
// filter datasets by data type
|
||||
filterType: function(filter_type) {
|
||||
// return matched datasets
|
||||
return this.currHistoryContents.filter( function( content ){
|
||||
// link details
|
||||
var history_content_type = content.get( 'history_content_type' );
|
||||
var data_type = content.get( 'data_type');
|
||||
|
||||
// apply filter
|
||||
return history_content_type === 'dataset';// && (data_type === filter_type || filter_type === '');
|
||||
});
|
||||
},
|
||||
|
||||
// filter datasets by id
|
||||
filter: function(filter_id) {
|
||||
// return matched datasets
|
||||
return _.first( this.currHistoryContents.filter( function( content ){ return content.get( 'id' ) === filter_id; }) );
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,8 @@
|
||||
define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'], function(Tools, Portlet, Table, Ui) {
|
||||
define(['mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc',
|
||||
'mvc/citation/citation-model', 'mvc/citation/citation-view',
|
||||
'mvc/tools', 'mvc/tools/tools-template', 'mvc/tools/tools-datasets'],
|
||||
function(Portlet, Table, Ui, CitationModel, CitationView,
|
||||
Tools, ToolTemplate, ToolDatasets) {
|
||||
|
||||
// create tool model
|
||||
var Model = Backbone.Model.extend({
|
||||
@@ -17,14 +21,31 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
// link this
|
||||
var self = this;
|
||||
|
||||
// link options
|
||||
this.options = options;
|
||||
|
||||
// load tool model
|
||||
this.model = new Model({
|
||||
id : options.id
|
||||
});
|
||||
|
||||
// initialize datasets
|
||||
this.datasets = new ToolDatasets({
|
||||
success: function() {
|
||||
self._initializeToolForm();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// initialize tool form
|
||||
_initializeToolForm: function() {
|
||||
// fetch model and render form
|
||||
var self = this;
|
||||
this.model.fetch({
|
||||
success: function() {
|
||||
// inputs
|
||||
self.inputs = self.model.get('inputs');
|
||||
|
||||
// create portlet
|
||||
self.portlet = new Portlet.View({
|
||||
icon : 'fa-wrench',
|
||||
@@ -41,15 +62,35 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
}
|
||||
});
|
||||
|
||||
// table
|
||||
// create table
|
||||
self.table = new Table.View();
|
||||
|
||||
// add message
|
||||
// create message
|
||||
self.message = new Ui.Message();
|
||||
self.portlet.append(self.message.$el);
|
||||
|
||||
// append portlet
|
||||
// append form
|
||||
$(self.main_el).append(self.portlet.$el);
|
||||
|
||||
// append help
|
||||
if (self.options.help != '') {
|
||||
$(self.main_el).append(ToolTemplate.help(self.options.help));
|
||||
}
|
||||
|
||||
// append citations
|
||||
if (self.options.citations) {
|
||||
// append html
|
||||
$(self.main_el).append(ToolTemplate.citations());
|
||||
|
||||
// fetch citations
|
||||
var citations = new CitationModel.ToolCitationCollection();
|
||||
citations.tool_id = self.options.id;
|
||||
var citation_list_view = new CitationView.CitationListView({ collection: citations } );
|
||||
citation_list_view.render();
|
||||
citations.fetch();
|
||||
}
|
||||
|
||||
// configure portlet and form table
|
||||
self.setElement(self.portlet.content());
|
||||
self.portlet.append(self.table.$el);
|
||||
self.render();
|
||||
@@ -59,9 +100,6 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
|
||||
// update
|
||||
render: function() {
|
||||
// inputs
|
||||
var settings = this.model.get('inputs');
|
||||
|
||||
// reset table
|
||||
this.table.delAll();
|
||||
|
||||
@@ -72,8 +110,8 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
var data = new Backbone.Model();
|
||||
|
||||
// load settings elements into table
|
||||
for (var id in settings) {
|
||||
this._add(settings[id], data);
|
||||
for (var id in this.inputs) {
|
||||
this._add(this.inputs[id], data);
|
||||
}
|
||||
|
||||
// trigger change
|
||||
@@ -83,53 +121,55 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
},
|
||||
|
||||
// add table row
|
||||
_add: function(settings_def, data) {
|
||||
_add: function(inputs_def, data) {
|
||||
// link this
|
||||
var self = this;
|
||||
|
||||
// get id
|
||||
var id = settings_def.name;
|
||||
|
||||
// log
|
||||
console.debug(settings_def);
|
||||
var id = inputs_def.name;
|
||||
|
||||
// field wrapper
|
||||
var field = null;
|
||||
|
||||
console.log(inputs_def);
|
||||
// create select field
|
||||
var type = settings_def.type;
|
||||
var type = inputs_def.type;
|
||||
switch(type) {
|
||||
// text input field
|
||||
case 'text' :
|
||||
field = this.field_text(settings_def, data);
|
||||
field = this.field_text(inputs_def, data);
|
||||
break;
|
||||
|
||||
// select field
|
||||
case 'select' :
|
||||
field = this.field_select(settings_def, data);
|
||||
field = this.field_select(inputs_def, data);
|
||||
break;
|
||||
|
||||
// radiobox field
|
||||
case 'radiobutton' :
|
||||
field = this.field_radio(settings_def, data);
|
||||
field = this.field_radio(inputs_def, data);
|
||||
break;
|
||||
|
||||
// dataset
|
||||
case 'data':
|
||||
field = this.field_select(settings_def, data);
|
||||
field = this.field_data(inputs_def, data);
|
||||
break;
|
||||
|
||||
// slider input field
|
||||
// dataset column
|
||||
case 'data_column':
|
||||
field = this.field_column(inputs_def, data);
|
||||
break;
|
||||
|
||||
// text area field
|
||||
case 'textarea' :
|
||||
field = this.field_textarea(settings_def, data);
|
||||
field = this.field_textarea(inputs_def, data);
|
||||
break;
|
||||
|
||||
// default
|
||||
default:
|
||||
field = new Ui.Input({
|
||||
id : 'field-' + id,
|
||||
placeholder : settings_def.placeholder,
|
||||
type : settings_def.type,
|
||||
placeholder : inputs_def.placeholder,
|
||||
type : inputs_def.type,
|
||||
onchange : function() {
|
||||
data.set(id, field.value());
|
||||
}
|
||||
@@ -138,7 +178,7 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
|
||||
// set value
|
||||
if (!data.get(id)) {
|
||||
data.set(id, settings_def.value);
|
||||
data.set(id, inputs_def.value);
|
||||
}
|
||||
field.value(data.get(id));
|
||||
|
||||
@@ -148,31 +188,26 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
// combine field and info
|
||||
var $input = $('<div/>');
|
||||
$input.append(field.$el);
|
||||
if (settings_def.info) {
|
||||
$input.append('<div class="ui-table-form-info">' + settings_def.info + '</div>');
|
||||
if (inputs_def.info) {
|
||||
$input.append('<div class="ui-table-form-info">' + inputs_def.info + '</div>');
|
||||
}
|
||||
|
||||
// add row to table
|
||||
if (this.options.style == 'bold') {
|
||||
this.table.add(new Ui.Label({title: settings_def.title, cls: 'form-label'}).$el);
|
||||
this.table.add($input);
|
||||
} else {
|
||||
this.table.add('<span class="ui-table-form-title">' + settings_def.label + '</span>', '25%');
|
||||
this.table.add($input);
|
||||
}
|
||||
|
||||
this.table.add('<span class="ui-table-form-title">' + inputs_def.label + '</span>', '25%');
|
||||
this.table.add($input);
|
||||
|
||||
// add to table
|
||||
this.table.append(id);
|
||||
|
||||
// show/hide
|
||||
if (settings_def.hide) {
|
||||
if (inputs_def.hide) {
|
||||
this.table.get(id).hide();
|
||||
}
|
||||
},
|
||||
|
||||
// text input field
|
||||
field_text : function(settings_def, data) {
|
||||
var id = settings_def.name;
|
||||
field_text : function(inputs_def, data) {
|
||||
var id = inputs_def.name;
|
||||
return new Ui.Input({
|
||||
id : 'field-' + id,
|
||||
value : data.get(id),
|
||||
@@ -183,8 +218,8 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
},
|
||||
|
||||
// text area
|
||||
field_textarea : function(settings_def, data) {
|
||||
var id = settings_def.name;
|
||||
field_textarea : function(inputs_def, data) {
|
||||
var id = inputs_def.name;
|
||||
return new Ui.Textarea({
|
||||
id : 'field-' + id,
|
||||
onchange : function() {
|
||||
@@ -193,12 +228,89 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
});
|
||||
},
|
||||
|
||||
// select field
|
||||
field_select : function (settings_def, data) {
|
||||
// data input field
|
||||
field_data : function(inputs_def, data) {
|
||||
// link this
|
||||
var self = this;
|
||||
|
||||
// get element id
|
||||
var id = inputs_def.name;
|
||||
|
||||
// get datasets
|
||||
var datasets = this.datasets.filterType();
|
||||
|
||||
// configure options fields
|
||||
var options = [];
|
||||
for (var i in settings_def.options) {
|
||||
var option = settings_def.options[i];
|
||||
for (var i in datasets) {
|
||||
options.push({
|
||||
label: datasets[i].get('name'),
|
||||
value: datasets[i].get('id')
|
||||
});
|
||||
}
|
||||
|
||||
// find referenced columns
|
||||
var column_list = _.where(this.inputs, {
|
||||
data_ref : id,
|
||||
type : 'data_column'
|
||||
});
|
||||
|
||||
// select field
|
||||
return new Ui.Select.View({
|
||||
id : 'field-' + id,
|
||||
data : options,
|
||||
value : options[0].value,
|
||||
onchange : function(value) {
|
||||
// update value
|
||||
data.set(id, value);
|
||||
|
||||
// find selected dataset
|
||||
var dataset = self.datasets.filter(value);
|
||||
|
||||
// check dataset
|
||||
if (dataset && column_list.length > 0) {
|
||||
// log selection
|
||||
console.debug('tool-form::field_data() - Selected dataset ' + value + '.');
|
||||
|
||||
// get meta data
|
||||
var meta = dataset.get('metadata_column_types');
|
||||
|
||||
// check meta data
|
||||
if (!meta) {
|
||||
console.debug('tool-form::field_data() - FAILED: Could not find metadata for dataset ' + value + '.');
|
||||
}
|
||||
|
||||
// load column options
|
||||
var columns = [];
|
||||
for (var key in meta) {
|
||||
// add to selection
|
||||
columns.push({
|
||||
'label' : 'Column: ' + (parseInt(key) + 1) + ' [' + meta[key] + ']',
|
||||
'value' : key
|
||||
});
|
||||
}
|
||||
|
||||
// update referenced columns
|
||||
for (var i in column_list) {
|
||||
var column_field = self.list[column_list[i].name]
|
||||
if (column_field) {
|
||||
column_field.update(columns);
|
||||
column_field.value(column_field.first());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// log failure
|
||||
console.debug('tool-form::field_data() - FAILED: Could not find dataset ' + value + '.');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// select field
|
||||
field_column : function (inputs_def, data) {
|
||||
// configure options fields
|
||||
var options = [];
|
||||
for (var i in inputs_def.options) {
|
||||
var option = inputs_def.options[i];
|
||||
options.push({
|
||||
label: option[0],
|
||||
value: option[1]
|
||||
@@ -206,56 +318,56 @@ define(['mvc/tools', 'mvc/ui/ui-portlet', 'mvc/ui/ui-table', 'mvc/ui/ui-misc'],
|
||||
}
|
||||
|
||||
// select field
|
||||
var id = settings_def.name;
|
||||
var id = inputs_def.name;
|
||||
return new Ui.Select.View({
|
||||
id : 'field-' + id,
|
||||
data : options,
|
||||
value : data.get(id),
|
||||
onchange : function(value) {
|
||||
// set new value
|
||||
data.set(id, value);
|
||||
|
||||
// find selected dictionary
|
||||
var dict = _.findWhere(options, {value: value});
|
||||
if (dict && dict.operations) {
|
||||
var operations = dict.operations;
|
||||
for (var i in operations.show) {
|
||||
var target = operations.show[i];
|
||||
self.table.get(target).show();
|
||||
}
|
||||
for (var i in operations.hide) {
|
||||
var target = operations.hide[i];
|
||||
self.table.get(target).hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// select field
|
||||
field_select : function (inputs_def, data) {
|
||||
// configure options fields
|
||||
var options = [];
|
||||
for (var i in inputs_def.options) {
|
||||
var option = inputs_def.options[i];
|
||||
options.push({
|
||||
label: option[0],
|
||||
value: option[1]
|
||||
});
|
||||
}
|
||||
|
||||
// identify display type
|
||||
var SelectClass = Ui.Select;
|
||||
if (inputs_def.display == 'checkboxes') {
|
||||
SelectClass = Ui.Checkbox;
|
||||
}
|
||||
|
||||
// select field
|
||||
var id = inputs_def.name;
|
||||
return new SelectClass.View({
|
||||
id : 'field-' + id,
|
||||
data : options,
|
||||
value : data.get(id),
|
||||
onchange : function(value) {
|
||||
data.set(id, value);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// radio field
|
||||
field_radio : function(settings_def, data) {
|
||||
var id = settings_def.name;
|
||||
field_radio : function(inputs_def, data) {
|
||||
var id = inputs_def.name;
|
||||
return new Ui.RadioButton({
|
||||
id : 'field-' + id,
|
||||
data : settings_def.data,
|
||||
data : inputs_def.data,
|
||||
value : data.get(id),
|
||||
onchange : function(value) {
|
||||
// set new value
|
||||
data.set(id, value);
|
||||
|
||||
// find selected dictionary
|
||||
var dict = _.findWhere(settings_def.data, {value: value});
|
||||
if (dict && dict.operations) {
|
||||
var operations = dict.operations;
|
||||
for (var i in operations.show) {
|
||||
var target = operations.show[i];
|
||||
self.table.get(target).show();
|
||||
}
|
||||
for (var i in operations.hide) {
|
||||
var target = operations.hide[i];
|
||||
self.table.get(target).hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// dependencies
|
||||
define([], function() {
|
||||
|
||||
// tool form templates
|
||||
return {
|
||||
help: function(content) {
|
||||
return '<div class="toolHelp">' +
|
||||
'<div class="toolHelpBody">' +
|
||||
content +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
},
|
||||
|
||||
citations: function() {
|
||||
return '<div id="citations"></div>';
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
// dependencies
|
||||
define(['utils/utils'], function(Utils) {
|
||||
|
||||
// plugin
|
||||
var View = Backbone.View.extend({
|
||||
// options
|
||||
optionsDefault: {
|
||||
value : '',
|
||||
visible : true,
|
||||
cls : '',
|
||||
data : [],
|
||||
id : Utils.uuid()
|
||||
},
|
||||
|
||||
// initialize
|
||||
initialize : function(options) {
|
||||
// configure options
|
||||
this.options = Utils.merge(options, this.optionsDefault);
|
||||
|
||||
// create new element
|
||||
this.setElement(this._template(this.options));
|
||||
|
||||
// hide input field
|
||||
if (!this.options.visible) {
|
||||
this.$el.hide();
|
||||
}
|
||||
|
||||
// set initial value
|
||||
if (this.options.value) {
|
||||
this.value(this.options.value);
|
||||
}
|
||||
|
||||
// current value
|
||||
this.current = this.options.value;
|
||||
|
||||
// onchange event handler. fires on user activity.
|
||||
var self = this;
|
||||
this.$el.find('input').on('change', function() {
|
||||
self.value(self._getValue());
|
||||
});
|
||||
},
|
||||
|
||||
// value
|
||||
value : function (new_val) {
|
||||
// get current value
|
||||
var before = this.current;
|
||||
|
||||
// set new value
|
||||
if (new_val !== undefined) {
|
||||
this.$el.find('label').removeClass('active');
|
||||
this.$el.find('[value="' + new_val + '"]').closest('label').addClass('active');
|
||||
this.current = new_val;
|
||||
}
|
||||
|
||||
// check value
|
||||
var after = this.current;
|
||||
if (after != before && this.options.onchange) {
|
||||
this.options.onchange(this.current);
|
||||
}
|
||||
|
||||
// get and return value
|
||||
return this.current;
|
||||
},
|
||||
|
||||
// get value
|
||||
_getValue: function() {
|
||||
var selected = this.$el.find(':checked');
|
||||
var value = null;
|
||||
if (selected.length > 0) {
|
||||
value = selected.val();
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
||||
// element
|
||||
_template: function(options) {
|
||||
var tmpl = '<div class="ui-checkbox">';
|
||||
for (key in options.data) {
|
||||
var pair = options.data[key];
|
||||
tmpl += '<input type="checkbox" name="' + options.id + '" value="' + pair.value + '" selected>' + pair.label + '<br>';
|
||||
}
|
||||
tmpl += '</div>';
|
||||
return tmpl;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
View : View
|
||||
};
|
||||
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
// dependencies
|
||||
define(['utils/utils', 'mvc/ui/ui-select-default', 'mvc/ui/ui-button-menu', 'mvc/ui/ui-modal'],
|
||||
function(Utils, Select, ButtonMenu, Modal) {
|
||||
define(['utils/utils', 'mvc/ui/ui-select-default', 'mvc/ui/ui-checkbox', 'mvc/ui/ui-radiobutton', 'mvc/ui/ui-button-menu', 'mvc/ui/ui-modal'],
|
||||
function(Utils, Select, Checkbox, RadioButton, ButtonMenu, Modal) {
|
||||
|
||||
/**
|
||||
* This class contains backbone wrappers for basic ui elements such as Images, Labels, Buttons, Input fields etc.
|
||||
@@ -409,90 +409,6 @@ var Textarea = Backbone.View.extend({
|
||||
}
|
||||
});
|
||||
|
||||
// plugin
|
||||
var RadioButton = Backbone.View.extend({
|
||||
// options
|
||||
optionsDefault: {
|
||||
value : '',
|
||||
visible : true,
|
||||
cls : '',
|
||||
data : [],
|
||||
id : Utils.uuid()
|
||||
},
|
||||
|
||||
// initialize
|
||||
initialize : function(options) {
|
||||
// configure options
|
||||
this.options = Utils.merge(options, this.optionsDefault);
|
||||
|
||||
// create new element
|
||||
this.setElement(this._template(this.options));
|
||||
|
||||
// hide input field
|
||||
if (!this.options.visible) {
|
||||
this.$el.hide();
|
||||
}
|
||||
|
||||
// set initial value
|
||||
if (this.options.value) {
|
||||
this.value(this.options.value);
|
||||
}
|
||||
|
||||
// current value
|
||||
this.current = this.options.value;
|
||||
|
||||
// onchange event handler. fires on user activity.
|
||||
var self = this;
|
||||
this.$el.find('input').on('change', function() {
|
||||
self.value(self._getValue());
|
||||
});
|
||||
},
|
||||
|
||||
// value
|
||||
value : function (new_val) {
|
||||
// get current value
|
||||
var before = this.current;
|
||||
|
||||
// set new value
|
||||
if (new_val !== undefined) {
|
||||
this.$el.find('label').removeClass('active');
|
||||
this.$el.find('[value="' + new_val + '"]').closest('label').addClass('active');
|
||||
this.current = new_val;
|
||||
}
|
||||
|
||||
// check value
|
||||
var after = this.current;
|
||||
if (after != before && this.options.onchange) {
|
||||
this.options.onchange(this.current);
|
||||
}
|
||||
|
||||
// get and return value
|
||||
return this.current;
|
||||
},
|
||||
|
||||
// get value
|
||||
_getValue: function() {
|
||||
var selected = this.$el.find(':checked');
|
||||
var value = null;
|
||||
if (selected.length > 0) {
|
||||
value = selected.val();
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
||||
// element
|
||||
_template: function(options) {
|
||||
var tmpl = '<div class="btn-group ui-radiobutton" data-toggle="buttons">';
|
||||
for (key in options.data) {
|
||||
var pair = options.data[key];
|
||||
tmpl += '<label class="btn btn-default">' +
|
||||
'<input type="radio" name="' + options.id + '" value="' + pair.value + '" selected>' + pair.label +
|
||||
'</label>';
|
||||
}
|
||||
tmpl += '</div>';
|
||||
return tmpl;
|
||||
}
|
||||
});
|
||||
|
||||
// return
|
||||
return {
|
||||
@@ -507,6 +423,7 @@ return {
|
||||
Message : Message,
|
||||
Modal : Modal,
|
||||
RadioButton : RadioButton,
|
||||
Checkbox : Checkbox,
|
||||
Searchbox : Searchbox,
|
||||
Select : Select,
|
||||
Textarea : Textarea
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// dependencies
|
||||
define(['utils/utils'], function(Utils) {
|
||||
|
||||
// plugin
|
||||
var View = Backbone.View.extend({
|
||||
// options
|
||||
optionsDefault: {
|
||||
value : '',
|
||||
visible : true,
|
||||
cls : '',
|
||||
data : [],
|
||||
id : Utils.uuid()
|
||||
},
|
||||
|
||||
// initialize
|
||||
initialize : function(options) {
|
||||
// configure options
|
||||
this.options = Utils.merge(options, this.optionsDefault);
|
||||
|
||||
// create new element
|
||||
this.setElement(this._template(this.options));
|
||||
|
||||
// hide input field
|
||||
if (!this.options.visible) {
|
||||
this.$el.hide();
|
||||
}
|
||||
|
||||
// set initial value
|
||||
if (this.options.value) {
|
||||
this.value(this.options.value);
|
||||
}
|
||||
|
||||
// current value
|
||||
this.current = this.options.value;
|
||||
|
||||
// onchange event handler. fires on user activity.
|
||||
var self = this;
|
||||
this.$el.find('input').on('change', function() {
|
||||
self.value(self._getValue());
|
||||
});
|
||||
},
|
||||
|
||||
// value
|
||||
value : function (new_val) {
|
||||
// get current value
|
||||
var before = this.current;
|
||||
|
||||
// set new value
|
||||
if (new_val !== undefined) {
|
||||
this.$el.find('label').removeClass('active');
|
||||
this.$el.find('[value="' + new_val + '"]').closest('label').addClass('active');
|
||||
this.current = new_val;
|
||||
}
|
||||
|
||||
// check value
|
||||
var after = this.current;
|
||||
if (after != before && this.options.onchange) {
|
||||
this.options.onchange(this.current);
|
||||
}
|
||||
|
||||
// get and return value
|
||||
return this.current;
|
||||
},
|
||||
|
||||
// get value
|
||||
_getValue: function() {
|
||||
var selected = this.$el.find(':checked');
|
||||
var value = null;
|
||||
if (selected.length > 0) {
|
||||
value = selected.val();
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
||||
// element
|
||||
_template: function(options) {
|
||||
var tmpl = '<div class="btn-group ui-radiobutton" data-toggle="buttons">';
|
||||
for (key in options.data) {
|
||||
var pair = options.data[key];
|
||||
tmpl += '<label class="btn btn-default">' +
|
||||
'<input type="radio" name="' + options.id + '" value="' + pair.value + '" selected>' + pair.label +
|
||||
'</label>';
|
||||
}
|
||||
tmpl += '</div>';
|
||||
return tmpl;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
View : View
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
define(["mvc/history/history-contents"],function(a){return Backbone.Model.extend({initialize:function(c){this.currHistoryContents=new a.HistoryContents({});this.currHistoryContents.historyId="f597429621d6eb2b";var b=this;var d=this.currHistoryContents.fetchAllDetails().done(function(){console.debug("tools-datasets::initialize() - Completed.");c.success&&c.success()}).fail(function(){console.debug("tools-datasets::initialize() - Ajax request failed.")})},filterType:function(b){return this.currHistoryContents.filter(function(c){var d=c.get("history_content_type");var e=c.get("data_type");return d==="dataset"})},filter:function(b){return _.first(this.currHistoryContents.filter(function(c){return c.get("id")===b}))}})});
|
||||
@@ -1 +1 @@
|
||||
define(["mvc/tools","mvc/ui/ui-portlet","mvc/ui/ui-table","mvc/ui/ui-misc"],function(b,c,a,f){var e=Backbone.Model.extend({initialize:function(g){this.url=galaxy_config.root+"api/tools/"+g.id+"?io_details=true"}});var d=Backbone.View.extend({main_el:"body",initialize:function(h){var g=this;this.model=new e({id:h.id});this.model.fetch({success:function(){g.portlet=new c.View({icon:"fa-wrench",title:"<b>"+g.model.get("name")+"</b> "+g.model.get("description"),buttons:{execute:new f.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){}})}});g.table=new a.View();g.message=new f.Message();g.portlet.append(g.message.$el);$(g.main_el).append(g.portlet.$el);g.setElement(g.portlet.content());g.portlet.append(g.table.$el);g.render()}})},render:function(){var g=this.model.get("inputs");this.table.delAll();this.list=[];var h=new Backbone.Model();for(var i in g){this._add(g[i],h)}for(var i in this.list){this.list[i].trigger("change")}},_add:function(g,j){var h=this;var m=g.name;console.debug(g);var k=null;var i=g.type;switch(i){case"text":k=this.field_text(g,j);break;case"select":k=this.field_select(g,j);break;case"radiobutton":k=this.field_radio(g,j);break;case"data":k=this.field_select(g,j);break;case"textarea":k=this.field_textarea(g,j);break;default:k=new f.Input({id:"field-"+m,placeholder:g.placeholder,type:g.type,onchange:function(){j.set(m,k.value())}})}if(!j.get(m)){j.set(m,g.value)}k.value(j.get(m));this.list[m]=k;var l=$("<div/>");l.append(k.$el);if(g.info){l.append('<div class="ui-table-form-info">'+g.info+"</div>")}if(this.options.style=="bold"){this.table.add(new f.Label({title:g.title,cls:"form-label"}).$el);this.table.add(l)}else{this.table.add('<span class="ui-table-form-title">'+g.label+"</span>","25%");this.table.add(l)}this.table.append(m);if(g.hide){this.table.get(m).hide()}},field_text:function(g,h){var i=g.name;return new f.Input({id:"field-"+i,value:h.get(i),onchange:function(j){h.set(i,j)}})},field_textarea:function(g,h){var i=g.name;return new f.Textarea({id:"field-"+i,onchange:function(){h.set(i,field.value())}})},field_select:function(g,l){var h=[];for(var j in g.options){var k=g.options[j];h.push({label:k[0],value:k[1]})}var m=g.name;return new f.Select.View({id:"field-"+m,data:h,value:l.get(m),onchange:function(p){l.set(m,p);var r=_.findWhere(h,{value:p});if(r&&r.operations){var n=r.operations;for(var o in n.show){var q=n.show[o];self.table.get(q).show()}for(var o in n.hide){var q=n.hide[o];self.table.get(q).hide()}}}})},field_radio:function(g,h){var i=g.name;return new f.RadioButton({id:"field-"+i,data:g.data,value:h.get(i),onchange:function(l){h.set(i,l);var n=_.findWhere(g.data,{value:l});if(n&&n.operations){var j=n.operations;for(var k in j.show){var m=j.show[k];self.table.get(m).show()}for(var k in j.hide){var m=j.hide[k];self.table.get(m).hide()}}}})}});return{View:d}});
|
||||
define(["mvc/ui/ui-portlet","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-datasets"],function(f,i,j,h,a,e,c,g){var d=Backbone.Model.extend({initialize:function(k){this.url=galaxy_config.root+"api/tools/"+k.id+"?io_details=true"}});var b=Backbone.View.extend({main_el:"body",initialize:function(l){var k=this;this.options=l;this.model=new d({id:l.id});this.datasets=new g({success:function(){k._initializeToolForm()}})},_initializeToolForm:function(){var k=this;this.model.fetch({success:function(){k.inputs=k.model.get("inputs");k.portlet=new f.View({icon:"fa-wrench",title:"<b>"+k.model.get("name")+"</b> "+k.model.get("description"),buttons:{execute:new j.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){}})}});k.table=new i.View();k.message=new j.Message();k.portlet.append(k.message.$el);$(k.main_el).append(k.portlet.$el);if(k.options.help!=""){$(k.main_el).append(c.help(k.options.help))}if(k.options.citations){$(k.main_el).append(c.citations());var l=new h.ToolCitationCollection();l.tool_id=k.options.id;var m=new a.CitationListView({collection:l});m.render();l.fetch()}k.setElement(k.portlet.content());k.portlet.append(k.table.$el);k.render()}})},render:function(){this.table.delAll();this.list=[];var k=new Backbone.Model();for(var l in this.inputs){this._add(this.inputs[l],k)}for(var l in this.list){this.list[l].trigger("change")}},_add:function(l,n){var k=this;var q=l.name;var o=null;console.log(l);var m=l.type;switch(m){case"text":o=this.field_text(l,n);break;case"select":o=this.field_select(l,n);break;case"radiobutton":o=this.field_radio(l,n);break;case"data":o=this.field_data(l,n);break;case"data_column":o=this.field_column(l,n);break;case"textarea":o=this.field_textarea(l,n);break;default:o=new j.Input({id:"field-"+q,placeholder:l.placeholder,type:l.type,onchange:function(){n.set(q,o.value())}})}if(!n.get(q)){n.set(q,l.value)}o.value(n.get(q));this.list[q]=o;var p=$("<div/>");p.append(o.$el);if(l.info){p.append('<div class="ui-table-form-info">'+l.info+"</div>")}this.table.add('<span class="ui-table-form-title">'+l.label+"</span>","25%");this.table.add(p);this.table.append(q);if(l.hide){this.table.get(q).hide()}},field_text:function(k,l){var m=k.name;return new j.Input({id:"field-"+m,value:l.get(m),onchange:function(n){l.set(m,n)}})},field_textarea:function(k,l){var m=k.name;return new j.Textarea({id:"field-"+m,onchange:function(){l.set(m,field.value())}})},field_data:function(n,q){var l=this;var r=n.name;var p=this.datasets.filterType();var m=[];for(var o in p){m.push({label:p[o].get("name"),value:p[o].get("id")})}var k=_.where(this.inputs,{data_ref:r,type:"data_column"});return new j.Select.View({id:"field-"+r,data:m,value:m[0].value,onchange:function(w){q.set(r,w);var y=l.datasets.filter(w);if(y&&k.length>0){console.debug("tool-form::field_data() - Selected dataset "+w+".");var x=y.get("metadata_column_types");if(!x){console.debug("tool-form::field_data() - FAILED: Could not find metadata for dataset "+w+".")}var v=[];for(var u in x){v.push({label:"Column: "+(parseInt(u)+1)+" ["+x[u]+"]",value:u})}for(var t in k){var s=l.list[k[t].name];if(s){s.update(v);s.value(s.first())}}}else{console.debug("tool-form::field_data() - FAILED: Could not find dataset "+w+".")}}})},field_column:function(l,o){var k=[];for(var m in l.options){var n=l.options[m];k.push({label:n[0],value:n[1]})}var p=l.name;return new j.Select.View({id:"field-"+p,data:k,value:o.get(p),onchange:function(q){o.set(p,q)}})},field_select:function(l,p){var k=[];for(var m in l.options){var n=l.options[m];k.push({label:n[0],value:n[1]})}var o=j.Select;if(l.display=="checkboxes"){o=j.Checkbox}var q=l.name;return new o.View({id:"field-"+q,data:k,value:p.get(q),onchange:function(r){p.set(q,r)}})},field_radio:function(k,l){var m=k.name;return new j.RadioButton({id:"field-"+m,data:k.data,value:l.get(m),onchange:function(n){l.set(m,n)}})}});return{View:b}});
|
||||
@@ -0,0 +1 @@
|
||||
define([],function(){return{help:function(a){return'<div class="toolHelp"><div class="toolHelpBody">'+a+"</div></div>"},citations:function(){return'<div id="citations"></div>'}}});
|
||||
@@ -0,0 +1 @@
|
||||
define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{value:"",visible:true,cls:"",data:[],id:a.uuid()},initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));if(!this.options.visible){this.$el.hide()}if(this.options.value){this.value(this.options.value)}this.current=this.options.value;var c=this;this.$el.find("input").on("change",function(){c.value(c._getValue())})},value:function(c){var d=this.current;if(c!==undefined){this.$el.find("label").removeClass("active");this.$el.find('[value="'+c+'"]').closest("label").addClass("active");this.current=c}var e=this.current;if(e!=d&&this.options.onchange){this.options.onchange(this.current)}return this.current},_getValue:function(){var c=this.$el.find(":checked");var d=null;if(c.length>0){d=c.val()}return d},_template:function(d){var c='<div class="ui-checkbox">';for(key in d.data){var e=d.data[key];c+='<input type="checkbox" name="'+d.id+'" value="'+e.value+'" selected>'+e.label+"<br>"}c+="</div>";return c}});return{View:b}});
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{value:"",visible:true,cls:"",data:[],id:a.uuid()},initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));if(!this.options.visible){this.$el.hide()}if(this.options.value){this.value(this.options.value)}this.current=this.options.value;var c=this;this.$el.find("input").on("change",function(){c.value(c._getValue())})},value:function(c){var d=this.current;if(c!==undefined){this.$el.find("label").removeClass("active");this.$el.find('[value="'+c+'"]').closest("label").addClass("active");this.current=c}var e=this.current;if(e!=d&&this.options.onchange){this.options.onchange(this.current)}return this.current},_getValue:function(){var c=this.$el.find(":checked");var d=null;if(c.length>0){d=c.val()}return d},_template:function(d){var c='<div class="btn-group ui-radiobutton" data-toggle="buttons">';for(key in d.data){var e=d.data[key];c+='<label class="btn btn-default"><input type="radio" name="'+d.id+'" value="'+e.value+'" selected>'+e.label+"</label>"}c+="</div>";return c}});return{View:b}});
|
||||
@@ -1,10 +1,47 @@
|
||||
<%inherit file="/base.mako"/>
|
||||
|
||||
<%
|
||||
# load tool help
|
||||
tool_help = ''
|
||||
if tool.help:
|
||||
if tool.has_multiple_pages:
|
||||
tool_help = tool.help_by_page[tool_state.page]
|
||||
else:
|
||||
tool_help = tool.help
|
||||
|
||||
# Help is Mako template, so render using current static path.
|
||||
tool_help = tool_help.render( static_path=h.url_for( '/static' ), host_url=h.url_for('/', qualified=True) )
|
||||
|
||||
# Convert to unicode to display non-ascii characters.
|
||||
if type( tool_help ) is not unicode:
|
||||
tool_help = unicode( tool_help, 'utf-8')
|
||||
endif
|
||||
|
||||
# check if citations exist
|
||||
tool_citations = False
|
||||
if tool.citations:
|
||||
tool_citations = True
|
||||
|
||||
# form configuration
|
||||
self.form_config = {
|
||||
'id' : tool.id,
|
||||
'help' : tool_help,
|
||||
'citations' : tool_citations
|
||||
}
|
||||
%>
|
||||
${h.js( "libs/bibtex" )}
|
||||
<script>
|
||||
require(['mvc/tools/tools-form'], function(ToolsForm){
|
||||
$(function(){
|
||||
var form = new ToolsForm.View({
|
||||
id : '${tool.id}'
|
||||
});
|
||||
var form = new ToolsForm.View(${ h.to_json_string(self.form_config) });
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
%if tool.tool_shed_repository:
|
||||
<% tool_url = tool.tool_shed_repository.get_sharable_url( tool.app ) %>
|
||||
%if tool_url:
|
||||
<br/>
|
||||
${ render_msg( 'This tool was installed from a ToolShed, you may be able to find additional information by following this link: <a href="%s" target="_blank">%s</a>' % ( tool_url, tool_url ), 'info' ) }
|
||||
%endif
|
||||
%endif
|
||||
|
||||
Reference in New Issue
Block a user