Skip to content

Commit

Permalink
Merge branch 'show-dce-count' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed May 16, 2016
2 parents 28acca5 + ab60901 commit a0291c6
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 57 deletions.
42 changes: 25 additions & 17 deletions client/galaxy/scripts/mvc/collection/collection-li.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,23 @@ var DCListItemView = FoldoutListItemView.extend(
/** event listeners */
_setUpListeners : function(){
FoldoutListItemView.prototype._setUpListeners.call( this );
// re-rendering on deletion
this.listenTo( this.model, 'change', function( model, options ){
if( _.isEqual( _.keys( model.changed ), [ 'deleted' ] ) ){
// if the model has changed deletion status render it entirely
if( _.has( model.changed, 'deleted' ) ){
this.render();

// if the model has been decorated after the fact with the element count,
// render the subtitle where the count is displayed
} else if( _.has( model.changed, 'element_count' ) ){
this.$( '> .title-bar .subtitle' ).replaceWith( this._renderSubtitle() );
}
});
},

// ......................................................................... rendering
//TODO:?? possibly move to listItem
/** render a subtitle to show the user what sort of collection this is */
_renderSubtitle : function(){
var $subtitle = $( '<div class="subtitle"></div>' );
//TODO: would be good to get this in the subtitle
//var len = this.model.elements.length;
switch( this.model.get( 'collection_type' ) ){
case 'list':
return $subtitle.text( _l( 'a list of datasets' ) );
case 'paired':
return $subtitle.text( _l( 'a pair of datasets' ) );
case 'list:paired':
return $subtitle.text( _l( 'a list of paired datasets' ) );
}
return $subtitle;
return $( this.templates.subtitle( this.model.toJSON(), this ) );
},

// ......................................................................... foldout
Expand Down Expand Up @@ -122,9 +115,24 @@ DCListItemView.prototype.templates = (function(){
'</div>'
], 'collection' );

// use element identifier
var subtitleTemplate = BASE_MVC.wrapTemplate([
'<div class="subtitle">',
'<% var countText = collection.element_count? ( collection.element_count + " " ) : ""; %>',
'<% if( collection.collection_type === "list" ){ %>',
_l( 'a list of <%- countText %>datasets' ),
'<% } else if( collection.collection_type === "paired" ){ %>',
_l( 'a pair of datasets' ),
'<% } else if( collection.collection_type === "list:paired" ){ %>',
_l( 'a list of <%- countText %>dataset pairs' ),
'<% } %>',
'</div>'
], 'collection' );

return _.extend( {}, FoldoutListItemView.prototype.templates, {
warnings : warnings,
titleBar : titleBarTemplate
warnings : warnings,
titleBar : titleBarTemplate,
subtitle : subtitleTemplate
});
}());

Expand Down
24 changes: 13 additions & 11 deletions client/galaxy/scripts/mvc/history/history-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ var HistoryContents = Backbone.Collection
return this.fetch( options );
},

/** specialty fetch method for retrieving the element_counts of all hdcas in the history */
fetchCollectionCounts : function( options ){
options = options || {};
options.data = _.defaults({
keys : [ 'type_id', 'element_count' ].join( ',' ),
q : 'history_content_type',
qv : 'dataset_collection',
}, options.data || {} );
options.merge = true;
options.remove = false;
return this.fetch( options );
},

/** using a queue, perform ajaxFn on each of the models in this collection */
ajaxQueue : function( ajaxFn, options ){
var deferred = jQuery.Deferred(),
Expand Down Expand Up @@ -292,17 +305,6 @@ var HistoryContents = Backbone.Collection
},

// ........................................................................ misc
/** override to ensure type id is set */
set : function( models, options ){
models = _.isArray( models )? models : [ models ];
_.each( models, function( model ){
if( !model.type_id || !model.get || !model.get( 'type_id' ) ){
model.type_id = HISTORY_CONTENT.typeIdStr( model.history_content_type, model.id );
}
});
Backbone.Collection.prototype.set.call( this, models, options );
},

