galaxy-dist commit 4b78bad81e77: Trackster: save current viewport when saving viz
# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User James Taylor <james@jamestaylor.org> # Date 1289169067 18000 # Node ID 4b78bad81e777cf503ac66acb5dbb01da841400f # Parent fb55bfc792b1d087783055a736d9fb439e5bb41c Trackster: save current viewport when saving viz --- a/static/scripts/trackster.js +++ b/static/scripts/trackster.js @@ -81,7 +81,7 @@ var Cache = function( num_elements ) { } }); -var View = function( container, title, vis_id, dbkey ) { +var View = function( container, title, vis_id, dbkey, callback ) { this.container = container; this.vis_id = vis_id; this.dbkey = dbkey; @@ -95,11 +95,11 @@ var View = function( container, title, v this.zoom_factor = 3; this.min_separation = 30; this.has_changes = false; - this.init(); + this.init( callback ); this.reset(); }; $.extend( View.prototype, { - init: function() { + init: function( callback ) { // Create DOM elements var parent_element = this.container, view = this; @@ -177,6 +177,9 @@ var View = function( container, title, v view.chrom_select.bind("change", function() { view.change_chrom(view.chrom_select.val()); }); + if ( callback ) { + callback(); + } }, error: function() { alert( "Could not load chroms for this dbkey:", view.dbkey ); @@ -244,8 +247,8 @@ var View = function( container, title, v this.drag_origin_x = e.clientX; this.drag_origin_pos = e.clientX / view.viewport_container.width() * (view.high - view.low) + view.low; this.drag_div = $("<div />").css( { - "height": view.content_div.height()+30, "top": "0px", "position": "absolute", - "background-color": "#cfc", "border": "1px solid #6a6", "opacity": 0.5, "z-index": 1000 + "height": view.content_div.height() + view.top_labeltrack.height() + view.nav_labeltrack.height(), "top": "0px", "position": "absolute", + "background-color": "#ccf", "opacity": 0.5, "z-index": 1000 } ).appendTo( $(this) ); }).bind( "drag", function(e) { var min = Math.min(e.clientX, this.drag_origin_x) - view.container.offset().left, @@ -1216,7 +1219,7 @@ var FeatureTrack = function ( name, view this.show_labels_scale = 0.001; this.showing_details = false; this.vertical_detail_px = 10; - this.vertical_nodetail_px = 2; + this.vertical_nodetail_px = 3; this.summary_draw_height = 30; this.default_font = "9px Monaco, Lucida Console, monospace"; this.inc_slots = {}; --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -1,12 +1,5 @@ """ Support for constructing and viewing custom "track" browsers within Galaxy. - -Track browsers are currently transient -- nothing is stored to the database -when a browser is created. Building a browser consists of selecting a set -of datasets associated with the same dbkey to display. Once selected, jobs -are started to create any necessary indexes in the background, and the user -is redirected to the browser interface, which loads the appropriate datasets. - """ import re, pkg_resources @@ -317,7 +310,7 @@ class TracksController( BaseController, if 'vis_id' in kwargs: vis_id = kwargs['vis_id'].strip('"') dbkey = kwargs['dbkey'] - + # Lookup or create Visualization object if vis_id == "undefined": # new vis vis = model.Visualization() vis.user = trans.user @@ -328,20 +321,30 @@ class TracksController( BaseController, else: decoded_id = trans.security.decode_id( vis_id ) vis = session.query( model.Visualization ).get( decoded_id ) - + # Decode the payload decoded_payload = simplejson.loads( kwargs['payload'] ) + # Create new VisualizationRevision that will be attached to the viz vis_rev = model.VisualizationRevision() vis_rev.visualization = vis vis_rev.title = vis.title vis_rev.dbkey = dbkey + # Tracks from payload tracks = [] - for track in decoded_payload: + for track in decoded_payload['tracks']: tracks.append( { "dataset_id": str(track['dataset_id']), "name": track['name'], "track_type": track['track_type'], "prefs": track['prefs'] } ) - vis_rev.config = { "tracks": tracks } + # Viewport from payload + if 'viewport' in decoded_payload: + chrom = decoded_payload['viewport']['chrom'] + start = decoded_payload['viewport']['start'] + end = decoded_payload['viewport']['end'] + vis_rev.config = { "tracks": tracks, "viewport": { 'chrom': chrom, 'start': start, 'end': end } } + else: + vis_rev.config = { "tracks": tracks } + print vis_rev.config vis.latest_revision = vis_rev session.add( vis_rev ) session.flush() --- a/templates/tracks/browser.mako +++ b/templates/tracks/browser.mako @@ -77,7 +77,11 @@ $(function() { %if config: - view = new View( $("#browser-container"), "${config.get('title') | h}", "${config.get('vis_id')}", "${config.get('dbkey')}" ); + var callback; + %if 'viewport' in config: + var callback = function() { view.change_chrom( '${config['viewport']['chrom']}', ${config['viewport']['start']}, ${config['viewport']['end']} ); } + %endif + view = new View( $("#browser-container"), "${config.get('title') | h}", "${config.get('vis_id')}", "${config.get('dbkey')}", callback ); view.editor = true; %for track in config.get('tracks'): view.add_track( @@ -180,21 +184,25 @@ $("#save-button").bind("click", function(e) { var sorted = $(".viewport-container").sortable('toArray'), - payload = []; + tracks = []; + + // Show saving dialog box + show_modal("Saving...", "<img src='${h.url_for('/static/images/yui/rel_interstitial_loading.gif')}'/>"); for (var i in sorted) { var track_id = parseInt(sorted[i].split("track_")[1]), track = view.tracks[track_id]; - payload.push( { + tracks.push( { "track_type": track.track_type, "name": track.name, "dataset_id": track.dataset_id, "prefs": track.prefs }); } - // Show saving dialog box - show_modal("Saving...", "<img src='${h.url_for('/static/images/yui/rel_interstitial_loading.gif')}'/>"); + + var payload = { 'tracks': tracks, 'viewport': { 'chrom': view.chrom, 'start': view.low , 'end': view.high } } + console.log( payload ); $.ajax({ url: "${h.url_for( action='save' )}", --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -185,6 +185,9 @@ class UsesVisualization( SharableItemSec config = { "title": visualization.title, "vis_id": trans.security.encode_id( visualization.id ), "tracks": tracks, "chrom": "", "dbkey": visualization.dbkey } + + if 'viewport' in latest_revision.config: + config['viewport'] = latest_revision.config['viewport'] return config
participants (1)
-
commits-noreply@bitbucket.org