Instructions bug fixed (issue #309)

parent 2ad4ba48
...@@ -30,11 +30,11 @@ END;; ...@@ -30,11 +30,11 @@ END;;
-- Memory table in order to recover data about current working sessions -- Memory table in order to recover data about current working sessions
-- --
CREATE TABLE stu_opentry ( CREATE TABLE stu_opentry (
id int NOT NULL AUTO_INCREMENT, id int(11) NOT NULL AUTO_INCREMENT,
id_stu int NOT NULL, id_stu int(11) NOT NULL,
id_sup int NOT NULL, id_sup int(11) NOT NULL,
id_ws int NOT NULL, id_ws int(11) NOT NULL,
id_opentry int , id_opentry int(11) ,
total_tries int DEFAULT 0, total_tries int DEFAULT 0,
begin timestamp NULL, begin timestamp NULL,
end timestamp NULL, end timestamp NULL,
...@@ -42,11 +42,10 @@ PRIMARY KEY(id), ...@@ -42,11 +42,10 @@ PRIMARY KEY(id),
UNIQUE(id_stu), UNIQUE(id_stu),
UNIQUE(id_sup), UNIQUE(id_sup),
UNIQUE(id_ws), UNIQUE(id_ws),
FOREIGN KEY (id_stu) REFERENCES student, FOREIGN KEY (id_stu) REFERENCES student(id),
FOREIGN KEY (id_opentry) REFERENCES try, FOREIGN KEY (id_opentry) REFERENCES try(id) ON DELETE SET NULL,
INDEX USING HASH (id_stu), FOREIGN KEY (id_ws) REFERENCES working_session(id) ON DELETE CASCADE
INDEX USING HASH (id_ws) ) ENGINE=InnoDB;;
) ENGINE=MEMORY;;
-- --
-- It creates a new try and notes down the try into the STU_OPENTRY memory table -- It creates a new try and notes down the try into the STU_OPENTRY memory table
...@@ -87,9 +86,6 @@ BEGIN ...@@ -87,9 +86,6 @@ BEGIN
IF (idopentry IS NOT NULL) THEN IF (idopentry IS NOT NULL) THEN
DELETE FROM try DELETE FROM try
WHERE id = idopentry; WHERE id = idopentry;
UPDATE stu_opentry
SET id_opentry=NULL
WHERE id_opentry = idopentry;
END IF; END IF;
END;; END;;
...@@ -125,12 +121,13 @@ END;; ...@@ -125,12 +121,13 @@ END;;
CREATE TRIGGER TRG_SESSION_CLOSED CREATE TRIGGER TRG_SESSION_CLOSED
AFTER UPDATE ON working_session AFTER UPDATE ON working_session
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN
CALL deleteOpenTry(new.id); CALL deleteOpenTry(new.id);
END IF; END IF;
END;; END;;
-- Integrity rule 3: every event is required to have the id try whenver a try happens -- Integrity rule 3: every event is required to have the id try whenver a try happens
-- when: state COM, event a4 -- when: state COM, event a4
-- --
...@@ -201,7 +198,9 @@ END;; ...@@ -201,7 +198,9 @@ END;;
ALTER TABLE `working_session` ALTER TABLE `working_session`
ADD CONSTRAINT `idx_ws_supcur` UNIQUE (id_sup, current);; ADD CONSTRAINT `idx_ws_supcur` UNIQUE (id_sup, current);;
-- Integrity rule 2: when a session is closed, last try must be discharged
-- Integrity rule 2: when a session is closed, last try must be discharged
-- when: state COM, event a4 -- when: state COM, event a4
-- current is to NULL (integrity rule 6) -- current is to NULL (integrity rule 6)
-- --
......
...@@ -722,7 +722,7 @@ module.exports = { ...@@ -722,7 +722,7 @@ module.exports = {
var attributes = req.param('attributes'); var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu; var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside action"); sails.log.debug("Inside action. Student:"+attributes.id_stu);
if (req.isSocket) { if (req.isSocket) {
sails.log.debug("websockets - room "+roomName); sails.log.debug("websockets - room "+roomName);
......
...@@ -31,7 +31,7 @@ module.exports = { ...@@ -31,7 +31,7 @@ module.exports = {
return res.json(500, {error: 'Working Session could not be closed'}); return res.json(500, {error: 'Working Session could not be closed'});
}}); }});
return res.json(200, {end: ws_end.toISOString()}); return res.json(200, {end: ws_end.toISOString()});
} }
else else
return res.json(200, {result:'no recovery required'}); return res.json(200, {result:'no recovery required'});
...@@ -150,13 +150,13 @@ module.exports = { ...@@ -150,13 +150,13 @@ module.exports = {
WorkingSession.update({id:params.id}, params).exec(function(err, ws){ WorkingSession.update({id:params.id}, params).exec(function(err, ws){
if(err || !ws){ if(err || !ws){
sails.log.debug("Updating Working Sesion: " + err); sails.log.error("Updating Working Sesion error: " + err);
return res.json(500, {error: 'Working Session not updated'}); return res.json(500, {error: 'Working Session not updated'});
} }
sails.log.debug("Working session updated: " + JSON.stringify(ws[0])); sails.log.debug("Working session updated: " + JSON.stringify(ws[0]));
if(params.end!=null){ if(params.end!=null){ //Closing WS
// Create the EndSession Action // Create the EndSession Action
Action.create({ Action.create({
"type": "endsession", "type": "endsession",
...@@ -169,21 +169,27 @@ module.exports = { ...@@ -169,21 +169,27 @@ module.exports = {
return res.json(500, {error: 'Working Session not updated'}); return res.json(500, {error: 'Working Session not updated'});
} }
}); });
}
/* NOT REQUIRED: Integrity session rule #2. Remove open try Try.findOne( { id_ws : params.id } ).exec(function(err, t) { //Deleting empty WS (no tries)
Try.getOpenTry(ws[0].student, function(err, id_try) { if (err) {
if (id_try) sails.log.error("Error Recovering from ws "+err);
Try.destroy({id: id_try}).exec(function deleteCB(err) { return res.json(500, {error: 'recovering from ws:'+err});
if (err) }
sails.log.debug("Error deleting open try " + id_try); if (typeof(t) == 'undefined') /*Empty WS must be deleted*/{
}); sails.log.debug("Empty WS to be deleted, id: "+params.id);
WorkingSession.destroy({id: params.id}).exec(function(err,u) {
if (err) {
sails.log.error("Error deleting empty WS (no tries) " + t.id_ws);
return res.json(500, {error: 'Error deleting empty WS (no tries)'});
}});
}
}); });
*/
// Return the working session updated
return res.json(ws);
} }
); // Return the working session updated
return res.json(ws);
});
}, },
......
...@@ -3,19 +3,58 @@ ...@@ -3,19 +3,58 @@
//----------------------- //-----------------------
// Student Session Controller // Student Session Controller
//----------------------- //-----------------------
dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtrl($rootScope, $scope, $stateParams, $http, config, $window) { dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtrl($scope, $stateParams, $http, config, $window) {
console.log("dashboardControllers reload:"+$scope.$id); console.log("dashboardControllers reload:"+$scope.$id);
// For tab navigation (here too, if the user refresh the page...) // For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'session'; $scope.nav.tab = 'session';
// ----------------------------------------------------------------------
// SESSION
// Prepare session recording information
//
//
// Actual WS
$scope.ws = $scope.ws || {};
$scope.actual_try = $scope.actual_try || {};
// pause flag
$scope.paused = false;
// Read the last working session to show the last tries when session tab is opened
$scope.wsessions = [];
// Query to obtain an array of only one working session (the last) with its tries/actions
$http
.get(config.backend+'/stu/'+ $scope.studentData.id +'/lasttries')
.success(function(data, status, headers, config) {
// Add to list
$scope.wsessions = data;
console.log(JSON.stringify($scope.wsessions));
console.log("Tries of last working session recovered");
$scope.currentPage = 1;
$scope.numPerPage = 5;
$scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
$scope.ws_recover = $scope.wsessions[0]!=null && $scope.wsessions[0].end==null;
console.log("tries: " + $scope.wsessions.length);
console.log("numPerPage: " + $scope.numPerPage);
console.log("pages: " + $scope.totalPages);
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
// Initially, show the last try
$scope.showLastTry = true;
// VER SI BORRAR --> SÓLO NECESARIO PARA DEJAR EN BLANCO LOS ENSAYOS CARGADOS // VER SI BORRAR --> SÓLO NECESARIO PARA DEJAR EN BLANCO LOS ENSAYOS CARGADOS
// Cargar instrucciones en select del método seleccionado arriba // Cargar instrucciones en select del método seleccionado arriba
$scope.load_instructions = function (method){ $scope.load_instructions = function (method){
console.log(JSON.stringify(method)); console.log(JSON.stringify(method));
// Empty ws/tries/actions // Empty ws/tries/actions
$rootScope.wsessions=[]; $scope.wsessions=[];
// Update the number of pages // Update the number of pages
$scope.totalPages = 0; $scope.totalPages = 0;
...@@ -40,15 +79,15 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -40,15 +79,15 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.get(config.backend+'/instruction/'+ instruction.id +'/ws') .get(config.backend+'/instruction/'+ instruction.id +'/ws')
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Add to list // Add to list
$rootScope.wsessions = data; $scope.wsessions = data;
console.log(JSON.stringify($rootScope.wsessions)); console.log(JSON.stringify($scope.wsessions));
console.log("WS/Tries/Actions for instruction "+ instruction.id +" recovered"); console.log("#WS for instruction "+ instruction.id +" recovered: "+$scope.wsessions.length);
// Refresh navigation vars // Refresh navigation vars
$scope.currentPage = 1; $scope.currentPage = 1;
$scope.numPerPage = 5; $scope.numPerPage = 5;
$scope.totalPages = Math.ceil($rootScope.wsessions.length / $scope.numPerPage); $scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
console.log("Error from API: " + data); console.log("Error from API: " + data);
...@@ -64,7 +103,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -64,7 +103,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// Tries pagination - next tries // Tries pagination - next tries
$scope.after = function(){ $scope.after = function(){
var total_pages = Math.ceil($rootScope.wsessions.length / $scope.numPerPage); var total_pages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
if($scope.currentPage < total_pages) $scope.currentPage++; if($scope.currentPage < total_pages) $scope.currentPage++;
}; };
...@@ -88,33 +127,33 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -88,33 +127,33 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.update_current_try = function(){ $scope.update_current_try = function(){
$http $http
.put(config.backend+'/try/' + $rootScope.actual_try.id, { result: $rootScope.actual_try.result, end: new Date() }) .put(config.backend+'/try/' + $scope.actual_try.id, { result: $scope.actual_try.result, end: new Date() })
.then( .then(
function(data, status, headers, config) { function(data, status, headers, config) {
console.log("Current try - updated. Student: " + $scope.studentData.id+" try:"+$rootScope.actual_try.id); console.log("Current try - updated. Student: " + $scope.studentData.id+" try:"+$scope.actual_try.id);
} }
, function(data, status, headers, config) { , function(data, status, headers, config) {
console.log("Error from API: " + data.error+ "when updating try "+$rootScope.actual_try); console.log("Error from API: " + data.error+ "when updating try "+$scope.actual_try);
} }
); );
}; };
$scope.send_show_action = function(){ $scope.send_show_action = function(){
console.log("ACTION!" + $scope.studentData.id+" try:"+$rootScope.actual_try.id); console.log("ACTION!" + $scope.studentData.id+" try:"+$scope.actual_try.id);
$http $http
.post(config.backend+'/action', { .post(config.backend+'/action', {
student: $scope.studentData.id, student: $scope.studentData.id,
type: 'Show', type: 'Show',
timestamp: new Date(), timestamp: new Date(),
_try: $rootScope.actual_try.id _try: $scope.actual_try.id
}) })
.then( .then(
function(data, status, headers, config) { function(data, status, headers, config) {
$scope.load_tries($scope.selectedIns); $scope.load_tries($scope.selectedIns);
// Empty actual try and push the first action of next try // Empty actual try and push the first action of next try
$rootScope.actual_try.actions = []; $scope.actual_try.actions = [];
$rootScope.actual_try.actions.push({ action: 'tryinit' }); $scope.actual_try.actions.push({ action: 'tryinit' });
$rootScope.actual_try.id = data.data.open_try; $scope.actual_try.id = data.data.open_try;
console.log("New try: " + $rootScope.actual_try.id+"="+ data.data.open_try+": "+JSON.stringify(data)); console.log("New try: " + $scope.actual_try.id+"="+ data.data.open_try+": "+JSON.stringify(data));
} }
, function(data, status, headers, config) { , function(data, status, headers, config) {
console.log("Error from API: " + data.error); console.log("Error from API: " + data.error);
...@@ -133,13 +172,13 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -133,13 +172,13 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.close_ws = function (){ $scope.close_ws = function (){
$http $http
.post(config.backend+ '/workingsession/'+$rootScope.wsessions[0].id+'/close') .post(config.backend+ '/workingsession/'+$scope.wsessions[0].id+'/close')
.then( .then(
function(data, status, headers, config) { function(data, status, headers, config) {
$rootScope.wsessions[0].end=data.data.end; $scope.wsessions[0].end=data.data.end;
$scope.ws_recover=false; $scope.ws_recover=false;
console.log("WS " + $rootScope.wsessions[0].id + "closed at "+ JSON.stringify(data.data.end)); console.log("WS " + $scope.wsessions[0].id + "closed at "+ JSON.stringify(data.data.end));
} }
, function(data, status, headers, config) { , function(data, status, headers, config) {
console.log("Error from API: " + data.error); console.log("Error from API: " + data.error);
...@@ -165,7 +204,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -165,7 +204,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Actual WS // Actual WS
$rootScope.ws = { $scope.ws = {
id: data.id id: data.id
}; };
...@@ -173,14 +212,14 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -173,14 +212,14 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// List of tries --> empty // List of tries --> empty
// BORRAR después lo que no sirva // BORRAR después lo que no sirva
$rootScope.actual_try = { $scope.actual_try = {
actions: [], actions: [],
id: data.first_try_id, id: data.first_try_id,
result: null result: null
}; };
// Adding initial action to the list of actions // Adding initial action to the list of actions
$rootScope.actual_try.actions.push({ action: 'tryinit' }); $scope.actual_try.actions.push({ action: 'tryinit' });
console.log("WS created for method "+$scope.selectedMethod.name+" Ins:"+$scope.selectedIns.name+": "+JSON.stringify(data)); console.log("WS created for method "+$scope.selectedMethod.name+" Ins:"+$scope.selectedIns.name+": "+JSON.stringify(data));
$scope.studentData.current_method=$scope.selectedMethod.name; $scope.studentData.current_method=$scope.selectedMethod.name;
$scope.studentData.current_instruction=$scope.selectedIns.name; $scope.studentData.current_instruction=$scope.selectedIns.name;
...@@ -213,18 +252,18 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -213,18 +252,18 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// For view // For view
$scope.sessionRunning = false; $scope.sessionRunning = false;
$rootScope.ws.end = new Date(); $scope.ws.end = new Date();
$http $http
.put(config.backend+'/workingsession/' + $rootScope.ws.id, { "end": $rootScope.ws.end, .put(config.backend+'/workingsession/' + $scope.ws.id, { "end": $scope.ws.end,
"id_stu": $scope.studentData.id "id_stu": $scope.studentData.id
}) })
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
console.log("WS stopped - updated: " + JSON.stringify(data)); console.log("WS stopped - updated: " + JSON.stringify(data));
// Empty actual WS and actual try // Empty actual WS and actual try
$rootScope.ws = {}; $scope.ws = {};
$rootScope.actual_try = {}; $scope.actual_try = {};
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
console.log("Error from API: " + data.error); console.log("Error from API: " + data.error);
...@@ -245,7 +284,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -245,7 +284,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
action: 'pausesession', action: 'pausesession',
attributes: { attributes: {
id_stu: $scope.studentData.id, id_stu: $scope.studentData.id,
id_ws: $rootScope.ws.id id_ws: $scope.ws.id
} }
}; };
...@@ -265,7 +304,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -265,7 +304,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
console.log("Action created: " + JSON.stringify(data)); console.log("Action created: " + JSON.stringify(data));
// Adding pause action to the list of actions // Adding pause action to the list of actions
$rootScope.actual_try.actions.push({ action: 'pausesession'} ); $scope.actual_try.actions.push({ action: 'pausesession'} );
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
...@@ -284,7 +323,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -284,7 +323,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
action: 'resumesession', action: 'resumesession',
attributes: { attributes: {
id_stu: $scope.studentData.id, id_stu: $scope.studentData.id,
id_ws: $rootScope.ws.id id_ws: $scope.ws.id
} }
}; };
...@@ -304,7 +343,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -304,7 +343,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
console.log("Action created: " + JSON.stringify(data)); console.log("Action created: " + JSON.stringify(data));
// Adding pause action to the list of actions // Adding pause action to the list of actions
$rootScope.actual_try.actions.push({ action: 'resumesession'} ); $scope.actual_try.actions.push({ action: 'resumesession'} );
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
...@@ -349,8 +388,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -349,8 +388,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
*/ */
$scope.is_currentOpenTry = function(t) { $scope.is_currentOpenTry = function(t) {
if (t.end==null && $rootScope.ws.id==t.workingSession) { if (t.end==null && $scope.ws.id==t.workingSession) {
$rootScope.actual_try.id=t.id; $scope.actual_try.id=t.id;
return true; return true;
} }
return false; return false;
...@@ -389,7 +428,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -389,7 +428,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
}; };
// For simulating the managing of the try in the pcb // For simulating the managing of the try in the pcb
// if($rootScope.ws) $scope.pcb_try = {}; // if($scope.ws) $scope.pcb_try = {};
$scope.pcb_actions = []; $scope.pcb_actions = [];
...@@ -517,14 +556,14 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -517,14 +556,14 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// It depends on the working session created // It depends on the working session created
// Here is controlled by a scope var, but in PCB it will be created // Here is controlled by a scope var, but in PCB it will be created
// a flag var to this purpouse when it gets an "WSInit" action // a flag var to this purpouse when it gets an "WSInit" action
if($rootScope.ws){ if($scope.ws){
// End the try with actual time // End the try with actual time
$scope.pcb_try.end = endDate; $scope.pcb_try.end = endDate;
// Save actions with a try (working session is running) // Save actions with a try (working session is running)
$http $http
.post(config.backend+'/try', { .post(config.backend+'/try', {
"ws": $rootScope.ws.id, "ws": $scope.ws.id,
"begin": $scope.pcb_try.begin, "begin": $scope.pcb_try.begin,
"end": $scope.pcb_try.end, "end": $scope.pcb_try.end,
"actions": $scope.pcb_actions, "actions": $scope.pcb_actions,
...@@ -571,7 +610,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -571,7 +610,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.unshow_sentence = function(){ $scope.unshow_sentence = function(){
// Begin a new try if there is a session initiated // Begin a new try if there is a session initiated
if($rootScope.ws){ if($scope.ws){
$scope.pcb_try = {}; $scope.pcb_try = {};
$scope.pcb_try.begin = new Date(); $scope.pcb_try.begin = new Date();
} }
...@@ -650,7 +689,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -650,7 +689,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
case 'endsession': case 'endsession':
console.log("PCB: EndSession action!!!!!!!!!!!!!"); console.log("PCB: EndSession action!!!!!!!!!!!!!");
// In PCB use other var to control the session (it is important to save the actions with or without the id_try field) // In PCB use other var to control the session (it is important to save the actions with or without the id_try field)
$rootScope.ws = null; $scope.ws = null;
break; break;
case 'pausesession': case 'pausesession':
console.log("PCB: blocked"); console.log("PCB: blocked");
...@@ -695,19 +734,19 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -695,19 +734,19 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
console.log('Action '+ data.action +' event received with the following data:'); console.log('Action '+ data.action +' event received with the following data:');
console.log(JSON.stringify(data.attributes)); console.log(JSON.stringify(data.attributes));
if($rootScope.ws){ if($scope.ws){
switch(data.action){ switch(data.action){
case 'Add': case 'Add':
console.log("ADD action to ws "+$rootScope.ws.id+":"+$rootScope.actual_try.id+" Scope:"+$scope.$id); console.log("ADD action to ws "+$scope.ws.id+":"+$scope.actual_try.id+" Scope:"+$scope.$id);
$rootScope.actual_try.actions.push(data); $scope.actual_try.actions.push(data);
break; break;
case 'Delete': case 'Delete':
console.log("delete action!!!!!!!!!!!!!"); console.log("delete action!!!!!!!!!!!!!");
$rootScope.actual_try.actions.push(data); $scope.actual_try.actions.push(data);
break; break;
case 'Select': case 'Select':
console.log("select action!!!!!!!!!!!!"); console.log("select action!!!!!!!!!!!!");
$rootScope.actual_try.actions.push(data); $scope.actual_try.actions.push(data);
break; break;
case 'Show': case 'Show':
console.log("show action!!!!!!!!!!!!"); console.log("show action!!!!!!!!!!!!");
...@@ -721,27 +760,27 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -721,27 +760,27 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.load_tries($scope.selectedIns); $scope.load_tries($scope.selectedIns);
/* /*
// Add the last show action to the list of try actions // Add the last show action to the list of try actions
$rootScope.actual_try.actions.push(data); $scope.actual_try.actions.push(data);
// Put it in the list // Put it in the list
$rootScope.wsessions.push($rootScope.actual_try); $scope.wsessions.push($scope.actual_try);
// Update total pages for navigation // Update total pages for navigation
$scope.totalPages = Math.ceil($rootScope.wsessions.length / $scope.numPerPage); $scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
*/ */
// Empty actual try and push the first action of next try // Empty actual try and push the first action of next try
$rootScope.actual_try.actions = []; $scope.actual_try.actions = [];
$rootScope.actual_try.actions.push({ action: 'tryinit' }); $scope.actual_try.actions.push({ action: 'tryinit' });
break; break;
/* /*
case 'unshow': case 'unshow':
console.log("unshow action!!!!!!!!!!!!"); console.log("unshow action!!!!!!!!!!!!");
$rootScope.actual_try.actions = []; $scope.actual_try.actions = [];
$rootScope.actual_try.actions.push(data); $scope.actual_try.actions.push(data);
// If a session is initiated // If a session is initiated
if($rootScope.ws){ if($scope.ws){
// Start the timer for the new try // Start the timer for the new try
$scope.startTimer(); $scope.startTimer();
} }
......
...@@ -204,46 +204,7 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf ...@@ -204,46 +204,7 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf
console.log("Error from API: " + data.error); console.log("Error from API: " + data.error);
}); });
// ----------------------------------------------------------------------
// SESSION
// Prepare session recording information
//
//
// Actual WS
$rootScope.ws = $rootScope.ws || {};
$rootScope.actual_try = $rootScope.actual_try || {};
// pause flag
$scope.paused = false;
// Read the last working session to show the last tries when session tab is opened
$rootScope.wsessions = [];
// Query to obtain an array of only one working session (the last) with its tries/actions
$http
.get(config.backend+'/stu/'+ $scope.studentData.id +'/lasttries')
.success(function(data, status, headers, config) {
// Add to list
$rootScope.wsessions = data;
console.log(JSON.stringify($rootScope.wsessions));
console.log("Tries of last working session recovered");
$scope.currentPage = 1;
$scope.numPerPage = 5;
$scope.totalPages = Math.ceil($rootScope.wsessions.length / $scope.numPerPage);
$scope.ws_recover = $rootScope.wsessions[0]!=null && $rootScope.wsessions[0].end==null;
console.log("tries: " + $rootScope.wsessions.length);
console.log("numPerPage: " + $scope.numPerPage);
console.log("pages: " + $scope.totalPages);
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
// Initially, show the last try
$scope.showLastTry = true;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
......
...@@ -199,7 +199,7 @@ ...@@ -199,7 +199,7 @@
</table> </table>
</p> </p>
</div> </div>
</div> </div> <!--showLasTry -->
<button class="btn btn-primary pull-right" type="button" ng-click="showTries = !showTries"> <button class="btn btn-primary pull-right" type="button" ng-click="showTries = !showTries">
Ensayos <span class="badge">{{ s.tries.length }}</span> Ensayos <span class="badge">{{ s.tries.length }}</span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment