1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/8fcb6ed6e233/ changeset: 8fcb6ed6e233 user: jgoecks date: 2012-09-27 23:35:04 summary: Viz framework: (a) fix embedded visualizations and (b) bookmarking. affected #: 6 files diff -r 7658dde1dd3356bfeb6b92bdcdf8f1c4b3537a0f -r 8fcb6ed6e2336542bb122cbac70c3150464cbbf1 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1278,6 +1278,18 @@ was converted successfully. """ + # FIXME: copied from controller.py + messages = Bunch( + PENDING = "pending", + NO_DATA = "no data", + NO_CHROMOSOME = "no chromosome", + NO_CONVERTER = "no converter", + NO_TOOL = "no tool", + DATA = "data", + ERROR = "error", + OK = "ok" + ) + # Get converted dataset; this will start the conversion if necessary. try: converted_dataset = self.get_converted_dataset( trans, target_type ) diff -r 7658dde1dd3356bfeb6b92bdcdf8f1c4b3537a0f -r 8fcb6ed6e2336542bb122cbac70c3150464cbbf1 static/scripts/viz/trackster/tracks.js --- a/static/scripts/viz/trackster/tracks.js +++ b/static/scripts/viz/trackster/tracks.js @@ -1,7 +1,7 @@ define( ["libs/underscore", "viz/visualization", "viz/trackster/util", "viz/trackster/slotting", "viz/trackster/painters", "mvc/data", - "viz/trackster/filters" ], - function( _, visualization, util, slotting, painters, data, filters_mod ) { + "viz/trackster/filters", "viz/trackster_ui" ], + function( _, visualization, util, slotting, painters, data, filters_mod, trackster_ui_mod ) { var extend = _.extend; var get_random_color = util.get_random_color; @@ -909,11 +909,15 @@ // 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_datasets(add_datasets_url, add_track_async_url, function(tracks) { + // Does not work because it would create circular dependency b/t trackster_ui and tracks. + /* + var ui = new trackster_ui_mod.TracksterUI(); + ui.add_datasets(add_datasets_url, add_track_async_url, function(tracks) { _.each(tracks, function(track) { view.add_drawable( object_from_template(track, view, view) ); }); }); + */ }); // Another label track at bottom this.nav_labeltrack = $("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container); diff -r 7658dde1dd3356bfeb6b92bdcdf8f1c4b3537a0f -r 8fcb6ed6e2336542bb122cbac70c3150464cbbf1 static/scripts/viz/trackster_ui.js --- a/static/scripts/viz/trackster_ui.js +++ b/static/scripts/viz/trackster_ui.js @@ -1,4 +1,4 @@ -define( ["base","libs/underscore","viz/trackster/slotting", "viz/trackster/painters","viz/trackster/tracks"], function( base, _, slotting, painters, tracks ) { +define( ["base","libs/underscore","viz/trackster/slotting", "viz/trackster/painters", "viz/trackster/tracks" ], function( base, _, slotting, painters, tracks ) { /************************************************************************ * Functions used for creating and managing the Trackster user interface. @@ -19,9 +19,9 @@ var self = this, menu = create_icon_buttons_menu([ { icon_class: 'plus-button', title: 'Add tracks', on_click: function() { - add_datasets(add_datasets_url, add_track_async_url, function(tracks) { + self.add_datasets(add_datasets_url, add_track_async_url, function(tracks) { _.each(tracks, function(track) { - view.add_drawable( trackster_ui.object_from_template(track, view, view) ); + view.add_drawable( object_from_template(track, view, view) ); }); }); } }, @@ -99,7 +99,8 @@ * Use a popup to select a dataset of create bookmarks from */ add_bookmarks: function() { - var baseURL = this.baseURL; + var self = this, + baseURL = this.baseURL; show_modal( "Select dataset for new bookmarks", "progress" ); $.ajax({ url: this.baseURL + "/visualization/list_histories", @@ -129,7 +130,7 @@ }).then( function(data) { for( i = 0; i < data.data.length; i++ ) { var row = data.data[i]; - add_bookmark( row[0], row[1] ); + self.add_bookmark( row[0], row[1] ); } }); }); @@ -183,7 +184,8 @@ create_visualization: function(view_config, viewport_config, drawables_config, bookmarks_config, editable) { // Create view. - view = new tracks.View(view_config); + var self = this, + view = new tracks.View(view_config); view.editor = true; $.when( view.load_chroms_deferred ).then(function() { // Viewport config. @@ -227,7 +229,7 @@ var bookmark; for (var i = 0; i < bookmarks_config.length; i++) { bookmark = bookmarks_config[i]; - add_bookmark(bookmark['position'], bookmark['annotation'], editable); + self.add_bookmark(bookmark['position'], bookmark['annotation'], editable); } } @@ -239,6 +241,58 @@ }, /** + * Use a popup grid to add more datasets. + */ + add_datasets: function(dataset_url, add_track_async_url, success_fn) { + $.ajax({ + url: dataset_url, + data: { "f-dbkey": view.dbkey }, + error: function() { alert( "Grid failed" ); }, + success: function(table_html) { + show_modal( + "Select datasets for new tracks", + table_html, { + "Cancel": function() { + hide_modal(); + }, + "Add": function() { + var requests = []; + $('input[name=id]:checked,input[name=ldda_ids]:checked').each(function() { + var data = { + data_type: 'track_config', + 'hda_ldda': 'hda' + }, + id = $(this).val(); + if ($(this).attr("name") !== "id") { + data.hda_ldda = 'ldda'; + } + requests[requests.length] = $.ajax({ + url: add_track_async_url + "/" + id, + data: data, + dataType: "json" + }); + }); + // To preserve order, wait until there are definitions for all tracks and then add + // them sequentially. + $.when.apply($, requests).then(function() { + // jQuery always returns an Array for arguments, so need to look at first element + // to determine whether multiple requests were made and consequently how to + // map arguments to track definitions. + var track_defs = (arguments[0] instanceof Array ? + $.map(arguments, function(arg) { return arg[0]; }) : + [ arguments[0] ] + ); + success_fn(track_defs); + }); + hide_modal(); + } + } + ); + } + }); + }, + + /** * Set up keyboard navigation for a visualization. */ init_keyboard_nav: function(view) { diff -r 7658dde1dd3356bfeb6b92bdcdf8f1c4b3537a0f -r 8fcb6ed6e2336542bb122cbac70c3150464cbbf1 static/scripts/viz/visualization.js --- a/static/scripts/viz/visualization.js +++ b/static/scripts/viz/visualization.js @@ -672,62 +672,6 @@ } }); -/** - * -- Helper functions. - */ - -/** - * Use a popup grid to add more datasets. - */ -var add_datasets = function(dataset_url, add_track_async_url, success_fn) { - $.ajax({ - url: dataset_url, - data: { "f-dbkey": view.dbkey }, - error: function() { alert( "Grid failed" ); }, - success: function(table_html) { - show_modal( - "Select datasets for new tracks", - table_html, { - "Cancel": function() { - hide_modal(); - }, - "Add": function() { - var requests = []; - $('input[name=id]:checked,input[name=ldda_ids]:checked').each(function() { - var data = { - data_type: 'track_config', - 'hda_ldda': 'hda' - }, - id = $(this).val(); - if ($(this).attr("name") !== "id") { - data.hda_ldda = 'ldda'; - } - requests[requests.length] = $.ajax({ - url: add_track_async_url + "/" + id, - data: data, - dataType: "json" - }); - }); - // To preserve order, wait until there are definitions for all tracks and then add - // them sequentially. - $.when.apply($, requests).then(function() { - // jQuery always returns an Array for arguments, so need to look at first element - // to determine whether multiple requests were made and consequently how to - // map arguments to track definitions. - var track_defs = (arguments[0] instanceof Array ? - $.map(arguments, function(arg) { return arg[0]; }) : - [ arguments[0] ] - ); - success_fn(track_defs); - }); - hide_modal(); - } - } - ); - } - }); -}; - return { BrowserBookmark: BrowserBookmark, BrowserBookmarkCollection: BrowserBookmarkCollection, @@ -741,8 +685,7 @@ ReferenceTrackDataManager: ReferenceTrackDataManager, TrackBrowserRouter: TrackBrowserRouter, TrackConfig: TrackConfig, - Visualization: Visualization, - add_datasets: add_datasets + Visualization: Visualization }; }); \ No newline at end of file diff -r 7658dde1dd3356bfeb6b92bdcdf8f1c4b3537a0f -r 8fcb6ed6e2336542bb122cbac70c3150464cbbf1 templates/tracks/browser.mako --- a/templates/tracks/browser.mako +++ b/templates/tracks/browser.mako @@ -48,8 +48,10 @@ ${render_trackster_js_vars()} - var view, - browser_router, + // FIXME: deliberate global required for now due to requireJS integration. + view = null; + + var browser_router, ui = new (trackster_ui.TracksterUI)( "${h.url_for('/')}" ); /** diff -r 7658dde1dd3356bfeb6b92bdcdf8f1c4b3537a0f -r 8fcb6ed6e2336542bb122cbac70c3150464cbbf1 templates/visualization/display.mako --- a/templates/visualization/display.mako +++ b/templates/visualization/display.mako @@ -54,44 +54,59 @@ <div id="${trans.security.encode_id( visualization.id )}" class="unified-panel-body" style="overflow:none;top:0px;"></div><script type="text/javascript"> - // TODO: much of this code is copied from browser.mako -- create shared base and use in both places. - ${render_trackster_js_vars()} + require.config({ + baseUrl: "${h.url_for('/static/scripts') }", + shim: { + "libs/underscore": { exports: "_" }, + "libs/backbone/backbone": { exports: "Backbone" }, + "libs/backbone/backbone-relational": ["libs/backbone/backbone"] + } + }); + require( ["base", "viz/visualization", "viz/trackster_ui", "viz/trackster/tracks"], + function( base, visualization, trackster_ui, tracks ) { - var view, - container_element = $("#${trans.security.encode_id( visualization.id )}"); - - $(function() { - var is_embedded = (container_element.parents(".item-content").length > 0); + ${render_trackster_js_vars()} + + // FIXME: deliberate global required for now due to requireJS integration. + view = null; + + var ui = new (trackster_ui.TracksterUI)( "${h.url_for('/')}" ) + container_element = $("#${trans.security.encode_id( visualization.id )}"); - // HTML setup. - if (is_embedded) { - container_element.css( { "position": "relative" } ); - } else { // Viewing just one shared viz - $("#right-border").click(function() { view.resize_window(); }); - } - - // Create visualization. - var callback; - %if 'viewport' in config: - var callback = function() { view.change_chrom( '${config['viewport']['chrom']}', ${config['viewport']['start']}, ${config['viewport']['end']} ); } - %endif - view = create_visualization( { - container: container_element, - name: "${config.get('title') | h}", - vis_id: "${config.get('vis_id')}", - dbkey: "${config.get('dbkey')}" - }, - JSON.parse('${ h.to_json_string( config.get( 'viewport', dict() ) ) }'), - JSON.parse('${ h.to_json_string( config['tracks'] ).replace("'", "\\'") }'), - JSON.parse('${ h.to_json_string( config.get('bookmarks') ) }') - ); - - // Set up keyboard navigation. - init_keyboard_nav(view); - - // HACK: set viewport height because it cannot be set automatically. Currently, max height for embedded - // elts is 25em, so use 20em. - view.viewport_container.height("20em"); + $(function() { + var is_embedded = (container_element.parents(".item-content").length > 0); + + // HTML setup. + if (is_embedded) { + container_element.css( { "position": "relative" } ); + } else { // Viewing just one shared viz + $("#right-border").click(function() { view.resize_window(); }); + } + + // Create visualization. + var callback; + %if 'viewport' in config: + var callback = function() { view.change_chrom( '${config['viewport']['chrom']}', ${config['viewport']['start']}, ${config['viewport']['end']} ); } + %endif + view = ui.create_visualization( { + container: container_element, + name: "${config.get('title') | h}", + vis_id: "${config.get('vis_id')}", + dbkey: "${config.get('dbkey')}" + }, + JSON.parse('${ h.to_json_string( config.get( 'viewport', dict() ) ) }'), + JSON.parse('${ h.to_json_string( config['tracks'] ).replace("'", "\\'") }'), + JSON.parse('${ h.to_json_string( config.get('bookmarks') ) }') + ); + + // Set up keyboard navigation. + ui.init_keyboard_nav(view); + + // HACK: set viewport height because it cannot be set automatically. Currently, max height for embedded + // elts is 25em, so use 20em. + view.viewport_container.height("20em"); + }); + }); </script> 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.