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);
});
}, },
......
...@@ -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