Add datatypes to api and connect with file type selector of the upload front end

This commit is contained in:
Aysam Guerler
2013-10-11 14:29:38 -04:00
parent ef4641e6ca
commit 8313e096c1
14 changed files with 138 additions and 67 deletions
+25 -14
View File
@@ -3,7 +3,7 @@
*/
// dependencies
define(["galaxy.modal", "galaxy.master", "utils/galaxy.uploadbox", "libs/backbone/backbone-relational"], function(mod_modal, mod_master) {
define(["galaxy.modal", "galaxy.master", "utils/galaxy.utils", "utils/galaxy.uploadbox", "libs/backbone/backbone-relational"], function(mod_modal, mod_master, mod_util) {
// galaxy upload
var GalaxyUpload = Backbone.View.extend(
@@ -69,6 +69,17 @@ var GalaxyUpload = Backbone.View.extend(
// add to master
Galaxy.master.prepend(this.button_show);
// load extension
var self = this;
mod_util.jsonFromUrl(galaxy_config.root + "api/datatypes",
function(datatypes) {
for (key in datatypes) {
var filetype = datatypes[key];
self.select_extension[filetype] = filetype;
}
});
},
// events
@@ -294,9 +305,20 @@ var GalaxyUpload = Backbone.View.extend(
if (this.counter.running == 0)
return;
// initiate upload procedure in plugin
// request pause
this.uploadbox.pause();
// set html content
$('#upload-info').html('Queueing will pause after completing the current file...');
},
// queue is done
event_complete: function()
{
// update running
this.counter.running = 0;
this.update_screen();
// switch icons for new uploads
var items = $(this.el).find('.upload-item');
var self = this;
@@ -314,17 +336,6 @@ var GalaxyUpload = Backbone.View.extend(
$(this).find('#space_to_tabs').attr('disabled', false);
}
});
// set html content
$('#upload-info').html('Queueing will pause after completing the current file.');
},
// queue is done
event_complete: function()
{
// update running
this.counter.running = 0;
this.update_screen();
},
// remove all
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
define(["libs/underscore"],function(a){function b(g,d){var e=$('<div class="'+g+'"></div>');e.appendTo(":eq(0)");var f=e.css(d);e.remove();return f}function c(d){if(!$('link[href^="'+d+'"]').length){$('<link href="'+galaxy_config.root+d+'" rel="stylesheet">').appendTo("head")}}return{load_file:c,get_attribute:b}});
@@ -1 +1 @@
(function(g){jQuery.event.props.push("dataTransfer");var c={url:"",paramname:"content",maxfilesize:250,maxfilenumber:20,dragover:function(){},dragleave:function(){},announce:function(){},initialize:function(){},progress:function(){},success:function(){},error:function(i,j,k){alert(k)},complete:function(){},error_filesize:"File exceeds 250MB. Please use an FTP client.",error_default:"Please make sure the file is available.",error_toomany:"You can only queue <20 files per upload session."};var f={};var a={};var b=0;var d=0;var h=false;var e=null;g.fn.uploadbox=function(y){f=g.extend({},c,y);e=this;e.append('<input id="uploadbox_input" type="file" style="display: none" multiple>');e.on("drop",l);e.on("dragover",m);e.on("dragleave",t);g("#uploadbox_input").change(function(z){v(z.target.files);g(this).val("")});function l(z){if(!z.dataTransfer){return}v(z.dataTransfer.files);z.preventDefault();return false}function m(z){z.preventDefault();f.dragover.call(z)}function t(z){z.stopPropagation();f.dragleave.call(z)}function i(z){if(z.lengthComputable){f.progress(this.index,this.file,Math.round((z.loaded*100)/z.total))}}function v(B){if(h){return}for(var A=0;A<B.length;A++){if(d>=f.maxfilenumber){break}var z=String(b++);a[z]=B[A];f.announce(z,a[z],"");d++}}function o(z){if(a[z]){delete a[z];d--}}function j(){if(d==0||!h){h=false;f.complete();return}else{h=true}var C=-1;for(var E in a){C=E;break}var D=a[C];o(C);var G=f.initialize(C,D);try{var A=new FileReader();var B=D.size;var z=1048576*f.maxfilesize;A.index=C;if(B<z){A.onload=function(H){n(C,D,G)};A.onerror=function(H){r(C,D,f.error_default)};A.readAsDataURL(D)}else{r(C,D,f.error_filesize)}}catch(F){r(C,D,F)}}function n(z,B,C){var D=new FormData();for(var A in C){D.append(A,C[A])}D.append(f.paramname,B,B.name);var E=new XMLHttpRequest();E.onloadend=function(){var F=null;if(E.responseText){try{F=jQuery.parseJSON(E.responseText)}catch(G){F=E.responseText}}if(E.status<200||E.status>299){var H=E.statusText;if(!E.statusText){H=f.error_default}r(z,B,H+" (Server Code "+E.status+")")}else{u(z,B,F)}};E.upload.index=z;E.upload.file=B;E.upload.addEventListener("progress",i,false);E.open("POST",f.url,true);E.setRequestHeader("Accept","application/json");E.setRequestHeader("Cache-Control","no-cache");E.setRequestHeader("X-Requested-With","XMLHttpRequest");E.send(D)}function u(z,A,B){f.success(z,A,B);j()}function r(z,A,B){f.error(z,A,B);j()}function s(){g("#uploadbox_input").trigger("click")}function q(z){for(z in a){o(z)}}function x(){if(!h){h=true;j()}}function w(){h=false}function k(z){f=g.extend({},f,z);return f}function p(){return window.File&&window.FileReader&&window.FormData&&window.XMLHttpRequest&&window.FileList}return{select:s,remove:o,upload:x,pause:w,reset:q,configure:k,compatible:p}}})(jQuery);
(function(d){jQuery.event.props.push("dataTransfer");var h={url:"",paramname:"content",maxfilesize:250,maxfilenumber:20,dragover:function(){},dragleave:function(){},announce:function(){},initialize:function(){},progress:function(){},success:function(){},error:function(j,k,l){alert(l)},complete:function(){},error_filesize:"File exceeds 250MB. Please use an FTP client.",error_default:"Please make sure the file is available.",error_server:"The server is unavailable.",error_toomany:"You can only queue <20 files per upload session."};var b={};var f={};var g=0;var i=0;var e=false;var a=false;var c=null;d.fn.uploadbox=function(z){b=d.extend({},h,z);c=this;c.append('<input id="uploadbox_input" type="file" style="display: none" multiple>');c.on("drop",m);c.on("dragover",n);c.on("dragleave",u);d("#uploadbox_input").change(function(A){w(A.target.files);d(this).val("")});function m(A){if(!A.dataTransfer){return}w(A.dataTransfer.files);A.preventDefault();return false}function n(A){A.preventDefault();b.dragover.call(A)}function u(A){A.stopPropagation();b.dragleave.call(A)}function j(A){if(A.lengthComputable){b.progress(this.index,this.file,Math.round((A.loaded*100)/A.total))}}function w(C){if(e){return}for(var B=0;B<C.length;B++){if(i>=b.maxfilenumber){break}var A=String(g++);f[A]=C[B];b.announce(A,f[A],"");i++}}function p(A){if(f[A]){delete f[A];i--}}function k(){if(i==0||a){a=false;e=false;b.complete();return}else{e=true}var D=-1;for(var F in f){D=F;break}var E=f[D];p(D);var H=b.initialize(D,E);try{var B=new FileReader();var C=E.size;var A=1048576*b.maxfilesize;B.index=D;if(C<A){B.onload=function(I){o(D,E,H)};B.onerror=function(I){s(D,E,b.error_default)};B.onabort=function(I){s(D,E,b.error_default)};B.readAsDataURL(E)}else{s(D,E,b.error_filesize)}}catch(G){s(D,E,G)}}function o(A,C,D){var E=new FormData();for(var B in D){E.append(B,D[B])}E.append(b.paramname,C,C.name);var F=new XMLHttpRequest();F.onreadystatechange=function(){if(F.readyState!=F.DONE){return}var G=null;if(F.responseText){try{G=jQuery.parseJSON(F.responseText)}catch(H){G=F.responseText}}if(F.status<200||F.status>299){var I=F.statusText;if(!F.statusText){if(F.status==0){I=b.error_server}else{I=b.error_default}}s(A,C,I+" ("+F.status+")")}else{v(A,C,G)}};F.upload.index=A;F.upload.file=C;F.upload.addEventListener("progress",j,false);F.open("POST",b.url,true);F.setRequestHeader("Accept","application/json");F.setRequestHeader("Cache-Control","no-cache");F.setRequestHeader("X-Requested-With","XMLHttpRequest");F.send(E)}function v(A,B,C){b.success(A,B,C);k()}function s(A,B,C){b.error(A,B,C);k()}function t(){d("#uploadbox_input").trigger("click")}function r(A){for(A in f){p(A)}}function y(){if(!e){e=true;k()}}function x(){a=true}function l(A){b=d.extend({},b,A);return b}function q(){return window.File&&window.FileReader&&window.FormData&&window.XMLHttpRequest&&window.FileList}return{select:t,remove:p,upload:y,pause:x,reset:r,configure:l,compatible:q}}})(jQuery);
@@ -0,0 +1 @@
define(["libs/underscore"],function(c){function d(g,f,e){var h=new XMLHttpRequest();h.open("GET",g,true);h.setRequestHeader("Accept","application/json");h.setRequestHeader("Cache-Control","no-cache");h.setRequestHeader("X-Requested-With","XMLHttpRequest");h.onloadend=function(){var i=h.status;if(i==200){try{response=jQuery.parseJSON(h.responseText)}catch(j){response=h.responseText}f&&f(response)}else{e&&e(i)}};h.send()}function b(h,e){var f=$('<div class="'+h+'"></div>');f.appendTo(":eq(0)");var g=f.css(e);f.remove();return g}function a(e){if(!$('link[href^="'+e+'"]').length){$('<link href="'+galaxy_config.root+e+'" rel="stylesheet">').appendTo("head")}}return{cssLoadFile:a,cssGetAttribute:b,jsonFromUrl:d}});
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-41
View File
@@ -1,41 +0,0 @@
/**
* Galaxy CSS utilities
*/
// dependencies
define(["libs/underscore"], function(_) {
// get css value
function get_attribute (classname, name)
{
// place dummy element
var el = $('<div class="' + classname + '"></div>');
// required append
el.appendTo(':eq(0)');
// get value
var value = el.css(name);
// remove element
el.remove();
// return css value
return value;
}
// load css
function load_file (url)
{
// check if css is already available
if (!$('link[href^="' + url + '"]').length)
$('<link href="' + galaxy_config.root + url + '" rel="stylesheet">').appendTo('head');
};
// return
return {
load_file : load_file,
get_attribute : get_attribute
};
});
+5 -3
View File
@@ -41,6 +41,7 @@
// indicates if queue is currently running
var queue_running = false;
var queue_pause = false;
// element
var el = null;
@@ -155,8 +156,9 @@
function process()
{
// validate
if (queue_length == 0 || !queue_running)
if (queue_length == 0 || queue_pause)
{
queue_pause = false;
queue_running = false;
opts.complete();
return;
@@ -338,8 +340,8 @@
// pause upload process
function pause()
{
// set global status variable to false
queue_running = false;
// request pause
queue_pause = true;
}
// set options
+73
View File
@@ -0,0 +1,73 @@
/**
* Galaxy utilities comprises small functions, which at this point
* do not require their own classes/files
*/
// dependencies
define(["libs/underscore"], function(_) {
// generic function to recieve json from url
function jsonFromUrl (url, successHandler, errorHandler) {
// open url
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
// configure request
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
// on completion
xhr.onloadend = function() {
var status = xhr.status;
if (status == 200) {
try
{
response = jQuery.parseJSON(xhr.responseText);
} catch (e) {
response = xhr.responseText;
}
successHandler && successHandler(response);
} else {
errorHandler && errorHandler(status);
}
};
// submit request
xhr.send();
};
// get css value
function cssGetAttribute (classname, name) {
// place dummy element
var el = $('<div class="' + classname + '"></div>');
// required append
el.appendTo(':eq(0)');
// get value
var value = el.css(name);
// remove element
el.remove();
// return css value
return value;
};
// load css
function cssLoadFile (url) {
// check if css is already available
if (!$('link[href^="' + url + '"]').length)
$('<link href="' + galaxy_config.root + url + '" rel="stylesheet">').appendTo('head');
};
// return
return {
cssLoadFile : cssLoadFile,
cssGetAttribute : cssGetAttribute,
jsonFromUrl : jsonFromUrl
};
});
+2 -2
View File
@@ -1125,10 +1125,10 @@ ul.icons{list-style-type:none;text-indent:-0.75em}ul.icons li [class^="fa-icon-"
.galaxy-frame .frame .f-pin{left:6px;top:1px}
.galaxy-frame .frame .f-resize{background:#fff;width:16px;height:16px;color:#2c3143;right:0px;bottom:0px;text-align:center;line-height:16px;border:0px}
.upload-info{font-weight:normal;text-align:center}
.upload-box{width:100%;height:90%;text-align:center;overflow:scroll;font-size:12px;line-height:1.33;-moz-border-radius:5px;border-radius:5px;border:1px dashed #bfbfbf;padding:10px}.upload-box .table{width:100%}
.upload-box{width:100%;height:95%;text-align:center;overflow:scroll;font-size:12px;line-height:1.33;-moz-border-radius:5px;border-radius:5px;border:1px dashed #bfbfbf;padding:10px}.upload-box .table{width:100%}
.upload-box .table th{text-align:center;white-space:nowrap}
.upload-box .table td{margin:0px;paddign:0px}
.upload-box .title{width:150px;word-wrap:break-word;font-size:11px}
.upload-box .title{width:120px;word-wrap:break-word;font-size:11px}
.upload-box .size{white-space:nowrap}
.upload-box .info{width:130px;font-size:11px}.upload-box .info .progress{top:1px;position:relative;width:100%;padding:0px;margin:0px}.upload-box .info .progress .progress-bar{border-radius:inherit;-moz-border-radius:inherit}
.upload-box .info .progress .percentage{position:absolute;text-align:center;width:100%;color:#fff}
+2 -2
View File
@@ -7,7 +7,7 @@
.upload-box
{
width : 100%;
height : 90%;
height : 95%;
text-align : center;
overflow : scroll;
font-size : @font-size-base;
@@ -32,7 +32,7 @@
}
.title {
width: 150px;
width: 120px;
word-wrap: break-word;
font-size : @font-size-small;
}