mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
UI, History: hack multiple copy by API into the 'histories shared with me' mako grid
This commit is contained in:
@@ -114,7 +114,7 @@ AjaxQueue.prototype.progress = function progress( fn ){
|
||||
* @returns {Deferred} the queue's main deferred
|
||||
*/
|
||||
AjaxQueue.create = function create( initialFunctions ){
|
||||
return new AjaxQeueue( initialFunctions ).deferred;
|
||||
return new AjaxQueue( initialFunctions ).deferred;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"ajax-queue.js","sources":["../../src/utils/ajax-queue.js"],"names":["define","AjaxQueue","initialFunctions","self","this","deferred","jQuery","Deferred","queue","responses","numToProcess","running","init","start","NamedAjaxQueue","names","call","prototype","forEach","fn","add","index","length","push","fnIndex","xhr","done","response","notify","curr","total","always","shift","stop","causeFail","msg","reject","resolve","fail","progress","create","AjaxQeueue","constructor","obj","hasOwnProperty","Error","JSON","stringify","name","clear"],"mappings":"AAAAA,UACG,WAWH,QAASC,GAAWC,GAEhB,GAAIC,GAAOC,IAeX,OAbAD,GAAKE,SAAWC,OAAOC,WAEvBJ,EAAKK,SAELL,EAAKM,aAELN,EAAKO,aAAe,EAEpBP,EAAKQ,SAAU,EAEfR,EAAKS,KAAMV,OACXC,EAAKU,QAEEV,EAsGX,QAASW,GAAgBZ,GACrB,GAAIC,GAAOC,IAGX,OAFAD,GAAKY,SACLd,EAAUe,KAAMZ,KAAMF,GACfC,EAoCP,MA1IJF,GAAUgB,UAAUL,KAAO,SAAeV,GACtC,GAAIC,GAAOC,IACXF,GAAiBgB,QAAS,SAAUC,GAChChB,EAAKiB,IAAKD,MAKlBlB,EAAUgB,UAAUG,IAAM,SAAcD,GAEpC,GAAIhB,GAAOC,KACPiB,EAAQjB,KAAKI,MAAMc,MACvBlB,MAAKM,cAAgB,EAErBN,KAAKI,MAAMe,KAAM,WACb,GAAIC,GAAUH,EACVI,EAAMN,GAEVM,GAAIC,KAA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EAAIxB,MAK5CL,EAAeG,UAAUgC,MAAQ,WAC7B7C,KAAKW,UAMTD,EAAe0B,OAAS,SAAiBtC,GACrC,MAAO,IAAIY,GAAgBZ,GAAmBG,WAM1CJ,UAAkBA,EAClBa,eAAkBA"}
|
||||
{"version":3,"file":"ajax-queue.js","sources":["../../src/utils/ajax-queue.js"],"names":["define","AjaxQueue","initialFunctions","self","this","deferred","jQuery","Deferred","queue","responses","numToProcess","running","init","start","NamedAjaxQueue","names","call","prototype","forEach","fn","add","index","length","push","fnIndex","xhr","done","response","notify","curr","total","always","shift","stop","causeFail","msg","reject","resolve","fail","progress","create","constructor","obj","hasOwnProperty","Error","JSON","stringify","name","clear"],"mappings":"AAAAA,UACG,WAWH,QAASC,GAAWC,GAEhB,GAAIC,GAAOC,IAeX,OAbAD,GAAKE,SAAWC,OAAOC,WAEvBJ,EAAKK,SAELL,EAAKM,aAELN,EAAKO,aAAe,EAEpBP,EAAKQ,SAAU,EAEfR,EAAKS,KAAMV,OACXC,EAAKU,QAEEV,EAsGX,QAASW,GAAgBZ,GACrB,GAAIC,GAAOC,IAGX,OAFAD,GAAKY,SACLd,EAAUe,KAAMZ,KAAMF,GACfC,EAoCP,MA1IJF,GAAUgB,UAAUL,KAAO,SAAeV,GACtC,GAAIC,GAAOC,IACXF,GAAiBgB,QAAS,SAAUC,GAChChB,EAAKiB,IAAKD,MAKlBlB,EAAUgB,UAAUG,IAAM,SAAcD,GAEpC,GAAIhB,GAAOC,KACPiB,EAAQjB,KAAKI,MAAMc,MACvBlB,MAAKM,cAAgB,EAErBN,KAAKI,MAAMe,KAAM,WACb,GAAIC,GAAUH,EACVI,EAAMN,GAEVM,GAAIC,KAAM,SAAUC,GAChBxB,EAAKE,SAASuB,QAASC,KAAML,EAASM,MAAO3B,EAAKO,aAAciB,SAAUA,MAI9EF,EAAIM,OAAQ,SAAUJ,GAClBxB,EAAKM,UAAUc,KAAMI,GACjBxB,EAAKK,MAAMc,OACXnB,EAAKK,MAAMwB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||
define([],function(){function a(a){var b=this;return b.deferred=jQuery.Deferred(),b.queue=[],b.responses=[],b.numToProcess=0,b.running=!1,b.init(a||[]),b.start(),b}function b(b){var c=this;return c.names={},a.call(this,b),c}return a.prototype.init=function(a){var b=this;a.forEach(function(a){b.add(a)})},a.prototype.add=function(a){var b=this,c=this.queue.length;this.numToProcess+=1,this.queue.push(function(){var d=c,e=a();e.done(function(a){b.deferred.notify({curr:d,total:b.numToProcess,response:a})}),e.always(function(a){b.responses.push(a),b.queue.length?b.queue.shift()():b.stop()})})},a.prototype.start=function(){this.queue.length&&(this.running=!0,this.queue.shift()())},a.prototype.stop=function(a,b){return this.running=!1,this.queue=[],a?this.deferred.reject(b):this.deferred.resolve(this.responses),this.numToProcess=0,this.deferred=jQuery.Deferred(),this},a.prototype.done=function(a){return this.deferred.done(a)},a.prototype.fail=function(a){return this.deferred.fail(a)},a.prototype.always=function(a){return this.deferred.always(a)},a.prototype.progress=function(a){return this.deferred.progress(a)},a.create=function(a){return new AjaxQeueue(a).deferred},b.prototype=new a,b.prototype.constructor=b,b.prototype.add=function(b){if(!b.hasOwnProperty("name")||!b.hasOwnProperty("fn"))throw new Error('NamedAjaxQueue.add requires an object with both "name" and "fn": '+JSON.stringify(b));this.names.hasOwnProperty(b.name)||(this.names[b.name]=!0,a.prototype.add.call(this,b.fn))},b.prototype.clear=function(){this.names={}},b.create=function(a){return new b(a).deferred},{AjaxQueue:a,NamedAjaxQueue:b}});
|
||||
//# sourceMappingURL=../../maps/utils/ajax-queue.js.map
|
||||
define([], function() {
|
||||
function AjaxQueue(initialFunctions) {
|
||||
var self = this;
|
||||
return self.deferred = jQuery.Deferred(), self.queue = [], self.responses = [],
|
||||
self.numToProcess = 0, self.running = !1, self.init(initialFunctions || []), self.start(),
|
||||
self;
|
||||
}
|
||||
function NamedAjaxQueue(initialFunctions) {
|
||||
var self = this;
|
||||
return self.names = {}, AjaxQueue.call(this, initialFunctions), self;
|
||||
}
|
||||
return AjaxQueue.prototype.init = function(initialFunctions) {
|
||||
var self = this;
|
||||
initialFunctions.forEach(function(fn) {
|
||||
self.add(fn);
|
||||
});
|
||||
}, AjaxQueue.prototype.add = function(fn) {
|
||||
var self = this, index = this.queue.length;
|
||||
this.numToProcess += 1, this.queue.push(function() {
|
||||
var fnIndex = index, xhr = fn();
|
||||
xhr.done(function(response) {
|
||||
self.deferred.notify({
|
||||
curr: fnIndex,
|
||||
total: self.numToProcess,
|
||||
response: response
|
||||
});
|
||||
}), xhr.always(function(response) {
|
||||
self.responses.push(response), self.queue.length ? self.queue.shift()() : self.stop();
|
||||
});
|
||||
});
|
||||
}, AjaxQueue.prototype.start = function() {
|
||||
this.queue.length && (this.running = !0, this.queue.shift()());
|
||||
}, AjaxQueue.prototype.stop = function(causeFail, msg) {
|
||||
return this.running = !1, this.queue = [], causeFail ? this.deferred.reject(msg) : this.deferred.resolve(this.responses),
|
||||
this.numToProcess = 0, this.deferred = jQuery.Deferred(), this;
|
||||
}, AjaxQueue.prototype.done = function(fn) {
|
||||
return this.deferred.done(fn);
|
||||
}, AjaxQueue.prototype.fail = function(fn) {
|
||||
return this.deferred.fail(fn);
|
||||
}, AjaxQueue.prototype.always = function(fn) {
|
||||
return this.deferred.always(fn);
|
||||
}, AjaxQueue.prototype.progress = function(fn) {
|
||||
return this.deferred.progress(fn);
|
||||
}, AjaxQueue.create = function(initialFunctions) {
|
||||
return new AjaxQueue(initialFunctions).deferred;
|
||||
}, NamedAjaxQueue.prototype = new AjaxQueue(), NamedAjaxQueue.prototype.constructor = NamedAjaxQueue,
|
||||
NamedAjaxQueue.prototype.add = function(obj) {
|
||||
if (!obj.hasOwnProperty("name") || !obj.hasOwnProperty("fn")) throw new Error('NamedAjaxQueue.add requires an object with both "name" and "fn": ' + JSON.stringify(obj));
|
||||
this.names.hasOwnProperty(obj.name) || (this.names[obj.name] = !0, AjaxQueue.prototype.add.call(this, obj.fn));
|
||||
}, NamedAjaxQueue.prototype.clear = function() {
|
||||
this.names = {};
|
||||
}, NamedAjaxQueue.create = function(initialFunctions) {
|
||||
return new NamedAjaxQueue(initialFunctions).deferred;
|
||||
}, {
|
||||
AjaxQueue: AjaxQueue,
|
||||
NamedAjaxQueue: NamedAjaxQueue
|
||||
};
|
||||
});
|
||||
@@ -8,7 +8,17 @@
|
||||
## define the module required below
|
||||
${copy_dialog_hack()}
|
||||
<script type="text/javascript">
|
||||
require([ 'copy-dialog-hack' ], function( copyDialogHack ){
|
||||
require([
|
||||
'copy-dialog-hack',
|
||||
'mvc/history/history-model',
|
||||
'utils/ajax-queue'
|
||||
], function( copyDialogHack, HISTORY, AJAX_QUEUE ){
|
||||
|
||||
function sharedNameFn( name, owner ){
|
||||
return [ _l( 'Copy of' ), name, _l( 'shared by' ), owner, _l( '(active items only)' ) ].join( ' ' );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- insert a popupmenu multiple copy
|
||||
function findHistoryId( menuButton ){
|
||||
return $( menuButton ).children( 'label' ).attr( 'id' );
|
||||
}
|
||||
@@ -21,19 +31,69 @@
|
||||
dialogOptions = {
|
||||
allowAll : false,
|
||||
nameFn : function( o ){
|
||||
// special special name
|
||||
var name = "'" + _.escape( o.name ) + "'";
|
||||
return [
|
||||
_l( 'Copy of' ), name, _l( 'shared by' ), sharedBy, _l( '(active items only)' )
|
||||
].join( ' ' );
|
||||
return sharedNameFn( "'" + _.escape( o.name ) + "'", sharedBy );
|
||||
}
|
||||
};
|
||||
|
||||
copyDialogHack.call( this, i, findHistoryId, dialogOptions );
|
||||
});
|
||||
|
||||
## TODO: multiple copy
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- insert a new 'for n histories' copy
|
||||
var setAsCurrent = false,
|
||||
allDatasets = false;
|
||||
// a function that accepts a number of history ids, attempts to copy them via the API, and update the user
|
||||
function ajaxCopyMultipleHistories( historyData ){
|
||||
if( !historyData.length ){ return jQuery.when(); }
|
||||
|
||||
var queue = new AJAX_QUEUE.AjaxQueue( historyData.map( function( data ){
|
||||
// create a series of functions that make ajax calls from the data scraped from the grid table
|
||||
return function(){
|
||||
var history = new HISTORY.History({ id: data.id });
|
||||
return history.copy( setAsCurrent, sharedNameFn( data.name, data.owner ), allDatasets );
|
||||
}
|
||||
}));
|
||||
// quick and dirty qarl
|
||||
queue.progress( function( call ){
|
||||
// show a timed message (like what existing before) that each has been copied
|
||||
var $msg = $( '<div class="donemessage"/>' )
|
||||
.text( '"' + call.response.name + '" copied' )
|
||||
.css( 'margin-bottom', '4px' );
|
||||
$( '#grid-message' ).append( $msg );
|
||||
_.delay( function(){ $msg.remove() }, 5000 );
|
||||
});
|
||||
return queue;
|
||||
}
|
||||
|
||||
// wait for page ready and set it all up
|
||||
$(function(){
|
||||
// remove any previous handlers and actual hrefs
|
||||
var $copyMultipleBtn = $( '.operation-button[value="Copy"]' )
|
||||
.off( 'click' ).attr( 'href', 'javascript:void(0)' );
|
||||
|
||||
// insert a function that gathers all ids, names, and users and sends them to the ajax queue
|
||||
$copyMultipleBtn.click( function( ev ){
|
||||
ev.preventDefault();
|
||||
var ids = $( '#grid-table td:first-child input:checked' ).toArray().map( function( input ){
|
||||
var $tr = $( input ).parent().parent();
|
||||
return {
|
||||
id : input.getAttribute( 'id' ),
|
||||
owner : $tr.children( 'td:last-child' ).text(),
|
||||
name : $tr.find( 'td:nth-child(2) .popup.menubutton label' ).text(),
|
||||
};
|
||||
});
|
||||
ajaxCopyMultipleHistories( ids )
|
||||
.fail( function(){
|
||||
console.error( 'multiple copy failed:', arguments );
|
||||
$( '#grid-message' ).html([
|
||||
'<div class="donemessage">',
|
||||
_l( 'An error occurred during a copy. Please contact a Galaxy administrator.' ),
|
||||
'</div>'
|
||||
].join( '' ));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
Reference in New Issue
Block a user