1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/1270fd83fab7/ changeset: 1270fd83fab7 user: jgoecks date: 2012-05-30 22:37:51 summary: Use backbone to save trackster visualizations. affected #: 5 files diff -r ec4584a0e500e755aa5436691318d442831d8787 -r 1270fd83fab77ddda4385a6a3eb2011518ebfd3a lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2445,8 +2445,8 @@ self.user = None class Visualization( object ): - def __init__( self, user=None, type=None, title=None, dbkey=None, slug=None, latest_revision=None ): - self.id = None + def __init__( self, id=None, user=None, type=None, title=None, dbkey=None, slug=None, latest_revision=None ): + self.id = id self.user = user self.type = type self.title = title diff -r ec4584a0e500e755aa5436691318d442831d8787 -r 1270fd83fab77ddda4385a6a3eb2011518ebfd3a lib/galaxy/web/controllers/tracks.py --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -234,15 +234,26 @@ rows.append( [location, name] ) return { 'data': rows } - # TODO: this is duplicated from visualization controller; remove it once - # routing incompatibilities have been resolved. @web.json - def save( self, trans, config, type, id=None, title=None, dbkey=None, annotation=None ): + def save( self, trans, vis_json ): """ Save a visualization; if visualization does not have an ID, a new visualization is created. Returns JSON of visualization. """ - return self.save_visualization( trans, from_json_string( config ), type, id, title, dbkey, annotation ) + + # TODO: Need from_dict to convert json to Visualization object. + vis_config = from_json_string( vis_json ) + config = { + 'view': vis_config[ 'datasets' ], + 'bookmarks': vis_config[ 'bookmarks' ], + 'viewport': vis_config[ 'viewport' ] + } + type = vis_config[ 'type' ] + id = vis_config[ 'id' ] + title = vis_config[ 'title' ] + dbkey = vis_config[ 'dbkey' ] + annotation = vis_config.get( 'annotation', None ) + return self.save_visualization( trans, config, type, id, title, dbkey, annotation ) @web.expose @web.require_login() diff -r ec4584a0e500e755aa5436691318d442831d8787 -r 1270fd83fab77ddda4385a6a3eb2011518ebfd3a static/scripts/mvc/visualization.js --- a/static/scripts/mvc/visualization.js +++ b/static/scripts/mvc/visualization.js @@ -54,6 +54,24 @@ type: "", dbkey: "", datasets: [] + }, + + url: function() { return galaxy_paths.get("visualization_url"); }, + + /** + * POSTs visualization's JSON to its URL using the parameter 'vis_json' + * Note: This is necessary because (a) Galaxy requires keyword args and + * (b) Galaxy does not handle PUT now. + */ + save: function() { + return $.ajax({ + url: this.url(), + type: "POST", + dataType: "json", + data: { + vis_json: JSON.stringify(this) + } + }); } }); diff -r ec4584a0e500e755aa5436691318d442831d8787 -r 1270fd83fab77ddda4385a6a3eb2011518ebfd3a static/scripts/trackster.js --- a/static/scripts/trackster.js +++ b/static/scripts/trackster.js @@ -1368,7 +1368,7 @@ // Introduction div shown when there are no tracks. this.intro_div = $("<div/>").addClass("intro").appendTo(this.viewport_container).hide(); var add_tracks_button = $("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function () { - add_tracks(); + add_datasets(); }); // Another label track at bottom this.nav_labeltrack = $("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container); diff -r ec4584a0e500e755aa5436691318d442831d8787 -r 1270fd83fab77ddda4385a6a3eb2011518ebfd3a templates/tracks/browser.mako --- a/templates/tracks/browser.mako +++ b/templates/tracks/browser.mako @@ -47,7 +47,10 @@ <script type="text/javascript"> // // Place URLs here so that url_for can be used to generate them. - // + // + galaxy_paths.set({ + visualization_url: "${h.url_for( action='save' )}" + }); var add_track_async_url = "${h.url_for( action='add_track_async' )}", add_datasets_url = "${h.url_for( action='list_current_history_datasets' )}", @@ -148,36 +151,29 @@ // FIXME: give unique IDs to Drawables and save overview as ID. var overview_track_name = (view.overview_drawable ? view.overview_drawable.name : null); - var payload = { - 'view': view.to_dict(), + var visualization = new TracksterVisualization({ + 'id': view.vis_id, + 'title': view.name, + 'dbkey': view.dbkey, + 'type': 'trackster', + 'datasets': view.to_dict(), 'viewport': { 'chrom': view.chrom, 'start': view.low , 'end': view.high, 'overview': overview_track_name }, 'bookmarks': bookmarks - }; - - $.ajax({ - url: "${h.url_for( action='save' )}", - type: "POST", - data: { - 'id': view.vis_id, - 'title': view.name, - 'dbkey': view.dbkey, - 'type': 'trackster', - 'config': JSON.stringify(payload) - }, - dataType: "json", - success: function(vis_info) { + }); + + visualization.save() + .success(function(vis_info) { hide_modal(); view.vis_id = vis_info.vis_id; view.has_changes = false; - + // Needed to set URL when first saving a visualization. window.history.pushState({}, "", vis_info.url + window.location.hash); - }, - error: function() { + }) + .error(function() { show_modal( "Could Not Save", "Could not save visualization. Please try again later.", { "Close" : hide_modal } ); - } - }); + }); } }, { icon_class: 'cross-circle', title: 'Close', on_click: function() { window.location = "${h.url_for( controller='visualization', action='list' )}"; 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.