Skip to content

Commit

Permalink
Merge pull request #84 from chrqls/dev
Browse files Browse the repository at this point in the history
[#39] Updating web client for teacher (0.8.7)
  • Loading branch information
chrqls committed Jun 14, 2014
2 parents 53db468 + 5e66f6c commit 62411a6
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 32 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
16 changes: 10 additions & 6 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 Expand Up @@ -492,15 +492,19 @@ function absoluteAlert(text, lifetime, alerttype, hasCross) {
var box_red = 'alert';
var box_blue = '';
var box_green = 'success';
var css = '';

if (!alerttype) { alerttype = box_grey; }
else if (alerttype === 'trace') { alerttype = box_red; text += ' : ' + printStackTrace(); }
else if (alerttype === 'red') { alerttype = box_red; }
else if (alerttype === 'blue') { alerttype = box_blue; }
else if (alerttype === 'green') { alerttype = box_green; }
else if (alerttype === 'green') { alerttype = box_green; }
else if (alerttype === 'pink') { css = ';border-color:#c80461;background-color:#fc087a'; }



var html_to_inject = '<div id="%s"> \
<div style="margin:3px 0;opacity:0.8;display: inline-block;padding-right:30px" class="alert-box %s" data-alert=""> \
<div style="margin:3px 0;opacity:0.8;display: inline-block;padding-right:30px'+css+'" class="alert-box %s" data-alert=""> \
<span style="font-weight:normal">%s</span>%s \
</div> \
</div>';
Expand Down Expand Up @@ -1164,7 +1168,7 @@ function getPrivateMessage() {
},
success: function(data) {

if(data) absoluteAlert('<u>Message from teacher</u>:<br><br><b>'+data.TEXT+'</b>',null,'red',true);
if(data) absoluteAlert('<u>Message from teacher</u>:<br><br><b>'+data.TEXT+'</b>',null,'pink',true);
}
});
}
Expand Down
93 changes: 72 additions & 21 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.7';

// 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 @@ -102,10 +103,10 @@ var GlobalViewModel = {
version: ko.observable(VERSION),

// Session values
status: ko.observable(''),
group_name: ko.observable(''),
teacher_name: ko.observable(''),
session_name: ko.observable(''),
group_name: ko.observable(''),
status: ko.observable(''),
new_iqset_name: ko.observable(''),
message_for_student: ko.observable(''),

Expand Down Expand Up @@ -153,9 +154,11 @@ ko.extenders.required = function(target, overrideMessage) {

/* -----------------------------------
ACTIONS
(functions called by the view)
----------------------------------- */

GlobalViewModel.redirectView = function() {
Expand Down Expand Up @@ -396,7 +399,8 @@ GlobalViewModel.seeResults = function() {

GlobalViewModel.retake = function() {

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

Expand Down Expand Up @@ -586,9 +590,13 @@ GlobalViewModel.saveNewIQSet = function() {

/* --------------------------------------------------------
UTILITY
(encapsulation of code used by the actions)
-------------------------------------------------------- */

function absoluteAlert(text, lifetime, alerttype, hasCross) {
Expand Down Expand Up @@ -794,22 +802,27 @@ function updateGVM() {
}

function calculateAndShowResults(dataAll) {

// Getting /smile/all
//var dataAll = JSON.parse(smile_all());

// Variables to fill
var students_results = [];
var answers;
var size_Q;
var answers;
// To display in tables
var scores = [];
var best_score = 0;
var percents_success;
var percents_success_sessionIDs = [];

// Extracting results
// Extracting all values
for(var i=0; i<dataAll.length; i++) {

switch(dataAll[i].TYPE) {

case 'QUESTION':
case 'QUESTION_PIC':

percents_success_sessionIDs.push(dataAll[i].SessionID);
break;

case 'ANSWER':
var studentResults = {};
studentResults.IP = dataAll[i].IP;
Expand All @@ -821,11 +834,12 @@ function calculateAndShowResults(dataAll) {
case 'START_SHOW':
answers = dataAll[i].RANSWER;
size_Q = dataAll[i].NUMQ;
percents_success = dataAll[i].RPERCENT;
break;
}
}

// Getting percents
// Data processing
for(var i=0; i<students_results.length; i++) {

var points = 0;
Expand All @@ -838,12 +852,12 @@ 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);
}

// Injecting scores into students table
// Injecting values to display in student and question tables
$('table#students tr').each(function(index) {
for(var i=0; i<scores.length; i++) {
if($(this).find('td[smile=ip_of_student] input[type=hidden]').val() === scores[i].IP) {
Expand All @@ -860,6 +874,27 @@ function calculateAndShowResults(dataAll) {
}
}
});
$('table#questions tr').each(function(index) {
for(var i=0; i<percents_success.length; i++) {

if($(this).find('input[type=hidden]').attr('name') === percents_success_sessionIDs[i]) {


console.log('TEST');
var html = '<span class="">';

var html;

if(parseInt(percents_success[i]) > 50)
html = '<span class="percent_success">';
else html = '<span class="percent_fail">';

html += percents_success[i]+'<span style="font-size:14px">%</span></span>'

$(this).find('.percentSuccess_container').html(html);
}
}
});
}

// Very useful to redirect views if a message already exists
Expand Down Expand Up @@ -994,8 +1029,6 @@ function postMessage(type,values) {

case 'iqset':

console.log(values);

$.ajax({
cache: false,
type: 'POST',
Expand Down Expand Up @@ -1078,7 +1111,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 +1148,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 +1169,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
Loading

0 comments on commit 62411a6

Please sign in to comment.