commit/galaxy-central: jgoecks: Use tabular chunked data diplay for shared/published datasets.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/41f4c9c90959/ changeset: 41f4c9c90959 user: jgoecks date: 2013-02-11 21:56:50 summary: Use tabular chunked data diplay for shared/published datasets. affected #: 5 files diff -r 422f368eb0978b7d8ed5a320f1700603aea22ca1 -r 41f4c9c9095919b080dc0e32a5d540865fdf0fa7 lib/galaxy/datatypes/data.py --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -69,6 +69,9 @@ <class 'galaxy.datatypes.metadata.MetadataParameter'> """ + # Data is not chunkable by default. + CHUNKABLE = False + #: dictionary of metadata fields for this datatype:: metadata_spec = None diff -r 422f368eb0978b7d8ed5a320f1700603aea22ca1 -r 41f4c9c9095919b080dc0e32a5d540865fdf0fa7 lib/galaxy/datatypes/tabular.py --- a/lib/galaxy/datatypes/tabular.py +++ b/lib/galaxy/datatypes/tabular.py @@ -20,6 +20,9 @@ class Tabular( data.Text ): """Tab delimited data""" + + # All tabular data is chunkable. + CHUNKABLE = True CHUNK_SIZE = 50000 """Add metadata elements""" diff -r 422f368eb0978b7d8ed5a320f1700603aea22ca1 -r 41f4c9c9095919b080dc0e32a5d540865fdf0fa7 lib/galaxy/webapps/galaxy/controllers/dataset.py --- a/lib/galaxy/webapps/galaxy/controllers/dataset.py +++ b/lib/galaxy/webapps/galaxy/controllers/dataset.py @@ -642,6 +642,11 @@ truncated, dataset_data = self.get_data( dataset, preview ) dataset.annotation = self.get_item_annotation_str( trans.sa_session, dataset.history.user, dataset ) + # If dataset is chunkable, get first chunk. + first_chunk = None + if dataset.datatype.CHUNKABLE: + first_chunk = dataset.datatype.get_chunk(trans, dataset, 0) + # If data is binary or an image, stream without template; otherwise, use display template. # TODO: figure out a way to display images in display template. if isinstance(dataset.datatype, datatypes.binary.Binary) or isinstance(dataset.datatype, datatypes.images.Image) or isinstance(dataset.datatype, datatypes.images.Html): @@ -658,8 +663,10 @@ user_item_rating = 0 ave_item_rating, num_ratings = self.get_ave_item_rating_data( trans.sa_session, dataset ) - return trans.fill_template_mako( "/dataset/display.mako", item=dataset, item_data=dataset_data, truncated=truncated, - user_item_rating = user_item_rating, ave_item_rating=ave_item_rating, num_ratings=num_ratings ) + return trans.fill_template_mako( "/dataset/display.mako", item=dataset, item_data=dataset_data, + truncated=truncated, user_item_rating = user_item_rating, + ave_item_rating=ave_item_rating, num_ratings=num_ratings, + first_chunk=first_chunk ) else: raise web.httpexceptions.HTTPNotFound() diff -r 422f368eb0978b7d8ed5a320f1700603aea22ca1 -r 41f4c9c9095919b080dc0e32a5d540865fdf0fa7 static/scripts/mvc/data.js --- a/static/scripts/mvc/data.js +++ b/static/scripts/mvc/data.js @@ -102,7 +102,10 @@ }); /** - * Provides table-based, dynamic view of a tabular dataset. + * Provides table-based, dynamic view of a tabular dataset. + * NOTE: view's el must be in DOM already and provided when + * createing the view so that scrolling event can be attached + * to the correct container. */ var TabularDatasetChunkedView = Backbone.View.extend({ @@ -129,13 +132,31 @@ this._renderChunk(first_chunk); } - // Show new chunks during scrolling. - var self = this; - $(window).scroll(function() { - if ($(window).scrollTop() === $(document).height() - $(window).height()) { + // -- Show new chunks during scrolling. -- + + var self = this, + // Element that does the scrolling. + scroll_elt = _.find(this.$el.parents(), function(p) { + return $(p).css('overflow') === 'auto'; + }), + // Flag to ensure that only one chunk is loaded at a time. + loading_chunk = false; + + // If no scrolling element found, use window. + if (!scroll_elt) { scroll_elt = window; } + + // Wrap scrolling element for easy access. + scroll_elt = $(scroll_elt); + + // Set up chunk loading when scrolling using the scrolling element. + scroll_elt.scroll(function() { + // If not already loading a chunk and have scrolled to the bottom of this element, get next chunk. + if ( !loading_chunk && (self.$el.height() - scroll_elt.scrollTop() - scroll_elt.height() <= 0) ) { + loading_chunk = true; $.when(self.model.get_next_chunk()).then(function(result) { if (result) { self._renderChunk(result); + loading_chunk = false; } }); } @@ -218,7 +239,7 @@ if (parent_elt) { parent_elt.append(a_view.$el); } - + return a_view; }; @@ -227,7 +248,14 @@ * and appends to parent_elt. */ var createTabularDatasetChunkedView = function(dataset_config, parent_elt) { - return createModelAndView(TabularDataset, TabularDatasetChunkedView, dataset_config, parent_elt); + // Create view element and add to parent. + var view_div = $('<div/>').appendTo(parent_elt); + + // Create view with model, render, and return. + return new TabularDatasetChunkedView({ + el: view_div, + model: new TabularDataset(dataset_config) + }).render(); }; return { diff -r 422f368eb0978b7d8ed5a320f1700603aea22ca1 -r 41f4c9c9095919b080dc0e32a5d540865fdf0fa7 templates/webapps/galaxy/dataset/display.mako --- a/templates/webapps/galaxy/dataset/display.mako +++ b/templates/webapps/galaxy/dataset/display.mako @@ -5,6 +5,35 @@ <%def name="javascripts()"> ${parent.javascripts()} + ## If data is chunkable, use JavaScript for display. + %if item.datatype.CHUNKABLE: + + <script type="text/javascript"> + require.config({ + baseUrl: "${h.url_for('/static/scripts')}", + shim: { + "libs/backbone/backbone": { exports: "Backbone" }, + "libs/backbone/backbone-relational": ["libs/backbone/backbone"] + } + }); + + require(['mvc/data'], function(data) { + data.createTabularDatasetChunkedView( + // Dataset config. TODO: encode id. + _.extend( ${h.to_json_string( item.get_api_value() )}, + { + chunk_url: "${h.url_for( controller='/dataset', action='display', + dataset_id=trans.security.encode_id( item.id ))}", + first_data_chunk: ${first_chunk} + } + ), + // Append view to body. + $('.page-body') + ); + }); + </script> + + %endif </%def><%def name="init()"> @@ -31,14 +60,17 @@ </%def><%def name="render_item( data, data_to_render )"> - %if truncated: - <div class="warningmessagelarge"> - This dataset is large and only the first megabyte is shown below. | - <a href="${h.url_for( controller='dataset', action='display_by_username_and_slug', username=data.history.user.username, slug=trans.security.encode_id( data.id ), preview=False )}">Show all</a> - </div> + ## Chunkable data is rendered in JavaScript above; render unchunkable data below. + %if not data.datatype.CHUNKABLE: + %if truncated: + <div class="warningmessagelarge"> + This dataset is large and only the first megabyte is shown below. | + <a href="${h.url_for( controller='dataset', action='display_by_username_and_slug', username=data.history.user.username, slug=trans.security.encode_id( data.id ), preview=False )}">Show all</a> + </div> + %endif + ## TODO: why is the default font size so small? + <pre style="font-size: 135%">${ data_to_render | h }</pre> %endif - ## TODO: why is the default font size so small? - <pre style="font-size: 135%">${ data_to_render | h }</pre></%def> 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.
participants (1)
-
Bitbucket