Skip to content

Commit

Permalink
Merge pull request #4513 from guerler/ftp_uploader
Browse files Browse the repository at this point in the history
Allow users to upload multiple FTP files within a single request
  • Loading branch information
jmchilton authored Oct 9, 2017
2 parents 5edc423 + 6081c0b commit e03bedf
Show file tree
Hide file tree
Showing 38 changed files with 469 additions and 334 deletions.
62 changes: 62 additions & 0 deletions client/galaxy/scripts/mvc/lazy/lazy-limited.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/** Contains helpers to limit/lazy load views for backbone views */
define([], function() {
return Backbone.View.extend({
initialize: function( options ) {
var self = this;
this.$container = options.$container;
this.collection = options.collection;
this.new_content = options.new_content;
this.max = options.max || 50;
this.content_list = {}
this.$message = $( '<div/>' ).addClass( 'ui-limitloader' ).append( '...only the first ' + this.max + ' entries are visible.' );
this.$container.append( this.$message );
this.listenTo( this.collection, 'reset', this._reset, this );
this.listenTo( this.collection, 'add', this._refresh, this );
this.listenTo( this.collection, 'remove', this._remove, this );
},

/** Checks if the limit has been reached */
_done: function() {
var done = _.size( this.content_list ) > this.max;
this.$message[ done ? 'show' : 'hide' ]();
return done;
},

/** Remove all content */
_reset: function() {
_.each( this.content_list, function( content ) {
content.remove();
});
this.content_list = {};
this.$message.hide();
},

/** Remove content */
_remove: function( model ) {
var model_id = model.id;
var content = this.content_list[ model_id ];
if ( content ) {
content.remove();
delete this.content_list[ model_id ];
}
this._refresh();
},

/** Refreshes container content by adding new views if visible */
_refresh: function() {
if ( !this._done() ) {
for ( var i in this.collection.models ) {
var model = this.collection.models[ i ];
var view = this.content_list[ model.id ];
if ( !this.content_list[ model.id ] ) {
var content = this.new_content( model );
this.content_list[ model.id ] = content;
if ( this._done() ) {
break;
}
}
}
}
}
});
});
39 changes: 5 additions & 34 deletions client/galaxy/scripts/mvc/upload/collection/collection-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Renders contents of the collection uploader */
define([ 'utils/utils', 'mvc/upload/upload-model', 'mvc/upload/collection/collection-row', 'mvc/upload/upload-ftp', 'mvc/ui/ui-popover', 'mvc/ui/ui-select', 'mvc/ui/ui-misc', 'mvc/collection/list-collection-creator', 'utils/uploadbox' ],
function( Utils, UploadModel, UploadRow, UploadFtp, Popover, Select, Ui, LIST_COLLECTION_CREATOR ) {
define([ 'utils/utils', 'mvc/upload/upload-model', 'mvc/upload/collection/collection-row', 'mvc/upload/upload-ftp', 'mvc/upload/upload-extension','mvc/ui/ui-popover', 'mvc/ui/ui-select', 'mvc/ui/ui-misc', 'mvc/collection/list-collection-creator', 'utils/uploadbox' ],
function( Utils, UploadModel, UploadRow, UploadFtp, UploadExtension, Popover, Select, Ui, LIST_COLLECTION_CREATOR ) {
return Backbone.View.extend({
// current upload size in bytes
upload_size: 0,
Expand Down Expand Up @@ -53,8 +53,6 @@ function( Utils, UploadModel, UploadRow, UploadFtp, Popover, Select, Ui, LIST_CO
ondragleave : function() { self.$( '.upload-box' ).removeClass( 'highlight' ) }
});

console.log(this.list_extensions);

// add ftp file viewer
this.ftp = new Popover.View( { title: 'FTP files', container: this.btnFtp.$el } );

Expand All @@ -78,10 +76,11 @@ function( Utils, UploadModel, UploadRow, UploadFtp, Popover, Select, Ui, LIST_CO

// handle extension info popover
this.$( '.upload-footer-extension-info' ).on( 'click', function( e ) {
self.showExtensionInfo({
new UploadExtension({
$el : $( e.target ),
title : self.select_extension.text(),
extension : self.select_extension.value(),
list : self.list_extensions,
placement : 'top'
});
}).on( 'mousedown', function( e ) { e.preventDefault() } );
Expand Down Expand Up @@ -191,21 +190,6 @@ function( Utils, UploadModel, UploadRow, UploadFtp, Popover, Select, Ui, LIST_CO
// events triggered by this view
//

/** [public] display extension info popup */
showExtensionInfo: function( options ) {
var self = this;
var $el = options.$el;
var extension = options.extension;
var title = options.title;
var description = _.findWhere( self.list_extensions, { 'id': extension } );
this.extension_popup && this.extension_popup.remove();
this.extension_popup = new Popover.View({ placement: options.placement || 'bottom', container: $el } );
this.extension_popup.title( title );
this.extension_popup.empty();
this.extension_popup.append( this._templateDescription( description ) );
this.extension_popup.show();
},

/** Show/hide ftp popup */
_eventFtp: function() {
if ( !this.ftp.visible ) {
Expand All @@ -215,7 +199,7 @@ function( Utils, UploadModel, UploadRow, UploadFtp, Popover, Select, Ui, LIST_CO
collection : this.collection,
ftp_upload_site : this.ftp_upload_site,
onadd : function( ftp_file ) {
self.uploadbox.add([{
return self.uploadbox.add([{
mode: 'ftp',
name: ftp_file.path,
size: ftp_file.size,
Expand Down Expand Up @@ -347,19 +331,6 @@ function( Utils, UploadModel, UploadRow, UploadFtp, Popover, Select, Ui, LIST_CO
return ( this.upload_completed + ( percentage * size ) ) / this.upload_size;
},

/** Template for extensions description */
_templateDescription: function( options ) {
if ( options.description ) {
var tmpl = options.description;
if ( options.description_url ) {
tmpl += '&nbsp;(<a href="' + options.description_url + '" target="_blank">read more</a>)';
}
return tmpl;
} else {
return 'There is no description available for this file extension.';
}
},

/** Template */
_template: function() {
return '<div class="upload-view-default">' +
Expand Down
54 changes: 13 additions & 41 deletions client/galaxy/scripts/mvc/upload/composite/composite-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Renders contents of the composite uploader */
define([ 'utils/utils', 'mvc/upload/upload-model', 'mvc/upload/composite/composite-row', 'mvc/ui/ui-popover', 'mvc/ui/ui-select', 'mvc/ui/ui-misc'],
function( Utils, UploadModel, UploadRow, Popover, Select, Ui ) {
define([ 'utils/utils', 'mvc/upload/upload-model', 'mvc/upload/composite/composite-row', 'mvc/upload/upload-extension', 'mvc/ui/ui-popover', 'mvc/ui/ui-select', 'mvc/ui/ui-misc'],
function( Utils, UploadModel, UploadRow, UploadExtension, Popover, Select, Ui ) {
return Backbone.View.extend({
collection: new UploadModel.Collection(),
initialize: function(app) {
Expand Down Expand Up @@ -40,10 +40,11 @@ function( Utils, UploadModel, UploadRow, Popover, Select, Ui ) {

// handle extension info popover
this.$( '.upload-footer-extension-info' ).on( 'click', function( e ) {
self._showExtensionInfo({
new UploadExtension({
$el : $( e.target ),
title : self.select_extension.text(),
extension : self.select_extension.value(),
list : self.list_extensions,
placement : 'top'
});
}).on( 'mousedown', function( e ) { e.preventDefault() } );
Expand Down Expand Up @@ -126,47 +127,11 @@ function( Utils, UploadModel, UploadRow, Popover, Select, Ui ) {
this.collection.each( function( it ) { it.set( { 'status': 'error', 'info': message } ) } );
},

/** Display extension info popup */
_showExtensionInfo: function(options) {
var self = this;
var $el = options.$el;
var extension = options.extension;
var title = options.title;
var description = _.findWhere(this.list_extensions, { id : extension });
this.extension_popup && this.extension_popup.remove();
this.extension_popup = new Popover.View({
placement: options.placement || 'bottom',
container: $el,
destroy: true
});
this.extension_popup.title( title );
this.extension_popup.empty();
this.extension_popup.append( this._templateDescription( description ) );
this.extension_popup.show();
},

/* Template for extensions description */
_templateDescription: function( options ) {
if ( options.description ) {
var tmpl = options.description;
if ( options.description_url ) {
tmpl += '&nbsp;(<a href="' + options.description_url + '" target="_blank">read more</a>)';
}
return tmpl;
} else {
return 'There is no description available for this file extension.';
}
},

/** Load html template */
_template: function() {
return '<div class="upload-view-composite">' +
'<div class="upload-footer">' +
'<span class="upload-footer-title">Composite Type:</span>' +
'<span class="upload-footer-extension"/>' +
'<span class="upload-footer-extension-info upload-icon-button fa fa-search"/> ' +
'<span class="upload-footer-title">Genome/Build:</span>' +
'<span class="upload-footer-genome"/>' +
'<div class="upload-top">' +
'<h6 class="upload-top-info"/>' +
'</div>' +
'<div class="upload-box">' +
'<table class="upload-table ui-table-striped" style="display: none;">' +
Expand All @@ -184,6 +149,13 @@ function( Utils, UploadModel, UploadRow, Popover, Select, Ui ) {
'<tbody/>' +
'</table>' +
'</div>' +
'<div class="upload-footer">' +
'<span class="upload-footer-title">Composite Type:</span>' +
'<span class="upload-footer-extension"/>' +
'<span class="upload-footer-extension-info upload-icon-button fa fa-search"/> ' +
'<span class="upload-footer-title">Genome/Build:</span>' +
'<span class="upload-footer-genome"/>' +
'</div>' +
'<div class="upload-buttons"/>' +
'</div>';
}
Expand Down
27 changes: 18 additions & 9 deletions client/galaxy/scripts/mvc/upload/default/default-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,27 @@ function( Utils, UploadModel, UploadSettings, Popover, Select ) {
this.listenTo( this.model, 'change:genome', function() { self._refreshGenome() } );
this.listenTo( this.model, 'change:extension', function() { self._refreshExtension() } );
this.listenTo( this.model, 'change:file_size', function() { self._refreshFileSize() } );
this.listenTo( this.model, 'remove', function() { self.remove() } );
this.app.collection.on('reset', function() { self.remove() } );
},

render: function() {
this._refreshType();
this._refreshPercentage();
this._refreshStatus();
this._refreshInfo()
this._refreshGenome();
this._refreshExtension();
this._refreshFileSize()
},

/** Remove view */
remove: function() {
this.select_genome.remove();
this.select_extension.remove();
Backbone.View.prototype.remove.apply( this );
},

/** Render type */
_refreshType: function() {
var options = this.model.attributes;
this.$title.html( _.escape( options.file_name ) );
this.$size.html( Utils.bytesToString ( options.file_size ) );
Expand All @@ -109,13 +125,6 @@ function( Utils, UploadModel, UploadSettings, Popover, Select ) {
}
},

/** Remove view */
remove: function() {
this.select_genome.remove();
this.select_extension.remove();
Backbone.View.prototype.remove.apply( this );
},

/** Update extension */
_refreshExtension: function() {
this.select_extension.value( this.model.get( 'extension' ) );
Expand Down
Loading

0 comments on commit e03bedf

Please sign in to comment.