Connect upload front end to upload tool via tools api

This commit is contained in:
Aysam Guerler
2013-10-10 14:41:47 -04:00
parent 7de5488c4e
commit efc2365e8c
3 changed files with 30 additions and 80 deletions
@@ -214,69 +214,6 @@ class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociatio
trans.sa_session.flush()
return hda.to_dict()
# copy from upload
if source == 'upload':
# get upload specific features
dbkey = payload.get('dbkey', None)
extension = payload.get('extension', None)
space_to_tabs = payload.get('space_to_tabs', False)
# check for filename
if content.filename is None:
trans.response.status = 400
return "history_contents:create() : The contents parameter needs to contain the uploaded file content."
# create a dataset
dataset = trans.app.model.Dataset()
trans.sa_session.add(dataset)
trans.sa_session.flush()
# get file destination
file_destination = dataset.get_file_name()
# check if the directory exists
dn = os.path.dirname(file_destination)
if not os.path.exists(dn):
os.makedirs(dn)
# get file and directory names
fn = os.path.basename(content.filename)
# save file locally
open(file_destination, 'wb').write(content.file.read())
# log
log.info ('The file "' + fn + '" was uploaded successfully.')
# replace separation with tabs
if space_to_tabs:
log.info ('Replacing spaces with tabs.')
sniff.convert_newlines_sep2tabs(file_destination)
# guess extension
if extension is None:
log.info ('Guessing extension.')
extension = sniff.guess_ext(file_destination)
# create hda
hda = trans.app.model.HistoryDatasetAssociation(dataset = dataset, name = content.filename,
extension = extension, dbkey = dbkey, history = history, sa_session = trans.sa_session)
# add status ok
hda.state = hda.states.OK
# add dataset to history
history.add_dataset(hda, genome_build = dbkey)
permissions = trans.app.security_agent.history_get_default_permissions( history )
trans.app.security_agent.set_all_dataset_permissions( hda.dataset, permissions )
# add to session
trans.sa_session.add(hda)
trans.sa_session.flush()
# get name
return hda.to_dict()
else:
# other options
trans.response.status = 501
+6 -4
View File
@@ -38,10 +38,12 @@ var GalaxyModal = Backbone.View.extend(
this.$body.css('max-height', maxHeight);
// fix height if available
if (this.options.height < maxHeight)
this.$body.css('height', this.options.height);
else
this.$body.css('height', maxHeight);
if (this.options.height) {
if (this.options.height < maxHeight)
this.$body.css('height', this.options.height);
else
this.$body.css('height', maxHeight);
}
// remove scroll bar
if (this.options.height)
+24 -13
View File
@@ -19,9 +19,7 @@ var GalaxyUpload = Backbone.View.extend(
// extension types
select_extension : {
'auto' : 'Auto-detect',
'bed' : 'bed',
'ab1' : 'ab1'
'auto' : 'Auto-detect'
},
// states
@@ -134,18 +132,31 @@ var GalaxyUpload = Backbone.View.extend(
// get element
var it = this.get_upload_item(index);
// read in configuration
var data = {
source : "upload",
space_to_tabs : it.find('#space_to_tabs').is(':checked'),
extension : it.find('#extension').val()
}
// configure url
// get current history
var current_history = Galaxy.currHistoryPanel.model.get('id');
this.uploadbox.configure({url : galaxy_config.root + "api/histories/" + current_history + "/contents"});
// configure tool
this.uploadbox.configure({url : galaxy_config.root + "api/tools/", paramname : "files_0|file_data"});
// get
var file_type = it.find('#extension').val();
var space_to_tabs = it.find('#space_to_tabs').is(':checked');
// configure tool
tool_input = {};
tool_input['dbkey'] = '?';
tool_input['file_type'] = file_type;
tool_input['files_0|NAME'] = file.name;
tool_input['files_0|type'] = 'upload_dataset';
tool_input['space_to_tabs'] = space_to_tabs;
// setup data
data = {};
data['history_id'] = current_history;
data['tool_id'] = 'upload1';
data['inputs'] = JSON.stringify(tool_input);
// return additional data to be send with file
return data;
},