From b0e9806238a347acc1472e987fd17542febb755d Mon Sep 17 00:00:00 2001 From: chrqls Date: Sat, 14 Jun 2014 16:08:37 +0200 Subject: [PATCH] [#39] Yaaaay, retake operational on web client ! I also reduced decimal size to 1 number for results in student table --- lib/smile/game.js | 28 +++++++++++++++++++++++++++- routes/index.js | 11 ++++++++++- smileplug.js | 5 +++++ static/js/smilestudent.js | 6 +++--- static/js/smileteacher.js | 38 +++++++++++++++++++++++++++++--------- static/smile-teacher.html | 1 - 6 files changed, 74 insertions(+), 15 deletions(-) diff --git a/lib/smile/game.js b/lib/smile/game.js index b19fa7f..7034d51 100644 --- a/lib/smile/game.js +++ b/lib/smile/game.js @@ -41,7 +41,7 @@ Game.prototype.setRatingMetadata = function setRatingMetadata(metadata) { } }; -Game.prototype.retake = function retake() { +Game.prototype.retake_dirty = function retake_dirty() { this.questionRatings = {}; this.questionCorrectCountMap = {}; @@ -77,6 +77,32 @@ Game.prototype.retake = function retake() { this.questions = new Questions(); }; +/* + When retaking, there is 2 things to manage: + - the past messages to clean + - the variables used for the current session +*/ +Game.prototype.retake = function retake() { + + this.questionRatings = {}; + this.questionCorrectCountMap = {}; + for (var key in this.students.currentStudents) { + this.students.currentStudents[key].retake(); + } + + var msgs = this.messages.past; + + for (var i=msgs.length-1; i>=0; i--) { + + if (msgs[i].TYPE === 'QUESTION' || msgs[i].TYPE === 'QUESTION_PIC' || + msgs[i].TYPE === 'START_MAKE' || msgs[i].TYPE === 'START_SOLVE' || + msgs[i].TYPE === 'START_SHOW' || msgs[i].TYPE === 'ANSWER') { + this.messages.past.splice(i, 1); + } + } + this.questions = new Questions(); +}; + Game.prototype.setCurrentMessage = function setCurrentMessage(message) { this.messages.current = message; this.registerMessage(message); diff --git a/routes/index.js b/routes/index.js index 298de21..01ee9f9 100644 --- a/routes/index.js +++ b/routes/index.js @@ -569,6 +569,7 @@ exports.handlePushMessage = function(req, res) { var type = null; var error = null; + // Android retake (old way to retake) if(JSON.stringify(message).indexOf("TYPE:'RE_TAKE'") != -1) { type = 'RE_TAKE'; game.registerMessage(MESSAGE_RETAKE); @@ -598,8 +599,9 @@ exports.handlePushMessage = function(req, res) { error = game.studentsWrapper.addStudent(message); break; case 'RE_TAKE': + // Android retaking (old way) console.log('Retaking...'); - error = game.retake(); + game.retake(); break; case 'RESET': console.log('-Reset session-'); @@ -622,6 +624,13 @@ exports.handlePushMessage = function(req, res) { } }; +exports.retakeSession = function(req, res) { + + game.retake(); + return res.sendText(HTTP_STATUS_OK, OK); +} + + /** Creating a session with teacher name, session title, and group name **/ diff --git a/smileplug.js b/smileplug.js index 4df73fc..219dd61 100644 --- a/smileplug.js +++ b/smileplug.js @@ -198,6 +198,11 @@ js.post('/smile/talk/student/post', routes.addPrivateMessageForTeacher);*/ js.put('/smile/iqset', routes.handlePostNewIQSet); js.post('/smile/iqset', routes.handlePostNewIQSet); +/** + Retake +**/ +js.get('/smile/retake', routes.retakeSession); + /** Delete the IQSet based on an existing :id. If :id does not exist return { 'error': } diff --git a/static/js/smilestudent.js b/static/js/smilestudent.js index 6c43247..c63c9f4 100644 --- a/static/js/smilestudent.js +++ b/static/js/smilestudent.js @@ -28,7 +28,7 @@ #SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **/ -var VERSION = '1.1.0'; +var VERSION = '1.1.1'; var DELAY_UPDATE_BOARD = 1500; var DELAY_PRIVATE_MESSAGE = 5000; @@ -354,8 +354,8 @@ GlobalViewModel.doAnswerNextQ = function() { // Submit All Questions // $('div#answer-form-area').block({ - message: '

Done. Please wait for the rest of the students to finish Answering Questions

', - css: { border: '3px solid #a00', width: '80%' + message: '

Done. Please wait for the rest of the students to finish Answering Questions

', + css: { border: '3px solid #a00', width: '70%' } }); diff --git a/static/js/smileteacher.js b/static/js/smileteacher.js index b620586..fc3c5d3 100644 --- a/static/js/smileteacher.js +++ b/static/js/smileteacher.js @@ -28,13 +28,13 @@ #SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **/ -var VERSION = '0.8.4'; +var VERSION = '0.8.6'; // Interval of time used to update the GlobalViewModel var DELAY_UPDATE_BOARD = 5000; var DELAY_ERROR = 60000; -var DELAY_SHORT = 5000; -var DELAY_NORMAL = 10000;/* +var DELAY_SHORT = 9000; +var DELAY_NORMAL = 18000;/* var DELAY_LONG = 20000;*/ var SMILEROUTES = { @@ -48,7 +48,8 @@ var SMILEROUTES = { 'startsolve': '/smile/startsolvequestion', 'seeresults': '/smile/sendshowresults', 'deletequestion': '/smile/questionview/', - 'talk': '/smile/talk/teacher/post' + 'talk': '/smile/talk/teacher/post', + 'retake': '/smile/retake' }; var DEAMON_UPDATING_BOARD; @@ -396,7 +397,8 @@ GlobalViewModel.seeResults = function() { GlobalViewModel.retake = function() { - // postMessage('seeresults'); + var status = smile_retake(); + console.log('status='+status); this.redirectView(); } @@ -838,7 +840,7 @@ function calculateAndShowResults(dataAll) { points++; } } - score.SCORE = 100*points/size_Q; + score.SCORE = Math.round((100*points/size_Q) * 10 ) / 10; if(score.SCORE > best_score) best_score = score.SCORE; scores.push(score); } @@ -1078,7 +1080,25 @@ function smile_reset() { async: false, error: function(xhr, text, err) { - absoluteAlert('Unable to reset. Reason: ' + xhr.status + ':' + xhr.responseText, DELAY_ERROR, 'trace'); + absoluteAlert('Unable to reset. Reason: ' + xhr.status + ':' + xhr.responseText, DELAY_ERROR, 'trace',true); + }, + success: function(data) {} + }); +} + +function smile_retake() { + + $.ajax({ + cache: false, + type: 'GET', + dataType: 'text', + //contentType: "application/json", + url: SMILEROUTES['retake'], + data: {}, + async: false, + + error: function(xhr, text, err) { + absoluteAlert('Unable to retake. Reason: ' + xhr.status + ':' + xhr.responseText, DELAY_ERROR, 'trace',true); }, success: function(data) {} }); @@ -1097,7 +1117,7 @@ function smile_iqsets() { data: {}, error: function(xhr, text, err) { - absoluteAlert('Unable to call /smile/iqsets. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', DELAY_ERROR, 'trace'); + absoluteAlert('Unable to call /smile/iqsets. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', DELAY_ERROR, 'trace',true); }, success: function(data) { iqsets = data; @@ -1118,7 +1138,7 @@ function smile_iqset(id) { async: false, data: {}, error: function(xhr, text, err) { - absoluteAlert('Unable to call /smile/iqset/{key}', DELAY_NORMAL, 'trace'); + absoluteAlert('Unable to call /smile/iqset/{key}', DELAY_ERROR, 'trace',true); }, success: function(data) { iqset = data; } }); diff --git a/static/smile-teacher.html b/static/smile-teacher.html index 83534ac..b509897 100644 --- a/static/smile-teacher.html +++ b/static/smile-teacher.html @@ -330,7 +330,6 @@ -