Skip to content

Commit

Permalink
Merge pull request #742 from carlfeberhard/history.copy-dialog
Browse files Browse the repository at this point in the history
History copy dialog & API fix
  • Loading branch information
martenson committed Sep 17, 2015
2 parents 63e3596 + 3f71220 commit fec26b3
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 77 deletions.
100 changes: 100 additions & 0 deletions client/galaxy/scripts/mvc/history/copy-dialog.js
@@ -0,0 +1,100 @@
define([
"utils/localization"
], function( _l ){
/* =============================================================================
Wrapper function around the global Galaxy.modal for use when copying histories.
==============================================================================*/
function _renderBody( vars ){
return [
'<form action="">',
'<label for="copy-modal-title">',
_l( 'Enter a title for the copied history' ), ':',
'</label><br />',
'<input id="copy-modal-title" class="form-control" style="width: 100%" value="', vars.defaultCopyName, '" />',
'<br />',
'<p>', _l( 'You can make a copy of the history that includes all datasets in the original history' ),
_l( ' or just the active (not deleted) datasets.' ), '</p>',
// copy non-deleted is the default
'<input name="copy-what" type="radio" id="copy-non-deleted" value="copy-non-deleted" checked />',
'<label for="copy-non-deleted">', _l( 'Copy only active (not deleted) datasets' ), '</label><br />',
'<input name="copy-what" type="radio" id="copy-all" value="copy-all" />',
'<label for="copy-all">', _l( 'Copy all datasets, including deleted ones' ), '</label><br />',
'</form>'
].join('');
}

function _validateName( name ){
if( !name ){
if( !Galaxy.modal.$( '#invalid-title' ).size() ){
var $invalidTitle = $( '<p/>' ).attr( 'id', 'invalid-title' )
.css({ color: 'red', 'margin-top': '8px' })
.addClass( 'bg-danger' ).text( _l( 'Please enter a valid history title' ) );
Galaxy.modal.$( '.modal-body' ).append( $invalidTitle );
}
return false;
}
return name;
}

function _renderCopyIndicator(){
return $([
'<p>', '<span class="fa fa-spinner fa-spin"></span> ', _l( 'Copying history' ), '...', '</p>'
].join( '' ))
//TODO: move out of inline
.css({ 'margin-top': '8px' });
}

/** show the dialog and handle validation, ajax, and callbacks */
function historyCopyDialog( history, options ){
options = options || {};
// fall back to un-notifying copy
if( !( Galaxy && Galaxy.modal ) ){
return history.copy();
}

// maybe better as multiselect dialog?
var historyName = history.get( 'name' ),
defaultCopyName = "Copy of '" + historyName + "'";

function copyHistory( name ){
var copyAllDatasets = Galaxy.modal.$( 'input[name="copy-what"]:checked' ).val() === 'copy-all',
$copyIndicator = _renderCopyIndicator();
Galaxy.modal.$( '.modal-body' ).children().replaceWith( $copyIndicator );
Galaxy.modal.$( 'button' ).prop( 'disabled', true );
history.copy( true, name, copyAllDatasets )
//TODO: make this unneccessary with pub-sub error or handling via Galaxy
.fail( function(){
alert( _l( 'History could not be copied. Please contact a Galaxy administrator' ) );
})
.always( function(){
Galaxy.modal.hide();
});
}
function checkNameAndCopy(){
var name = Galaxy.modal.$( '#copy-modal-title' ).val();
if( !_validateName( name ) ){ return; }
copyHistory( name );
}

Galaxy.modal.show( _.extend({
title : _l( 'Copying history' ) + ' "' + historyName + '"',
body : $( _renderBody({ defaultCopyName: defaultCopyName }) ),
buttons : {
'Cancel' : function(){ Galaxy.modal.hide(); },
'Copy' : checkNameAndCopy
},
closing_events : true
}, options ));
$( '#copy-modal-title' ).focus().select();
$( '#copy-modal-title' ).on( 'keydown', function( ev ){
if( ev.keyCode === 13 ){
checkNameAndCopy();
}
});
// TODO: return a promise completed on copy, close, or error
}

//==============================================================================
return historyCopyDialog;
});
8 changes: 5 additions & 3 deletions client/galaxy/scripts/mvc/history/history-model.js
@@ -1,3 +1,4 @@

