Skip to content

Commit

Permalink
Reimplement copy operation
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Jun 7, 2017
1 parent 84adc65 commit d931df2
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 120 deletions.
113 changes: 19 additions & 94 deletions client/galaxy/scripts/mvc/history/history-list.js
@@ -1,93 +1,5 @@
/** This class renders the page list. */
define( [ 'utils/utils', 'mvc/grid/grid-view' ], function( Utils, GridView ) {

/*/ define a module that has:
// an hack for which to override the url based history copy function in the popupmenus
// and replace it with a dialog that uses the API instead
define( 'copy-dialog-hack', [
'mvc/history/history-model',
'mvc/history/copy-dialog'
], function( mHistory, historyCopyDialog ){
// callbacks
function tellTheUserItFailed(){
// history failed to copy, put the relevant techy crap in the console and alert the user
console.error( arguments );
alert( "${_('History could not be fetched. Please contact an administrator')}" );
}
function refreshEverything(){
// history was copied
// if we're in a frame, check for the parent Galaxy and try to refresh the history
if( window.parent && window.parent.Galaxy && window.parent.Galaxy.currHistoryPanel ){
window.parent.Galaxy.currHistoryPanel.loadCurrentHistory();
}
// in any case reload the save history panel
window.location.reload( true );
}
// get the id from the dom somehow (the two doms (saved/shared) are different...)
function findHistoryId( $menuButton ){
var title = '${grid.title}';
if( title === 'Saved Histories' ){
var $link = $menuButton.children( '.menubutton-label' );
// TODO: ohdearlord. stahp.
return ( $link.attr( 'href' ).match( /id=(\w+)/ ) || [] )[1];
}
// Histories shared with you
var $label = $menuButton.children( 'label' );
return $label.attr( 'id' );
}
// for each popupmenu, (this == a popup activator button), remove the link and add a click function
// that fetches the history and shows a copy dialog for it
// pass in a fn for extracting the id from the dom and an (optional) object with dialog options
function copyDialogHack( i, historyIdFindFn, dialogOptions ){
dialogOptions = dialogOptions || {};
var $this = $( this ),
historyId = historyIdFindFn( this ),
menuOptions = $this.data( 'popupmenu' ).options,
copyOption = menuOptions.filter( function( o ){ return o.html === 'Copy' })[0];
copyOption.href = 'javascript:void(0)';
copyOption.func = function copyOptionClicked( ev ){
ev.preventDefault();
var history = new mHistory.History({ id : historyId });
history.fetch()
.fail( tellTheUserItFailed )
.done( function(){
historyCopyDialog( history, dialogOptions ).done( refreshEverything );
});
}
}
return copyDialogHack;
});
function findHistoryId( menuButton ){
var $link = $( menuButton ).children( '.menubutton-label' );
// TODO: ohdearlord. stahp.
return ( $link.attr( 'href' ).match( /id=(\w+)/ ) || [] )[1];
}
// wait for page ready and set it all up, do it again when the grid refreshes
$(function(){
if( !gridView ){
console.warn( 'no grid' );
return;
}
function replaceCopyFunction(){
gridView.$( '.popup.menubutton' ).each( function( i ){
copyDialogHack.call( this, i, findHistoryId );
});
}
replaceCopyFunction();
var originalInitGrid = gridView.init_grid;
gridView.init_grid = function __patched_init_grid( json ){
originalInitGrid.call( gridView, json );
replaceCopyFunction();
};
});*/
/** This class renders the grid list. */
define( [ 'utils/utils', 'mvc/grid/grid-view', 'mvc/history/history-model', 'mvc/history/copy-dialog' ], function( Utils, GridView, HistoryModel, historyCopyDialog ) {

var View = Backbone.View.extend({
initialize: function( options ) {
Expand All @@ -98,12 +10,9 @@ define( [ 'utils/utils', 'mvc/grid/grid-view' ], function( Utils, GridView ) {
url : Galaxy.root + 'history/list',
success : function( response ) {
response[ 'dict_format' ] = true;
window.console.log( response );
_.each( response[ 'operations' ], function( operation ) {
if ( operation.label == 'Copy' ) {
operation.onclick = function( id ) {
alert( id );
}
operation.onclick = function( id ) { self._showCopyDialog( id ) };
}
});
self.model.set( response );
Expand All @@ -115,6 +24,22 @@ define( [ 'utils/utils', 'mvc/grid/grid-view' ], function( Utils, GridView ) {
render: function() {
var grid = new GridView( this.model.attributes );
this.$el.empty().append( grid.$el );
},

_showCopyDialog: function( id ) {
var history = new HistoryModel.History( { id : id } );
history.fetch()
.fail( function() {
alert( 'History could not be fetched. Please contact an administrator' );
})
.done( function(){
historyCopyDialog( history, {} ).done( function() {
if( window.parent && window.parent.Galaxy && window.parent.Galaxy.currHistoryPanel ) {
window.parent.Galaxy.currHistoryPanel.loadCurrentHistory();
}
window.location.reload( true );
} );
});
}
});

Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/history/history-list.js.map

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

2 changes: 1 addition & 1 deletion static/scripts/bundled/admin.bundled.js

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

2 changes: 1 addition & 1 deletion static/scripts/bundled/admin.bundled.js.map

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions static/scripts/bundled/analysis.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/analysis.bundled.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions static/scripts/bundled/libs.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/libs.bundled.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/mvc/history/history-list.js

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

0 comments on commit d931df2

Please sign in to comment.