Mercurial > hg > webaudioevaluationtool
changeset 2722:a087cb7b5972
#186. Interim saves now use the prefix. Re-writting completion save to use correct stores
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Sat, 15 Apr 2017 11:10:38 +0100 |
parents | a6a0d2b786af |
children | 2e1cafe93c78 |
files | js/core.js python/pythonServer.py |
diffstat | 2 files changed, 46 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/js/core.js Fri Apr 14 16:28:19 2017 +0100 +++ b/js/core.js Sat Apr 15 11:10:38 2017 +0100 @@ -175,7 +175,7 @@ gReturnURL = value; break; case "saveFilenamePrefix": - gSaveFilenamePrefix = value; + storage.filenamePrefix = value; break; } } @@ -1213,7 +1213,7 @@ function stateMachine() { // Object prototype for tracking and managing the test state - + function pickSubPool(pool, numElements) { // Assumes each element of pool has function "alwaysInclude" @@ -1227,7 +1227,7 @@ return picked.concat(randomSubArray(pool, numElements - picked.length)); } - + this.stateMap = []; this.preTestSurvey = null; this.postTestSurvey = null; @@ -1239,7 +1239,7 @@ // Get the data from Specification var pagePool = []; - specification.pages.forEach(function(page){ + specification.pages.forEach(function (page) { if (page.position !== null || page.alwaysInclude) { page.alwaysInclude = true; } @@ -1252,7 +1252,7 @@ // Now get the order of pages var fixed = []; - pagePool.forEach(function(page){ + pagePool.forEach(function (page) { if (page.position !== null) { fixed.push(page); var i = pagePool.indexOf(page); @@ -1265,7 +1265,7 @@ } // Place in the correct order - fixed.forEach(function(page) { + fixed.forEach(function (page) { pagePool.splice(page.position, 0, page); }); @@ -2585,19 +2585,19 @@ for (var i = 0; i < optCount; i++) { var div = document.createElement('div'); div.className = "comment-checkbox-inputs-flex"; - + var span = document.createElement('span'); span.textContent = commentQuestion.options[i].text; span.className = 'comment-radio-span'; div.appendChild(span); - + var input = document.createElement('input'); input.type = 'radio'; input.name = commentQuestion.id; input.setAttribute('setvalue', commentQuestion.options[i].name); input.className = 'comment-radio'; div.appendChild(input); - + this.inputs.appendChild(div); this.options.push(input); } @@ -2660,19 +2660,19 @@ for (var i = 0; i < optCount; i++) { var div = document.createElement('div'); div.className = "comment-checkbox-inputs-flex"; - + var span = document.createElement('span'); span.textContent = commentQuestion.options[i].text; span.className = 'comment-radio-span'; div.appendChild(span); - + var input = document.createElement('input'); input.type = 'checkbox'; input.name = commentQuestion.id; input.setAttribute('setvalue', commentQuestion.options[i].name); input.className = 'comment-radio'; div.appendChild(input); - + this.inputs.appendChild(div); this.options.push(input); } @@ -2840,7 +2840,7 @@ }; this.playhead = (function () { - var playhead ={}; + var playhead = {}; playhead.object = document.createElement('div'); playhead.object.className = 'playhead'; playhead.object.align = 'left'; @@ -3402,6 +3402,7 @@ this.document = null; this.root = null; this.state = 0; + var pFilenamePrefix = ""; this.initialise = function (existingStore) { if (existingStore === undefined) { @@ -3480,7 +3481,7 @@ returnURL = specification.projectReturn; } } - xmlhttp.open("POST", returnURL + "php/save.php?key=" + this.key); + xmlhttp.open("POST", returnURL + "php/save.php?key=" + this.key + "&saveFilenamePrefix=" + this.parent.filenamePrefix); xmlhttp.setRequestHeader('Content-Type', 'text/xml'); xmlhttp.onerror = function () { console.log('Error updating file to server!'); @@ -3650,6 +3651,21 @@ this.root.setAttribute("state", "complete"); return this.root; }; + + Object.defineProperties(this, { + 'filenamePrefix': { + 'get': function () { + return pFilenamePrefix; + }, + 'set': function (value) { + if (typeof value !== "string") { + value = String(value); + } + pFilenamePrefix = value; + return value; + } + } + }) } var window_depedancy_callback;
--- a/python/pythonServer.py Fri Apr 14 16:28:19 2017 +0100 +++ b/python/pythonServer.py Sat Apr 15 11:10:38 2017 +0100 @@ -137,16 +137,27 @@ global curFileName global curSaveIndex options = self.path.rsplit('?') - options = options[1].rsplit('=') - key = options[1] + options = options[1].rsplit('&') + for option in options: + optionPair = option.rsplit('=') + if optionPair[0] == "key": + key = optionPair[1] + elif optionPair[0] == "saveFilenamePrefix": + prefix = optionPair[1] + if key == None: + self.send_response(404) + return + if prefix == None: + prefix = "save" varLen = int(self.headers['Content-Length']) postVars = self.rfile.read(varLen) print("Saving file key "+key) - file = open('../saves/save-'+key+'.xml','wb') + filename = prefix+'-'+key+'.xml' + file = open('../saves/'+filename,'wb') file.write(postVars) file.close() try: - wbytes = os.path.getsize('../saves/save-'+key+'.xml') + wbytes = os.path.getsize('../saves/'+filename) except OSError: self.send_response(200) self.send_header("Content-type", "text/xml") @@ -155,7 +166,7 @@ self.send_response(200) self.send_header("Content-type", "text/xml") self.end_headers() - reply = '<response state="OK"><message>OK</message><file bytes="'+str(wbytes)+'">"saves/'+curFileName+'"</file></response>' + reply = '<response state="OK"><message>OK</message><file bytes="'+str(wbytes)+'">"saves/'+filename+'"</file></response>' if sys.version_info[0] == 2: self.wfile.write(reply) elif sys.version_info[0] == 3: