Changeset 20597
- Timestamp:
- 05/09/16 21:26:22 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/clusters/generic.js
r20588 r20597 47 47 this.UploadAndRun = function (md,callbackfunction,fid,toolkitsstring,solutionstring,name,runtimename) { //{{{ 48 48 49 var oReq = new XMLHttpRequest(); 50 oReq.open("POST", this.url, true); 51 oReq.responseType = 'application/octet-stream'; 52 oReq.position = 0 53 54 //TODO: dynamic progress update with package lengths and parsing 55 oReq.onprogress = function (oEvent) { 56 var newResponse = oReq.responseText; 57 if (newResponse.length == 13) { //"Starting" length as encoded in base64 length 58 $(".run-button").html("COMPUTING...").prop("disabled", true); 59 console.log("base64 repsonse: " + newResponse + " string response: " + window.atob(oReq.responseText)); 49 var request = new XMLHttpRequest(); 50 $(".run-button").html("CONNECTING...").prop("disabled", true); 51 request.position = 0; //Keep track of current parsing position in repsonseText 52 //TODO: Test timeout conditions (timeout will trigger even if ocnnection is successful, if computation takes too long) 53 request.timeout = 3000; 54 request.ontimeout = function (event) { 55 $(".run-button").html("RUN").prop("disabled", false); 56 } 57 58 request.upload.onprogress = function(event) { 59 var progress = (event.loaded / event.total * 100).toFixed(0); 60 $(".run-button").html("UPLOADING: " + progress + "%"); 61 } 62 63 request.onprogress = function (event) { 64 //Receive updates by parsing message length as a 32-bit hex string of form 0x*09ABCDEF)) 65 var startIndex = request.position; 66 var endIndex = request.position + 10; 67 if (request.responseText.length >= endIndex) { //Ensure entire hex string is loaded 68 var chunkSize = parseInt(request.responseText.slice(startIndex, endIndex)); 69 startIndex = endIndex; 70 endIndex = startIndex + chunkSize; 71 if (chunkSize >= 65535) { //Arbitrary maximium size of message (Must be below minimium size of model results) 72 $(".run-button").html("DOWNLOADING: " + ((request.responseText.length - request.position) / chunkSize * 100).toFixed(0) + "%").prop("disabled", true); 73 } 74 else if (request.responseText.length >= endIndex) { //Ensure entire chunk is loaded 75 var responseChunk = request.responseText.slice(startIndex, endIndex); 76 $(".run-button").html(responseChunk); 77 request.position = endIndex; 78 } 60 79 } 61 80 }; 62 81 63 oReq.onload = function (oEvent) {82 request.onload = function (event) { 64 83 //get context to this.str2ab to avoid duplciation 65 84 function str2ab(str) { … … 70 89 return buf; 71 90 } //}}} 72 var buffer2 = str2ab(window.atob(oReq.responseText.slice(13))); 91 //if (request.responseText.slice(request.position, request.position + 1) == "0x") request.position = request.position + 10; 92 var buffer2 = str2ab(window.atob(request.responseText.slice(request.position + 10))); 73 93 var returnBuffer = new Uint8Array(buffer2); 74 94 var returnBuffer_size=returnBuffer.byteLength; … … 79 99 console.log(e); 80 100 } 101 $(".run-button").html("RUN").prop("disabled", false); 81 102 callbackfunction(); 82 103 }; … … 102 123 solutionlength[0] = solutionbuffer.byteLength; 103 124 104 var binbuffer = new Uint8Array(fid.rawbuffer()); 105 //var binbuffer = new Uint16Array(fid.rawbuffer()); seems that 16 array bytes length could be incompatible. 125 var binbuffer = new Uint8Array(fid.rawbuffer()); //seems that 16 array bytes length could be incompatible. 106 126 107 127 … … 111 131 var data = new Blob([nplength,npbuffer,runtimenamelength,runtimenamebuffer,namelength,namebuffer,toolkitslength,toolkitsbuffer,solutionlength,solutionbuffer,binlength,binbuffer]); 112 132 //if (typeof(download) != "undefined") download(fid.rawbuffer()); 113 oReq.send(data); 133 134 request.open("POST", this.url, true); 135 request.responseType = 'application/octet-stream'; 136 request.send(data); 114 137 115 138 return;
Note:
See TracChangeset
for help on using the changeset viewer.