Skip to content

Commit

Permalink
Merge pull request #3781 from jmchilton/collection-builders
Browse files Browse the repository at this point in the history
Abstraction for re-use between collection creators.
  • Loading branch information
dannon authored Mar 21, 2017
2 parents 5428d39 + 18cb50e commit a5b0e76
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 186 deletions.
106 changes: 106 additions & 0 deletions client/galaxy/scripts/mvc/collection/base-creator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
define([
], function( ){

/* For presentation-related functionality shared across collection creators.
Particularily overlapping functionality related to name processing and help.
*/
var CollectionCreatorMixin = {

/** add (or clear if clear is truthy) a validation warning to the DOM element described in what */
_validationWarning : function( what, clear ){
var VALIDATION_CLASS = 'validation-warning';
if( what === 'name' ){
what = this.$( '.collection-name' ).add( this.$( '.collection-name-prompt' ) );
this.$( '.collection-name' ).focus().select();
}
if( clear ){
what = what || this.$( '.' + VALIDATION_CLASS );
what.removeClass( VALIDATION_CLASS );
} else {
what.addClass( VALIDATION_CLASS );
}
},

// ........................................................................ footer
/** handle a collection name change */
_changeName : function( ev ){
this._validationWarning( 'name', !!this._getName() );
},

/** check for enter key press when in the collection name and submit */
_nameCheckForEnter : function( ev ){
if( ev.keyCode === 13 && !this.blocking ){
this._clickCreate();
}
},

/** get the current collection name */
_getName : function(){
return _.escape( this.$( '.collection-name' ).val() );
},

// ........................................................................ header
/** expand help */
_clickMoreHelp : function( ev ){
ev.stopPropagation();
this.$( '.main-help' ).addClass( 'expanded' );
this.$( '.more-help' ).hide();
},
/** collapse help */
_clickLessHelp : function( ev ){
ev.stopPropagation();
this.$( '.main-help' ).removeClass( 'expanded' );
this.$( '.more-help' ).show();
},
/** toggle help */
_toggleHelp : function( ev ){
ev.stopPropagation();
this.$( '.main-help' ).toggleClass( 'expanded' );
this.$( '.more-help' ).toggle();
},

/** show an alert on the top of the interface containing message (alertClass is bootstrap's alert-*) */
_showAlert : function( message, alertClass ){
alertClass = alertClass || 'alert-danger';
this.$( '.main-help' ).hide();
this.$( '.header .alert' )
.attr( 'class', 'alert alert-dismissable' ).addClass( alertClass ).show()
.find( '.alert-message' ).html( message );
},
/** hide the alerts at the top */
_hideAlert : function( message ){
this.$( '.main-help' ).show();
this.$( '.header .alert' ).hide();
},

_cancelCreate: function( ev ){
if( typeof this.oncancel === 'function' ){
this.oncancel.call( this );
}
},

/** attempt to create the current collection */
_clickCreate : function( ev ){
var name = this._getName();
if( !name ){
this._validationWarning( 'name' );
} else if( !this.blocking ){
this.createList( name );
}
},

_creatorTemplates: {
main : _.template([
'<div class="header flex-row no-flex"></div>',
'<div class="middle flex-row flex-row-container"></div>',
'<div class="footer flex-row no-flex"></div>'
].join('')),
}

}

//==============================================================================
return {
CollectionCreatorMixin: CollectionCreatorMixin
};
});
99 changes: 7 additions & 92 deletions client/galaxy/scripts/mvc/collection/list-collection-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ define([
"mvc/history/hdca-model",
"mvc/dataset/states",
"mvc/base-mvc",
"mvc/collection/base-creator",
"mvc/ui/ui-modal",
"utils/natural-sort",
"utils/localization",
"ui/hoverhighlight"
], function( HDCA, STATES, BASE_MVC, UI_MODAL, naturalSort, _l ){
], function( HDCA, STATES, BASE_MVC, baseCreator, UI_MODAL, naturalSort, _l ){

'use strict';

var logNamespace = 'collections';

/*==============================================================================
TODO:
use proper Element model and not just json
Expand Down Expand Up @@ -151,7 +153,7 @@ var DatasetCollectionElementView = Backbone.View.extend( BASE_MVC.LoggableMixin
// ============================================================================
/** An interface for building collections.
*/
var ListCollectionCreator = Backbone.View.extend( BASE_MVC.LoggableMixin ).extend({
var ListCollectionCreator = Backbone.View.extend( BASE_MVC.LoggableMixin ).extend( baseCreator.CollectionCreatorMixin ).extend({
_logNamespace : logNamespace,

/** the class used to display individual elements */
Expand Down Expand Up @@ -367,21 +369,6 @@ var ListCollectionCreator = Backbone.View.extend( BASE_MVC.LoggableMixin ).exten
this._showAlert( this.templates.invalidElements({ problems: this.invalidElements }), 'alert-warning' );
},

/** add (or clear if clear is truthy) a validation warning to the DOM element described in what */
_validationWarning : function( what, clear ){
var VALIDATION_CLASS = 'validation-warning';
if( what === 'name' ){
what = this.$( '.collection-name' ).add( this.$( '.collection-name-prompt' ) );
this.$( '.collection-name' ).focus().select();
}
if( clear ){
what = what || this.$( '.' + VALIDATION_CLASS );
what.removeClass( VALIDATION_CLASS );
} else {
what.addClass( VALIDATION_CLASS );
}
},

_disableNameAndCreate : function( disable ){
disable = !_.isUndefined( disable )? disable : true;
if( disable ){
Expand Down Expand Up @@ -624,48 +611,10 @@ var ListCollectionCreator = Backbone.View.extend( BASE_MVC.LoggableMixin ).exten
// footer
'change .collection-name' : '_changeName',
'keydown .collection-name' : '_nameCheckForEnter',
'click .cancel-create' : function( ev ){
if( typeof this.oncancel === 'function' ){
this.oncancel.call( this );
}
},
'click .cancel-create' : '_cancelCreate',
'click .create-collection' : '_clickCreate'//,
},

// ........................................................................ header
/** expand help */
_clickMoreHelp : function( ev ){
ev.stopPropagation();
this.$( '.main-help' ).addClass( 'expanded' );
this.$( '.more-help' ).hide();
},
/** collapse help */
_clickLessHelp : function( ev ){
ev.stopPropagation();
this.$( '.main-help' ).removeClass( 'expanded' );
this.$( '.more-help' ).show();
},
/** toggle help */
_toggleHelp : function( ev ){
ev.stopPropagation();
this.$( '.main-help' ).toggleClass( 'expanded' );
this.$( '.more-help' ).toggle();
},

/** show an alert on the top of the interface containing message (alertClass is bootstrap's alert-*) */
_showAlert : function( message, alertClass ){
alertClass = alertClass || 'alert-danger';
this.$( '.main-help' ).hide();
this.$( '.header .alert' )
.attr( 'class', 'alert alert-dismissable' ).addClass( alertClass ).show()
.find( '.alert-message' ).html( message );
},
/** hide the alerts at the top */
_hideAlert : function( message ){
this.$( '.main-help' ).show();
this.$( '.header .alert' ).hide();
},

// ........................................................................ elements
/** reset all data to the initial state */
reset : function(){
Expand Down Expand Up @@ -789,46 +738,12 @@ var ListCollectionCreator = Backbone.View.extend( BASE_MVC.LoggableMixin ).exten
this.$dragging = null;
},

// ........................................................................ footer
/** handle a collection name change */
_changeName : function( ev ){
this._validationWarning( 'name', !!this._getName() );
},

/** check for enter key press when in the collection name and submit */
_nameCheckForEnter : function( ev ){
if( ev.keyCode === 13 && !this.blocking ){
this._clickCreate();
}
},

/** get the current collection name */
_getName : function(){
return _.escape( this.$( '.collection-name' ).val() );
},

/** attempt to create the current collection */
_clickCreate : function( ev ){
var name = this._getName();
if( !name ){
this._validationWarning( 'name' );
} else if( !this.blocking ){
this.createList( name );
}
},

// ------------------------------------------------------------------------ templates
//TODO: move to require text plugin and load these as text
//TODO: underscore currently unnecc. bc no vars are used
//TODO: better way of localizing text-nodes in long strings
/** underscore template fns attached to class */
templates : {
/** the skeleton */
main : _.template([
'<div class="header flex-row no-flex"></div>',
'<div class="middle flex-row flex-row-container"></div>',
'<div class="footer flex-row no-flex"></div>'
].join('')),
templates : _.extend(baseCreator.CollectionCreatorMixin._creatorTemplates, {

/** the header (not including help text) */
header : _.template([
Expand Down Expand Up @@ -974,7 +889,7 @@ var ListCollectionCreator = Backbone.View.extend( BASE_MVC.LoggableMixin ).exten
'</div>',
'</div>'
].join('')),
},
}),

// ------------------------------------------------------------------------ misc
/** string rep */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
define([
"utils/levenshtein",
"utils/natural-sort",
"mvc/collection/list-collection-creator",
"mvc/collection/base-creator",
"mvc/base-mvc",
"utils/localization",
"ui/hoverhighlight"
], function( levenshteinDistance, naturalSort, LIST_COLLECTION_CREATOR, baseMVC, _l ){
], function( levenshteinDistance, naturalSort, baseCreator, baseMVC, _l ){

'use strict';

Expand Down Expand Up @@ -190,7 +190,7 @@ function autoPairFnBuilder( options ){
// ============================================================================
/** An interface for building collections of paired datasets.
*/
var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).extend({
var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).extend( baseCreator.CollectionCreatorMixin ).extend({
_logNamespace : logNamespace,

className: 'list-of-pairs-collection-creator collection-creator flex-row-container',
Expand Down Expand Up @@ -942,6 +942,7 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte
// header
'click .more-help' : '_clickMoreHelp',
'click .less-help' : '_clickLessHelp',
'click .main-help' : '_toggleHelp',
'click .header .alert button' : '_hideAlert',
'click .forward-column .column-title' : '_clickShowOnlyUnpaired',
'click .reverse-column .column-title' : '_clickShowOnlyUnpaired',
Expand Down Expand Up @@ -981,39 +982,10 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte
'change .remove-extensions' : function( ev ){ this.toggleExtensions(); },
'change .collection-name' : '_changeName',
'keydown .collection-name' : '_nameCheckForEnter',
'click .cancel-create' : function( ev ){
if( typeof this.oncancel === 'function' ){
this.oncancel.call( this );
}
},
'click .cancel-create' : '_cancelCreate',
'click .create-collection' : '_clickCreate'//,
},

// ........................................................................ header
/** expand help */
_clickMoreHelp : function( ev ){
this.$( '.main-help' ).addClass( 'expanded' );
this.$( '.more-help' ).hide();
},
/** collapse help */
_clickLessHelp : function( ev ){
this.$( '.main-help' ).removeClass( 'expanded' );
this.$( '.more-help' ).show();
},

/** show an alert on the top of the interface containing message (alertClass is bootstrap's alert-*)*/
_showAlert : function( message, alertClass ){
alertClass = alertClass || 'alert-danger';
this.$( '.main-help' ).hide();
this.$( '.header .alert' ).attr( 'class', 'alert alert-dismissable' ).addClass( alertClass ).show()
.find( '.alert-message' ).html( message );
},
/** hide the alerts at the top */
_hideAlert : function( message ){
this.$( '.main-help' ).show();
this.$( '.header .alert' ).hide();
},

/** toggle between showing only unpaired and split view */
_clickShowOnlyUnpaired : function( ev ){
//this.debug( 'click unpaired', ev.currentTarget );
Expand Down Expand Up @@ -1419,33 +1391,6 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte
creator._renderFooter();
},

/** handle a collection name change */
_changeName : function( ev ){
this._validationWarning( 'name', !!this._getName() );
},

/** check for enter key press when in the collection name and submit */
_nameCheckForEnter : function( ev ){
if( ev.keyCode === 13 && !this.blocking ){
this._clickCreate();
}
},

/** get the current collection name */
_getName : function(){
return _.escape( this.$( '.collection-name' ).val() );
},

/** attempt to create the current collection */
_clickCreate : function( ev ){
var name = this._getName();
if( !name ){
this._validationWarning( 'name' );
} else if( !this.blocking ){
this.createList();
}
},

// ------------------------------------------------------------------------ misc
/** debug a dataset list */
_printList : function( list ){
Expand Down Expand Up @@ -1473,14 +1418,7 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte
//TODO: underscore currently unnecc. bc no vars are used
//TODO: better way of localizing text-nodes in long strings
/** underscore template fns attached to class */
PairedCollectionCreator.templates = PairedCollectionCreator.templates || {

/** the skeleton */
main : _.template([
'<div class="header flex-row no-flex"></div>',
'<div class="middle flex-row flex-row-container"></div>',
'<div class="footer flex-row no-flex">'
].join('')),
PairedCollectionCreator.templates = PairedCollectionCreator.templates || _.extend(baseCreator.CollectionCreatorMixin._creatorTemplates, {

/** the header (not including help text) */
header : _.template([
Expand Down Expand Up @@ -1665,7 +1603,7 @@ PairedCollectionCreator.templates = PairedCollectionCreator.templates || {
'(Note: you do not have to pair all unpaired datasets to finish.)'
].join( '' )), '</p>'
].join(''))
};
});


//=============================================================================
Expand Down
1 change: 1 addition & 0 deletions static/maps/mvc/collection/base-creator.js.map

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

Loading

0 comments on commit a5b0e76

Please sign in to comment.