/** */
createHDCA : function( elementIdentifiers, collectionType, name, options ){
//precondition: elementIdentifiers is an array of plain js objects
Expand Down
26 changes: 18 additions & 8 deletions client/galaxy/scripts/mvc/history/history-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ var HistoryView = _super.extend(
return this.loadHistory( historyId, attributes, historyFn, contentsFn, detailIdsFn );
},

/** @type {Number} ms to wait after history load to fetch/decorate hdcas with element_count */
FETCH_COLLECTION_COUNTS_DELAY : 2000,

/** loads a history & contents (but does not make them the current history) */
loadHistory : function( historyId, attributes, historyFn, contentsFn, detailIdsFn ){
this.info( 'loadHistory:', historyId, attributes, historyFn, contentsFn, detailIdsFn );
Expand All @@ -200,6 +203,12 @@ var HistoryView = _super.extend(
panel.trigger( 'error', panel, xhr, attributes, _l( 'An error was encountered while ' + where ),
{ historyId: historyId, history: history || {} });
})
.done( function(){
// after the initial load, decorate with more time consuming fields (like HDCA element_counts)
_.delay( function(){
panel.model.contents.fetchCollectionCounts();
}, panel.FETCH_COLLECTION_COUNTS_DELAY );
})
.always( function(){
// bc _hideLoadingIndicator relies on this firing
panel.trigger( 'loading-done', panel );
Expand All @@ -209,14 +218,15 @@ var HistoryView = _super.extend(
/** given an xhr that will provide both history and contents data, pass data to set model or handle xhr errors */
_loadHistoryFromXHR : function( xhr, attributes ){
var panel = this;
xhr.then( function( historyJSON, contentsJSON ){
panel.JSONToModel( historyJSON, contentsJSON, attributes );
panel.render();
});
xhr.fail( function( xhr, where ){
// render anyways - whether we get a model or not
panel.render();
});
xhr
.then( function( historyJSON, contentsJSON ){
panel.JSONToModel( historyJSON, contentsJSON, attributes );
panel.render();
})
.fail( function( xhr, where ){
// render anyways - whether we get a model or not
panel.render();
});
return xhr;
},

Expand Down
26 changes: 20 additions & 6 deletions lib/galaxy/managers/hdcas.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def add_serializers( self ):
super( DCSerializer, self ).add_serializers()
self.serializers.update({
'model_class' : lambda *a, **c: 'DatasetCollection',
'elements' : self.serialize_elements
'elements' : self.serialize_elements,
'element_count' : self.serialize_element_count
})

def serialize_elements( self, item, key, **context ):
Expand All @@ -118,6 +119,14 @@ def serialize_elements( self, item, key, **context ):
returned.append( serialized )
return returned

def serialize_element_count( self, item, key, **context ):
"""Return the count of elements for this collection."""
# TODO: app.model.context -> session
# TODO: to the container interface (dataset_collection_contents)
return ( self.app.model.context.query( model.DatasetCollectionElement )
.filter( model.DatasetCollectionElement.dataset_collection_id == item.id )
.count() )


class DCASerializer( base.ModelSerializer ):
"""
Expand Down Expand Up @@ -152,7 +161,8 @@ def add_serializers( self ):
'populated',
'populated_state',
'populated_state_message',
'elements'
'elements',
'element_count'
]
for key in collection_keys:
self.serializers[ key ] = self._proxy_to_dataset_collection( key=key )
Expand Down Expand Up @@ -182,14 +192,17 @@ def __init__( self, app ):

self.default_view = 'summary'
self.add_view( 'summary', [
'id', 'name',
'type_id',
'history_id', 'hid',
'history_content_type',
'id',
'collection_type',
'populated',
'populated_state',
'populated_state_message',

'name',
'type_id',
'history_id',
'hid',
'history_content_type',
'deleted',
# 'purged',
'visible',
Expand All @@ -207,6 +220,7 @@ def add_serializers( self ):

self.serializers.update({
'model_class' : lambda *a, **c: self.hdca_manager.model_class.__class__.__name__,
# TODO: remove
'type' : lambda *a, **c: 'collection',
# part of a history and container
'history_id' : self.serialize_id,
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/collection/collection-li.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0291c6

Please sign in to comment.