Skip to content

Commit

Permalink
Enable composite data submission
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 5, 2015
1 parent d85342d commit 8e09384
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 79 deletions.
Expand Up @@ -48,6 +48,7 @@ return Backbone.View.extend({
},
onchange: function(files) {
if (files && files.length > 0) {
self.model.set('file_data', files[0]);
self.model.set('file_name', files[0].name);
self.model.set('file_size', files[0].size);
self.model.set('file_mode', files[0].mode || 'local');
Expand Down
13 changes: 12 additions & 1 deletion client/galaxy/scripts/mvc/upload/composite/composite-view.js
Expand Up @@ -126,7 +126,18 @@ return Backbone.View.extend({

// start upload process
_eventStart : function() {
$.uploadpost();
var self = this;
this.collection.each(function(item) {
item.set('genome', self.select_genome.value());
item.set('extension', self.select_extension.value());
});
$.uploadpost({
url : this.app.options.nginx_upload_path,
data : this.app.toData(this.collection.filter()),
success : function(message) { console.log(message); },
error : function(message) { console.log(message); },
progress : function(percentage) { console.log(percentage); }
});
},

// progress
Expand Down
58 changes: 3 additions & 55 deletions client/galaxy/scripts/mvc/upload/default/default-view.js
Expand Up @@ -85,7 +85,7 @@ return Backbone.View.extend({
this.uploadbox = this.$('#upload-box').uploadbox({
url : this.app.options.nginx_upload_path,
announce : function(d) { self._eventAnnounce(d) },
initialize : function(d) { return self._eventInitialize(d) },
initialize : function(d) { return self.app.toData([ self.collection.get(d.index) ]) },
progress : function(d, percentage) { self._eventProgress(d, percentage) },
success : function(d, message) { self._eventSuccess(d, message) },
error : function(d, message) { self._eventError(d, message) },
Expand Down Expand Up @@ -184,7 +184,8 @@ return Backbone.View.extend({
file_name : d.file.name,
file_size : d.file.size,
file_mode : d.file.mode || 'local',
file_path : d.file.path
file_path : d.file.path,
file_data : d.file
});

// add to collection
Expand All @@ -197,59 +198,6 @@ return Backbone.View.extend({
upload_item.render();
},

// the uploadbox plugin is initializing the upload for this file
_eventInitialize: function(d) {
// get element
var it = this.collection.get(d.index);

// update status
it.set('status', 'running');

// get configuration
var file_name = it.get('file_name');
var file_path = it.get('file_path');
var file_mode = it.get('file_mode');
var extension = it.get('extension');
var genome = it.get('genome');
var url_paste = it.get('url_paste');
var space_to_tab = it.get('space_to_tab');
var to_posix_lines = it.get('to_posix_lines');

// validate
if (!url_paste && !(d.file.size > 0)) {
return { error: 'No upload content available.' };
}

// configure tool input
inputs = {};
inputs['dbkey'] = genome;
inputs['file_type'] = extension;
inputs['files_0|type'] = 'upload_dataset';
inputs['files_0|space_to_tab'] = space_to_tab && 'Yes' || null;
inputs['files_0|to_posix_lines'] = to_posix_lines && 'Yes' || null;

// modes without upload data
if (file_mode == 'new') {
inputs['files_0|url_paste'] = url_paste;
}
if (file_mode == 'ftp') {
inputs['files_0|ftp_files'] = file_path;
}

// setup/return submission data
var data = {
payload: {
'tool_id' : 'upload1',
'history_id' : this.app.current_history,
'inputs' : JSON.stringify(inputs),
}
}
if (file_mode == 'local') {
data['files'] = [{ name: 'files_0|file_data', file: d.file }];
}
return data;
},

// progress
_eventProgress: function(d, percentage) {
// set progress for row
Expand Down
48 changes: 48 additions & 0 deletions client/galaxy/scripts/mvc/upload/upload-view.js
Expand Up @@ -176,6 +176,54 @@ return Backbone.View.extend({
if (this.current_user) {
this.current_history = Galaxy.currHistoryPanel.model.get('id');
}
},

// package upload items
toData: function(items) {
// create dictionary for data submission
var data = {
payload: {
'tool_id' : 'upload1',
'history_id' : this.current_history,
'inputs' : {}
},
files: [],
error_message: null
}
// add upload tools input data
if (items && items.length > 0) {
var inputs = {};
console.log(items);
inputs['dbkey'] = items[0].get('genome', null);
inputs['file_type'] = items[0].get('extension', null);
for (var index in items) {
var it = items[index];
it.set('status', 'running');
if (it.get('file_size') > 0) {
var prefix = 'files_' + index + '|';
inputs[prefix + 'type'] = 'upload_dataset';
inputs[prefix + 'space_to_tab'] = it.get('space_to_tab') && 'Yes' || null;
inputs[prefix + 'to_posix_lines'] = it.get('to_posix_lines') && 'Yes' || null;
switch (it.get('file_mode')) {
case 'new':
inputs[prefix + 'url_paste'] = it.get('url_paste');
break;
case 'ftp':
inputs[prefix + 'ftp_files'] = it.get('file_path');
break;
case 'local':
data.files.push({ name: prefix + 'file_data', file: it.get('file_data') });
}
} else {
data.error_message = 'Upload content incomplete.';
it.set('status', 'error');
it.set('status_text', data.error_message);
break;
}
}
data.payload.inputs = JSON.stringify(inputs);
}
return data;
}
});

Expand Down
28 changes: 15 additions & 13 deletions client/galaxy/scripts/utils/uploadbox.js
Expand Up @@ -26,6 +26,12 @@
// link data
var data = cnf.data;

// check errors
if (data.error_message) {
cnf.error(data.error_message);
return;
}

// construct form data
var form = new FormData();
for (var key in data.payload) {
Expand Down Expand Up @@ -91,6 +97,8 @@
}, false);

// send request
console.debug('uploadbox::uploadpost() - Posting following data:');
console.debug(cnf);
xhr.send(form);
}

Expand Down Expand Up @@ -223,19 +231,13 @@

// create and submit data
var callback_data = { index: index, file: file };
var data = opts.initialize(callback_data);
if (!data.error) {
$.uploadpost({
url : opts.url,
data : data,
success : function(message) { opts.success(callback_data, message); process();},
error : function(message) { opts.error(callback_data, message); process();},
progress : function(percentage) { opts.progress(callback_data, percentage); }
});
} else {
opts.error(callback_data, data.error);
process();
}
$.uploadpost({
url : opts.url,
data : opts.initialize(callback_data),
success : function(message) { opts.success(callback_data, message); process();},
error : function(message) { opts.error(callback_data, message); process();},
progress : function(percentage) { opts.progress(callback_data, percentage); }
});
}

/*
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/upload/composite/composite-row.js.map

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

0 comments on commit 8e09384

Please sign in to comment.