Commit 60c67280 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

upload close to be ok, progress in progress

parent 9d921032
......@@ -208,11 +208,29 @@ class JFlowServer (object):
workflow = self.wfmanager.get_workflow(kwargs["workflow_id"])
return self.jsonify_workflow_status(workflow)
@cherrypy.expose
def upload(self, **kwargs):
print kwargs
file_param = kwargs.keys()[0]
# the file transfer can take a long time; by default cherrypy
# limits responses to 300s; we increase it to 1h
cherrypy.response.timeout = 3600
# upload file by chunks
FH_sever_file = open("/tmp/" + kwargs[file_param].filename, "w") ##################tmp folder a recup
size = 0
while True:
data = kwargs[file_param].file.read(8192)
if not data:
break
size += len(data)
FH_sever_file.write(data)
FH_sever_file.close()
return "ok"
@cherrypy.expose
@cherrypy.tools.noBodyProcess()
@cherrypy.tools.CORS()
def upload(self, **kwargs):
def upload2(self, **kwargs):
file = kwargs.keys()[0]
# the file transfer can take a long time; by default cherrypy
......
......@@ -138,7 +138,8 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
!function ($) {
"use strict"; // jshint ;_;
var TIMER = 2000,
timer;
/* WFForm CLASS DEFINITION
* ========================= */
......@@ -159,6 +160,30 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
}
}
var _uploadProgress = function(template) {
var allUploaded = true,
upload_file_status = new Array();
$(".fileupload").each(function(){
var tloaded = $(this).fileupload('progress').loaded,
t2load = $(this).fileupload('progress').total,
tid = $(this).attr("id").split("_"),
iid = tid.slice(1, tid.length).join("_");
if (tloaded != t2load) {
allUploaded = false
}
if (t2load != 0) {
upload_file_status.push({param: tid.join("_"), name: $("#"+iid).val(), loaded: tloaded, total: t2load});
}
if (allUploaded) {
clearInterval(timer);
}
});
$("#workflow_form").hide();
$("#progress").html("");
$.tmpl(template, {upload_file_status: upload_file_status}).appendTo($("#progress"));
}
WFForm.prototype.run = function() {
// first check if the form is valid
if ($("#workflow_form").valid()) {
......@@ -178,13 +203,11 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
$this.$element.trigger('upload.files');
/*$.ajax({
url: this.options.serverURL + '/run_workflow?' + params + 'callback=?',
dataType: "json",
success: function(running_wf) {
$this.$element.trigger('run', running_wf);
}
});*/
// execute _uploadProgress to init the display
_uploadProgress($this.options.progressTemplate)
// then loop to follow the file upload
timer = setInterval(function() { _uploadProgress($this.options.progressTemplate) }, TIMER);
}
}
......@@ -484,7 +507,25 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
' {{/if}}',
' {{/each}}',
' {{/each}}',
'</form>'].join('\n'),
'</form>',
'<div id="progress"></div>'].join('\n'),
progressTemplate: ['<dl class="dl-horizontal">',
'<dt>Start</dt>',
'<dd>sss</dd>',
'<dt>End</dt>',
'<dd>ddd</dd>',
'<dt>Elapsed time</dt>',
'<dd>dfdf</dd>',
'<br/>',
'{{each(index, file) upload_file_status}}',
'<dt>${file.name}</dt>',
'<dd>',
'<div class="progress">',
'<div class="bar bar-success" style="width: ${parseInt((file.loaded/file.total)*100)}%;"></div>',
'</div>',
'</dd>',
'{{/each}}',
'</dl>'].join('\n'),
workflowClass: null,
displayRunButton: true,
displayResetButton: true,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment