From 5bcbbdc40bf13ba9a87cf35df56027af5259fdba Mon Sep 17 00:00:00 2001 From: Carl Eberhard Date: Wed, 24 Sep 2014 13:54:04 -0400 Subject: [PATCH] Fix to 83aaac5: copy changes into client/ --- client/galaxy/scripts/galaxy.frame.js | 53 ++++++++++++++++++- client/galaxy/scripts/mvc/data.js | 6 ++- .../galaxy/scripts/mvc/dataset/dataset-li.js | 20 +------ 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/client/galaxy/scripts/galaxy.frame.js b/client/galaxy/scripts/galaxy.frame.js index f6b0db9bfd7..0a779afb074 100644 --- a/client/galaxy/scripts/galaxy.frame.js +++ b/client/galaxy/scripts/galaxy.frame.js @@ -73,8 +73,59 @@ var GalaxyFrame = Backbone.View.extend( }); this._refresh(); }, + + /** + * Add a dataset to the frames. + */ + add_dataset: function(dataset_id) { + var self = this; + require(['mvc/data'], function(DATA) { + var dataset = new DATA.Dataset({ id: dataset_id }); + $.when( dataset.fetch() ).then( function() { + // Construct frame config based on dataset's type. + var frame_config = { + title: dataset.get('name') + }, + // HACK: For now, assume 'tabular' and 'interval' are the only + // modules that contain tabular files. This needs to be replaced + // will a is_datatype() function. + is_tabular = _.find(['tabular', 'interval'], function(data_type) { + return dataset.get('data_type').indexOf(data_type) !== -1; + }); + + // Use tabular chunked display if dataset is tabular; otherwise load via URL. + if (is_tabular) { + var tabular_dataset = new DATA.TabularDataset(dataset.toJSON()); + _.extend(frame_config, { + type: 'other', + content: function( parent_elt ) { + DATA.createTabularDatasetChunkedView({ + model: tabular_dataset, + parent_elt: parent_elt, + embedded: true, + height: '100%' + }); + } + }); + } + else { + _.extend(frame_config, { + type: 'url', + content: galaxy_config.root + 'datasets/' + + dataset.id + '/display/?preview=True' + }); + } + + self.add(frame_config); + + }); + }); + + }, - // adds and displays a new frame/window + /** + * Add and display a new frame/window based on options. + */ add: function(options) { // open new tab diff --git a/client/galaxy/scripts/mvc/data.js b/client/galaxy/scripts/mvc/data.js index 2a654c8d90f..c693b39781d 100644 --- a/client/galaxy/scripts/mvc/data.js +++ b/client/galaxy/scripts/mvc/data.js @@ -20,7 +20,11 @@ var Dataset = Backbone.Model.extend({ }, initialize: function() { - this._set_metadata(); + // Metadata can be passed in as a model or a set of attributes; if it's + // already a model, there's no need to set metadata. + if (!this.get('metadata')) { + this._set_metadata(); + } // Update metadata on change. this.on('change', this._set_metadata, this); diff --git a/client/galaxy/scripts/mvc/dataset/dataset-li.js b/client/galaxy/scripts/mvc/dataset/dataset-li.js index d17cd482f09..feea0276916 100644 --- a/client/galaxy/scripts/mvc/dataset/dataset-li.js +++ b/client/galaxy/scripts/mvc/dataset/dataset-li.js @@ -161,24 +161,8 @@ var DatasetListItemView = _super.extend( var self = this; displayBtnData.onclick = function( ev ){ if( Galaxy.frame && Galaxy.frame.active ){ - // Create frame with TabularChunkedView. - Galaxy.frame.add({ - title : "Data Viewer: " + self.model.get( 'name' ), - type : "other", - content : function( parent_elt ){ - require(['mvc/data'], function(DATA) { - var new_dataset = new DATA.TabularDataset({ id: self.model.get( 'id' ) }); - $.when( new_dataset.fetch() ).then( function(){ - DATA.createTabularDatasetChunkedView({ - model: new_dataset, - parent_elt: parent_elt, - embedded: true, - height: '100%' - }); - }); - }); - } - }); + // Add dataset to frames. + Galaxy.frame.add_dataset(self.model.get('id')); ev.preventDefault(); } };