Skip to content

Commit

Permalink
[RazortoothRTC#39] Yaaaay, retake operational on web client ! I also …
Browse files Browse the repository at this point in the history
…reduced decimal size to 1 number for results in student table
  • Loading branch information
chrqls committed Jun 14, 2014
1 parent 796f31d commit b0e9806
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
28 changes: 27 additions & 1 deletion lib/smile/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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-');
Expand All @@ -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
**/
Expand Down
5 changes: 5 additions & 0 deletions smileplug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': <Reason> }
Expand Down
6 changes: 3 additions & 3 deletions static/js/smilestudent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -354,8 +354,8 @@ GlobalViewModel.doAnswerNextQ = function() {
// Submit All Questions
//
$('div#answer-form-area').block({
message: '<h1>Done. Please wait for the rest of the students to finish Answering Questions</h1>',
css: { border: '3px solid #a00', width: '80%'
message: '<h4>Done. Please wait for the rest of the students to finish Answering Questions</h4>',
css: { border: '3px solid #a00', width: '70%'
}
});

Expand Down
38 changes: 29 additions & 9 deletions static/js/smileteacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
Expand Down Expand Up @@ -396,7 +397,8 @@ GlobalViewModel.seeResults = function() {

GlobalViewModel.retake = function() {

// postMessage('seeresults');
var status = smile_retake();
console.log('status='+status);
this.redirectView();
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {}
});
Expand All @@ -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;
Expand All @@ -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; }
});
Expand Down
1 change: 0 additions & 1 deletion static/smile-teacher.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@
<div data-bind="if: message_for_student" class="small-2 columns">
<a href="#" class="button prefix" data-bind='click: talkToStudent'>Send</a>
</div>

</div>
</div>
</div>
Expand Down

0 comments on commit b0e9806

Please sign in to comment.