Trackster: Fix trackster button in tabular data viewer

This commit is contained in:
Aysam Guerler
2014-03-26 23:00:42 -04:00
parent e329872433
commit 152fa0db00
9 changed files with 145 additions and 105 deletions
File diff suppressed because one or more lines are too long
@@ -135,7 +135,7 @@ return Backbone.View.extend(
this.title = new Ui.Input({
placeholder: 'Chart title',
onchange: function() {
self.app.config.set('title', self.title.value());
self.chart.set('title', self.title.value());
}
});
@@ -223,6 +223,7 @@ return Backbone.View.extend(
_refreshTitle: function() {
var title = this.chart.get('title');
this.portlet.title(title);
this.title.value(title);
},
// update
@@ -58,8 +58,6 @@ return Backbone.View.extend(
break;
case 'initialized':
self.chart.trigger('drawable');
$icon.addClass('fa fa-warning');
break;
default:
$icon.addClass('fa fa-spinner fa-spin');
break;
+1 -1
View File
@@ -1242,7 +1242,7 @@ class UsesVisualizationMixin( UsesHistoryDatasetAssociationMixin, UsesLibraryMix
trans.sa_session.flush()
return imported_visualization
def create_visualization( self, trans, type, title="Untitled Genome Vis", slug=None,
def create_visualization( self, trans, type, title="Untitled Visualization", slug=None,
dbkey=None, annotation=None, config={}, save=True ):
"""
Create visualiation and first revision.
@@ -178,9 +178,9 @@ class VisualizationsController( BaseAPIController, UsesVisualizationMixin, Shara
revision = self.add_visualization_revision( trans, visualization, config, title, dbkey )
rval = { 'id' : id, 'revision' : revision.id }
#TODO: allow updating vis title & slug
#visualization.title = title
#trans.sa_session.flush()
# allow updating vis title
visualization.title = title
trans.sa_session.flush()
except ( ItemAccessibilityException, ItemDeletionException ), exception:
trans.response.status = 403
+135 -94
View File
@@ -1,5 +1,5 @@
// Additional dependencies: jQuery, underscore.
define([], function() {
define(['mvc/ui/ui-modal', 'mvc/ui/ui-frames'], function(Modal, Frames) {
/**
* Dataset metedata.
@@ -126,7 +126,10 @@ var TabularDatasetChunkedView = Backbone.View.extend({
this.dark_row_color = '#DDD';
// load trackster button
new TabularButtonTracksterView(options);
new TabularButtonTracksterView({
model : options.model,
$el : this.$el
});
},
render: function() {
@@ -301,8 +304,8 @@ var EmbeddedTabularDatasetChunkedView = TabularDatasetChunkedView.extend({
});
// button for trackster visualization
var TabularButtonTracksterView = Backbone.View.extend(
{
var TabularButtonTracksterView = Backbone.View.extend({
// gene region columns
col: {
chrom : null,
@@ -320,110 +323,137 @@ var TabularButtonTracksterView = Backbone.View.extend(
genome_build: null,
// data type
data_type: null,
data_type : null,
// backbone initialize
initialize: function (options)
{
// get options
var attributes = options.model.attributes;
var metadata = options.model.attributes.metadata.attributes;
initialize: function (options) {
// check if environment is available
var Galaxy = parent.Galaxy;
// link galaxy modal or create one
if (Galaxy && Galaxy.modal) {
this.modal = Galaxy.modal;
}
// link galaxy frames
if (Galaxy && Galaxy.frame) {
this.frame = Galaxy.frame;
}
// check
if (!this.modal || !this.frame) {
return;
}
// model/metadata
var model = options.model;
var metadata = model.get('metadata');
// check for datatype
if (typeof attributes.data_type !== "undefined")
this.data_type = attributes.data_type;
else
console.log("TabularButtonTrackster : Data type missing.");
if (!model.get('data_type')) {
return;
}
// get data type
this.data_type = model.get('data_type');
// check for bed-file format
if (this.data_type == "bed")
if (this.data_type == 'bed')
{
// verify that metadata exists
if (typeof metadata.chromCol !== "undefined" || typeof metadata.startCol !== "undefined" || typeof metadata.endCol !== "undefined")
if (metadata.get('chromCol') && metadata.get('startCol') && metadata.get('endCol'))
{
// read in columns
this.col.chrom = metadata.chromCol - 1;
this.col.start = metadata.startCol - 1;
this.col.end = metadata.endCol - 1;
} else
console.log("TabularButtonTrackster : Bed-file metadata incomplete.");
this.col.chrom = metadata.get('chromCol') - 1;
this.col.start = metadata.get('startCol') - 1;
this.col.end = metadata.get('endCol') - 1;
} else {
console.log('TabularButtonTrackster : Bed-file metadata incomplete.');
return;
}
}
// check for vcf-file format
if (this.data_type == "vcf")
if (this.data_type == 'vcf')
{
// search array
function search (str, array)
{
function search (str, array) {
for (var j = 0; j < array.length; j++)
if (array[j].match(str)) return j;
return -1;
};
// load
this.col.chrom = search("Chrom", metadata.column_names);
this.col.start = search("Pos", metadata.column_names);
this.col.chrom = search('Chrom', metadata.get('column_names'));
this.col.start = search('Pos', metadata.get('column_names'));
this.col.end = null;
// verify that metadata exists
if (this.col.chrom == -1 || this.col.start == -1)
console.log("TabularButtonTrackster : VCF-file metadata incomplete.");
if (this.col.chrom == -1 || this.col.start == -1) {
console.log('TabularButtonTrackster : VCF-file metadata incomplete.');
return;
}
}
// check
if(this.col.chrom === null) {
if(this.col.chrom === undefined) {
return;
}
// get dataset id
if (typeof options.model.attributes.id === "undefined") {
console.log("TabularButtonTrackster : Dataset identification is missing.");
if (model.id) {
this.dataset_id = model.id;
} else {
this.dataset_id = options.model.attributes.id;
console.log('TabularButtonTrackster : Dataset identification is missing.');
return;
}
// get url
if (typeof options.model.attributes.url_viz === "undefined") {
console.log("TabularButtonTrackster : Url for visualization controller is missing.");
if (model.get('url_viz')) {
this.url_viz = model.get('url_viz');
} else {
this.url_viz = options.model.attributes.url_viz;
console.log('TabularButtonTrackster : Url for visualization controller is missing.');
return;
}
// get genome_build / database key
if (typeof options.model.attributes.genome_build !== "undefined") {
this.genome_build = options.model.attributes.genome_build;
if (model.get('genome_build')) {
this.genome_build = model.get('genome_build');
}
// render the icon from template
var btn_viz = new IconButtonView({ model : new IconButton({
title : 'Visualize',
icon_class : 'chart_curve',
id : 'btn_viz'
})});
// create the icon
var btn_viz = new IconButtonView({
model : new IconButton({
title : 'Visualize',
icon_class : 'chart_curve',
id : 'btn_viz'
})
});
// add it to the screen
// set element
this.setElement(options.$el);
// add to element
this.$el.append(btn_viz.render().$el);
// hide the button
$('#btn_viz').hide();
this.hide();
},
// backbone events
events:
{
'mouseover tr' : 'btn_viz_show',
'mouseleave' : 'btn_viz_hide'
'mouseover tr' : 'show',
'mouseleave' : 'hide'
},
// show button
btn_viz_show: function (e)
{
show: function (e) {
// is numeric
function is_numeric(n)
{
function is_numeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
};
// check
if(this.col.chrom === null)
return;
@@ -439,8 +469,8 @@ var TabularButtonTracksterView = Backbone.View.extend(
var end = this.col.end ? row.children().eq(this.col.end).html() : start;
// double check location
if (!chrom.match("^#") && chrom !== "" && is_numeric(start))
{
if (!chrom.match("^#") && chrom !== "" && is_numeric(start)) {
// get target gene region
var btn_viz_pars = {
dataset_id : this.dataset_id,
@@ -450,7 +480,7 @@ var TabularButtonTracksterView = Backbone.View.extend(
// get button position
var offset = row.offset();
var left = offset.left - 10;
var top = offset.top - $(window).scrollTop();
var top = offset.top - $(window).scrollTop() + 3;
// update css
$('#btn_viz').css({'position': 'fixed', 'top': top + 'px', 'left': left + 'px'});
@@ -466,72 +496,83 @@ var TabularButtonTracksterView = Backbone.View.extend(
},
// hide button
btn_viz_hide: function ()
{
// hide button from screen
$('#btn_viz').hide();
hide: function () {
this.$el.find('#btn_viz').hide();
},
// create action
create_trackster_action : function (vis_url, dataset_params, dbkey) {
// link this
var self = this;
// create function
return function() {
var listTracksParams = {};
if (dbkey){
// list_tracks seems to use 'f-dbkey' (??)
if (dbkey) {
listTracksParams[ 'f-dbkey' ] = dbkey;
}
$.ajax({
url: vis_url + '/list_tracks?' + $.param( listTracksParams ),
dataType: "html",
error: function() { alert( ( "Could not add this dataset to browser" ) + '.' ); },
dataType: 'html',
error: function() {
// show error message
self.modal.show({
title : 'Something went wrong!',
body : 'Unfortunately we could not add this dataset to the track browser. Please try again or contact us.',
buttons : {
'Cancel': function(){
self.modal.hide();
}
}
});
},
success: function(table_html) {
var parent = window.parent;
parent.Galaxy.modal.show({
title : "View Data in a New or Saved Visualization",
self.modal.show({
title : 'View Data in a New or Saved Visualization',
buttons :{
"Cancel": function(){
parent.Galaxy.modal.hide();
'Cancel': function(){
self.modal.hide();
},
"View in saved visualization": function(){
// Show new modal with saved visualizations.
parent.Galaxy.modal.show(
'View in saved visualization': function(){
// show modal with saved visualizations
self.modal.show(
{
title: "Add Data to Saved Visualization",
body: table_html,
buttons :{
"Cancel": function(){
parent.Galaxy.modal.hide();
title : 'Add Data to Saved Visualization',
body : table_html,
buttons : {
'Cancel': function(){
self.modal.hide();
},
"Add to visualization": function(){
$(parent.document).find('input[name=id]:checked').each(function(){
// hide
parent.Galaxy.modal.hide();
'Add to visualization': function(){
// hide
self.modal.hide();
// search selected fields
self.modal.$el.find('input[name=id]:checked').each(function(){
// get visualization id
var vis_id = $(this).val();
dataset_params.id = vis_id;
// add widget
parent.Galaxy.frame.add({
title : "Trackster",
type : "url",
content : vis_url + "/trackster?" + $.param(dataset_params)
self.frame.add({
title : 'Trackster',
type : 'url',
content : vis_url + '/trackster?' + $.param(dataset_params)
});
});
}
}
});
},
"View in new visualization": function(){
'View in new visualization': function(){
// hide
parent.Galaxy.modal.hide();
self.modal.hide();
var url = vis_url + "/trackster?" + $.param(dataset_params);
// add widget
parent.Galaxy.frame.add({
title : "Trackster",
type : "url",
content : url
self.frame.add({
title : 'Trackster',
type : 'url',
content : vis_url + '/trackster?' + $.param(dataset_params)
});
}
}
+1 -1
View File
@@ -218,7 +218,7 @@ return {
tmpl += '</div>';
}
} else {
tmpl += '<div id="' + id + '" class="' + cls + '"><label id="' + column.label_id_prefix + encoded_id + '" for="' + encoded_id + '">' + value + '</label></div>';
tmpl += '<div id="' + id + '" class="' + cls + '"><label id="' + column.label_id_prefix + encoded_id + '" for="' + encoded_id + '">' + (value || '') + '</label></div>';
}
tmpl += '</td>';
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long