Skip to content
Permalink
Browse files

UI, Collections: better validity checking of collection inputs (must …

…be datasets in the ok state), refactoring
  • Loading branch information...
carlfeberhard committed Mar 20, 2015
1 parent 535fc9c commit 0c796800ea788152265e11f250a56f48330a6fa7
@@ -1,27 +1,52 @@
define([
"mvc/collection/collection-model",
"mvc/dataset/states",
"mvc/ui/error-modal",
"utils/localization"
], function( DC_MODEL, _l ){
], function( STATES, errorModal, _l ){
/*==============================================================================
==============================================================================*/
function createListCollection( collection ){
//TODO: filter out non-datasets, non-ready
//TODO: fail if no valid elements remain
//return jQuery.Deferred().reject( _l( 'No valid datasets to add' ) );
function validElements( collection ){
var elements = collection.toJSON().filter( function( content ){
return content.history_content_type === 'dataset'
&& content.state === STATES.OK;
});
return elements;
}

var noValidElementsMessage = 'No valid datasets were selected';

function noValidElementsErrorModal(){
errorModal(
'Use the checkboxes at the left of the dataset names to select them. ' +
'Selected datasets should be error-free and should have completed running.',
noValidElementsMessage
);
}

function createListHDCA( collection ){
var name = 'New Dataset List',
elementIdentifiers = collection.toJSON().map( function( element ){
elementIdentifiers = validElements( collection ).map( function( element ){
// TODO: Handle duplicate names.
return {
id : element.id,
name : element.name,
//TODO: this allows for list:list even if the filter above does not - reconcile
src : ( element.history_content_type === 'dataset'? 'hda' : 'hdca' )
}
});
if( !elementIdentifiers.length ){
noValidElementsErrorModal();
return jQuery.Deferred().reject( noValidElementsMessage );
}
return collection.createHDCA( elementIdentifiers, 'list', name );
}

//==============================================================================
return {
createListCollection : createListCollection
validElements : validElements,
noValidElementsMessage : noValidElementsMessage,
noValidElementsErrorModal : noValidElementsErrorModal,
createListHDCA : createListHDCA
};
});
@@ -1,9 +1,10 @@
define([
"utils/levenshtein",
"utils/natural-sort",
"mvc/collection/list-collection-creator",
"mvc/base-mvc",
"utils/localization"
], function( levenshteinDistance, naturalSort, baseMVC, _l ){
], function( levenshteinDistance, naturalSort, LIST_COLLECTION_CREATOR, baseMVC, _l ){
/* ============================================================================
TODO:
@@ -247,6 +248,9 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte
/** DOM elements currently being dragged */
this.$dragging = null;

/** Used for blocking UI events during ajax/operations (don't post twice) */
this.blocking = false;

this._setUpBehaviors();
this._dataSetUp();
},
@@ -576,12 +580,16 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte

};
//this.debug( JSON.stringify( ajaxData ) );
creator.blocking = true;
return jQuery.ajax( url, {
type : 'POST',
contentType : 'application/json',
dataType : 'json',
data : JSON.stringify( ajaxData )
})
.always( function(){
creator.blocking = false;
})
.fail( function( xhr, status, message ){
creator._ajaxErrHandler( xhr, status, message );
})
@@ -855,7 +863,7 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte
what.addClass( VALIDATION_CLASS );
}
},

// ------------------------------------------------------------------------ events
/** set up event handlers on self */
_setUpBehaviors : function(){
@@ -1406,7 +1414,7 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte

/** check for enter key press when in the collection name and submit */
_nameCheckForEnter : function( ev ){
if( ev.keyCode === 13 ){
if( ev.keyCode === 13 && !this.blocking ){
this._clickCreate();
}
},
@@ -1421,7 +1429,7 @@ var PairedCollectionCreator = Backbone.View.extend( baseMVC.LoggableMixin ).exte
var name = this._getName();
if( !name ){
this._validationWarning( 'name' );
} else {
} else if( !this.blocking ){
this.createList();
}
},
@@ -1683,20 +1691,26 @@ PairedCollectionCreator.templates = PairedCollectionCreator.templates || {
/** a modal version of the paired collection creator */
var pairedCollectionCreatorModal = function _pairedCollectionCreatorModal( datasets, options ){

var deferred = jQuery.Deferred(),
creator;

options = _.defaults( options || {}, {
datasets : datasets,
oncancel : function(){ Galaxy.modal.hide(); },
oncreate : function(){
oncancel : function(){
Galaxy.modal.hide();
deferred.reject( 'cancelled' );
},
oncreate : function( creator, response ){
Galaxy.modal.hide();
Galaxy.currHistoryPanel.refreshContents();
deferred.resolve( response );
}
});

if( !window.Galaxy || !Galaxy.modal ){
throw new Error( 'Galaxy or Galaxy.modal not found' );
}

var creator = new PairedCollectionCreator( options );
creator = new PairedCollectionCreator( options );
Galaxy.modal.show({
title : 'Create a collection of paired datasets',
body : creator.$el,
@@ -1705,15 +1719,31 @@ var pairedCollectionCreatorModal = function _pairedCollectionCreatorModal( datas
closing_events: true
});
creator.render();
window.creator = creator;

//TODO: remove modal header
window.PCC = creator;
return creator;
return deferred;
};


//=============================================================================
function createListOfPairsCollection( collection ){
var elements = LIST_COLLECTION_CREATOR.validElements( collection );
if( !elements.length ){
LIST_COLLECTION_CREATOR.noValidElementsErrorModal();
return jQuery.Deferred().reject( LIST_COLLECTION_CREATOR.noValidElementsMessage );
}

return pairedCollectionCreatorModal( elements, {
historyId : collection.historyId
});
}


//=============================================================================
return {
PairedCollectionCreator : PairedCollectionCreator,
pairedCollectionCreatorModal : pairedCollectionCreatorModal
pairedCollectionCreatorModal : pairedCollectionCreatorModal,
createListOfPairsCollection : createListOfPairsCollection
};
});
@@ -0,0 +1,33 @@
define([
"mvc/collection/list-collection-creator",
"mvc/ui/error-modal",
"utils/localization"
], function( LIST_COLLECTION_CREATOR, errorModal, _l ){

function createPairHDCA( collection ){
// currently: datasets in the ok state
var elementsJSON = LIST_COLLECTION_CREATOR.validElements( collection );
if( !elementsJSON.length ){
LIST_COLLECTION_CREATOR.noValidElementsErrorModal();
return jQuery.Deferred().reject( LIST_COLLECTION_CREATOR.noValidElementsMessage );
}
if( elementsJSON.length !== 2 ){
errorModal(
'When pairing datasets, select only two datasets: one forward and one reverse.',
'Not a valid pair'
);
return jQuery.Deferred().reject( LIST_COLLECTION_CREATOR.noValidElementsMessage );
}

var name = 'New Dataset Pair',
elementIdentifiers = [
{ name: "forward", src: "hda", id: elementsJSON[0].id },
{ name: "reverse", src: "hda", id: elementsJSON[1].id }
];
return collection.createHDCA( elementIdentifiers, 'paired', name );
}

return {
createPairHDCA : createPairHDCA
};
});
@@ -8,6 +8,8 @@ define([
"mvc/tags",
"mvc/annotations",
"mvc/collection/list-collection-creator",
"mvc/collection/pair-collection-creator",
"mvc/collection/list-of-pairs-collection-creator",
"ui/fa-icon-button",
"mvc/ui/popup-menu",
"utils/localization"
@@ -21,6 +23,8 @@ define([
TAGS,
ANNOTATIONS,
LIST_COLLECTION_CREATOR,
PAIR_COLLECTION_CREATOR,
LIST_OF_PAIRS_COLLECTION_CREATOR,
faIconButton,
PopupMenu,
_l
@@ -29,47 +33,6 @@ define([
TODO:
============================================================================= */
function createPairCollection( history, collection ){
//TODO: filter out non-datasets, non-ready
//TODO: fail if no valid elements remain
//return jQuery.Deferred().reject( _l( 'No valid datasets to add' ) );
var elementsJSON = collection.toJSON(),
name = 'New Dataset Pair',
elementIdentifiers = [
{ name: "forward", src: "hda", id: elementsJSON[0].id },
{ name: "reverse", src: "hda", id: elementsJSON[1].id }
];
return collection.createHDCA( elementIdentifiers, 'paired', name );
}

function createListOfPairsCollection( history, collection ){
var datasets = collection.toJSON().filter( function( content ){
return content.history_content_type === 'dataset'
&& content.state === STATES.OK;
});

if( datasets.length ){
require([ 'mvc/collection/paired-collection-creator' ], function( creator ){
window.creator = creator.pairedCollectionCreatorModal( datasets, {
historyId : history.id
});
});

} else {
Galaxy.modal.show({
title : _l( 'No valid datasets were selected' ),
body : _l([
'Use the checkboxes at the left of the dataset names to select them.',
'Selected datasets should be error-free and should have completed running.'
].join(' ')),
buttons : { 'Ok': function(){ Galaxy.modal.hide(); } },
closing_events: true
});
}
}


// =============================================================================
var _super = HPANEL.HistoryPanel;
// base class for current-history-panel and used as-is in history/view.mako
/** @class Editable View/Controller for the history model.
@@ -315,23 +278,31 @@ var HistoryPanelEdit = _super.extend(
}
});
}
return actions.concat([
actions = actions.concat( panel._collectionActions() );
return actions;
},

/** */
_collectionActions : function(){
var panel = this;
return [
{ html: _l( 'Build Dataset List' ), func: function() {
LIST_COLLECTION_CREATOR.createListCollection( panel.getSelectedModels() )
LIST_COLLECTION_CREATOR.createListHDCA( panel.getSelectedModels() )
.done( function(){ panel.model.refresh() });
}
},
// TODO: Only show quick pair if two things selected.
{ html: _l( 'Build Dataset Pair' ), func: function() {
createPairCollection( panel.model, panel.getSelectedModels() )
PAIR_COLLECTION_CREATOR.createPairHDCA( panel.getSelectedModels() )
.done( function(){ panel.model.refresh() });
}
},
{ html: _l( 'Build List of Dataset Pairs' ), func: function() {
createListOfPairsCollection( panel.model, panel.getSelectedModels() );
LIST_OF_PAIRS_COLLECTION_CREATOR.createListOfPairsCollection( panel.getSelectedModels() )
.done( function(){ panel.model.refresh() });
}
},
]);
];
},

// ------------------------------------------------------------------------ sub-views
@@ -0,0 +1,29 @@
define([
"utils/localization"
], function( _l ){

function _errorModal( message, title ){
Galaxy.modal.show({
title : _l( title ),
body : _l( message ),
buttons : { 'Ok': function(){ Galaxy.modal.hide(); } },
closing_events: true
});
}

function _errorAlert( message, title ){
alert( title + '\n\n' + message );
}

function errorModal( message, title ){
if( !message ){ return; }
title = title || 'Error';
if( window.Galaxy && Galaxy.modal ){
return _errorModal( message, title );
}
return _errorAlert( message, title );
}


return errorModal;
});

Some generated files are not rendered by default. Learn more.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more.

0 comments on commit 0c79680

Please sign in to comment.
You can’t perform that action at this time.