define([
"mvc/history/history-contents",
"utils/utils",
Expand Down Expand Up @@ -243,7 +244,7 @@ var History = Backbone.Model.extend( BASE_MVC.LoggableMixin ).extend(
* @fires copied passed this history and the response JSON from the copy
* @returns {xhr}
*/
copy : function( current, name ){
copy : function( current, name, allDatasets ){
current = ( current !== undefined )?( current ):( true );
if( !this.id ){
throw new Error( 'You must set the history ID before copying it.' );
Expand All @@ -256,8 +257,9 @@ var History = Backbone.Model.extend( BASE_MVC.LoggableMixin ).extend(
if( name ){
postData.name = name;
}

//TODO:?? all datasets?
if( !allDatasets ){
postData.all_datasets = false;
}

var history = this,
copy = jQuery.post( this.urlRoot, postData );
Expand Down
71 changes: 2 additions & 69 deletions client/galaxy/scripts/mvc/history/multi-panel.js
@@ -1,79 +1,12 @@
define([
"mvc/history/history-model",
"mvc/history/history-panel-edit",
"mvc/history/copy-dialog",
"mvc/base-mvc",
"utils/ajax-queue",
"ui/mode-button",
"ui/search-input"
], function( HISTORY_MODEL, HPANEL_EDIT, baseMVC, ajaxQueue ){
//==============================================================================
/** */
function historyCopyDialog( history, options ){
options = options || {};
// fall back to un-notifying copy
if( !( Galaxy && Galaxy.modal ) ){
return history.copy();
}

// maybe better as multiselect dialog?
var historyName = history.get( 'name' ),
defaultCopyName = "Copy of '" + historyName + "'";

function validateName( name ){
if( !name ){
if( !Galaxy.modal.$( '#invalid-title' ).size() ){
var $invalidTitle = $( '<p/>' ).attr( 'id', 'invalid-title' )
.css({ color: 'red', 'margin-top': '8px' })
.addClass( 'bg-danger' ).text( _l( 'Please enter a valid history title' ) );
Galaxy.modal.$( '.modal-body' ).append( $invalidTitle );
}
return false;
}
return name;
}

function copyHistory( name ){
var $copyIndicator = $( '<p><span class="fa fa-spinner fa-spin"></span> Copying history...</p>' )
.css( 'margin-top', '8px' );
Galaxy.modal.$( '.modal-body' ).append( $copyIndicator );
history.copy( true, name )
//TODO: make this unneccessary with pub-sub error
.fail( function(){
alert( _l( 'History could not be copied. Please contact a Galaxy administrator' ) );
})
.always( function(){
Galaxy.modal.hide();
});
}
function checkNameAndCopy(){
var name = Galaxy.modal.$( '#copy-modal-title' ).val();
if( !validateName( name ) ){ return; }
copyHistory( name );
}

Galaxy.modal.show( _.extend({
title : _l( 'Copying history' ) + ' "' + historyName + '"',
body : $([
'<label for="copy-modal-title">',
_l( 'Enter a title for the copied history' ), ':',
'</label><br />',
'<input id="copy-modal-title" class="form-control" style="width: 100%" value="',
defaultCopyName, '" />'
].join('')),
buttons : {
'Cancel' : function(){ Galaxy.modal.hide(); },
'Copy' : checkNameAndCopy
}
}, options ));
$( '#copy-modal-title' ).focus().select();
$( '#copy-modal-title' ).on( 'keydown', function( ev ){
if( ev.keyCode === 13 ){
checkNameAndCopy();
}
});
}


], function( HISTORY_MODEL, HPANEL_EDIT, historyCopyDialog, baseMVC, ajaxQueue ){
/* ==============================================================================
TODO:
rendering/delayed rendering is a mess
Expand Down
6 changes: 5 additions & 1 deletion lib/galaxy/webapps/galaxy/api/histories.py
Expand Up @@ -22,6 +22,7 @@

from galaxy.managers import histories, citations, users

from galaxy import util
from galaxy.util import string_as_bool
from galaxy.util import restore_text
from galaxy.web import url_for
Expand Down Expand Up @@ -286,6 +287,7 @@ def create( self, trans, payload, **kwd ):
:param payload: (optional) dictionary structure containing:
* name: the new history's name
* history_id: the id of the history to copy
* all_datasets: copy deleted hdas/hdcas? 'True' or 'False', defaults to True
* archive_source: the url that will generate the archive to import
* archive_type: 'url' (default)
Expand All @@ -300,6 +302,8 @@ def create( self, trans, payload, **kwd ):
hist_name = restore_text( payload['name'] )
copy_this_history_id = payload.get( 'history_id', None )

all_datasets = util.string_as_bool( payload.get( 'all_datasets', True ) )

if "archive_source" in payload:
archive_source = payload[ "archive_source" ]
archive_type = payload.get( "archive_type", "url" )
Expand All @@ -312,7 +316,7 @@ def create( self, trans, payload, **kwd ):
decoded_id = self.decode_id( copy_this_history_id )
original_history = self.history_manager.get_accessible( decoded_id, trans.user, current_history=trans.history )
hist_name = hist_name or ( "Copy of '%s'" % original_history.name )
new_history = original_history.copy( name=hist_name, target_user=trans.user )
new_history = original_history.copy( name=hist_name, target_user=trans.user, all_datasets=all_datasets )

# otherwise, create a new empty history
else:
Expand Down
1 change: 1 addition & 0 deletions static/maps/mvc/history/copy-dialog.js.map

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

0 comments on commit fec26b3

Please sign in to comment.