Instructions bug fixed (issue #309)

parent 2ad4ba48
......@@ -30,11 +30,11 @@ END;;
-- Memory table in order to recover data about current working sessions
--
CREATE TABLE stu_opentry (
id int NOT NULL AUTO_INCREMENT,
id_stu int NOT NULL,
id_sup int NOT NULL,
id_ws int NOT NULL,
id_opentry int ,
id int(11) NOT NULL AUTO_INCREMENT,
id_stu int(11) NOT NULL,
id_sup int(11) NOT NULL,
id_ws int(11) NOT NULL,
id_opentry int(11) ,
total_tries int DEFAULT 0,
begin timestamp NULL,
end timestamp NULL,
......@@ -42,11 +42,10 @@ PRIMARY KEY(id),
UNIQUE(id_stu),
UNIQUE(id_sup),
UNIQUE(id_ws),
FOREIGN KEY (id_stu) REFERENCES student,
FOREIGN KEY (id_opentry) REFERENCES try,
INDEX USING HASH (id_stu),
INDEX USING HASH (id_ws)
) ENGINE=MEMORY;;
FOREIGN KEY (id_stu) REFERENCES student(id),
FOREIGN KEY (id_opentry) REFERENCES try(id) ON DELETE SET NULL,
FOREIGN KEY (id_ws) REFERENCES working_session(id) ON DELETE CASCADE
) ENGINE=InnoDB;;
--
-- It creates a new try and notes down the try into the STU_OPENTRY memory table
......@@ -87,9 +86,6 @@ BEGIN
IF (idopentry IS NOT NULL) THEN
DELETE FROM try
WHERE id = idopentry;
UPDATE stu_opentry
SET id_opentry=NULL
WHERE id_opentry = idopentry;
END IF;
END;;
......@@ -131,6 +127,7 @@ BEGIN
END IF;
END;;
-- Integrity rule 3: every event is required to have the id try whenver a try happens
-- when: state COM, event a4
--
......@@ -201,6 +198,8 @@ END;;
ALTER TABLE `working_session`
ADD CONSTRAINT `idx_ws_supcur` UNIQUE (id_sup, current);;
-- Integrity rule 2: when a session is closed, last try must be discharged
-- when: state COM, event a4
-- current is to NULL (integrity rule 6)
......
......@@ -722,7 +722,7 @@ module.exports = {
var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside action");
sails.log.debug("Inside action. Student:"+attributes.id_stu);
if (req.isSocket) {
sails.log.debug("websockets - room "+roomName);
......
......@@ -150,13 +150,13 @@ module.exports = {
WorkingSession.update({id:params.id}, params).exec(function(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'});
}
sails.log.debug("Working session updated: " + JSON.stringify(ws[0]));
if(params.end!=null){
if(params.end!=null){ //Closing WS
// Create the EndSession Action
Action.create({
"type": "endsession",
......@@ -169,21 +169,27 @@ module.exports = {
return res.json(500, {error: 'Working Session not updated'});
}
});
Try.findOne( { id_ws : params.id } ).exec(function(err, t) { //Deleting empty WS (no tries)
if (err) {
sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err});
}
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)'});
}});
}
/* NOT REQUIRED: Integrity session rule #2. Remove open try
Try.getOpenTry(ws[0].student, function(err, id_try) {
if (id_try)
Try.destroy({id: id_try}).exec(function deleteCB(err) {
if (err)
sails.log.debug("Error deleting open try " + id_try);
});
});
*/
}
// Return the working session updated
return res.json(ws);
}
);
});
},
......
......@@ -3,19 +3,58 @@
//-----------------------
// 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);
// For tab navigation (here too, if the user refresh the page...)
$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
// Cargar instrucciones en select del método seleccionado arriba
$scope.load_instructions = function (method){
console.log(JSON.stringify(method));
// Empty ws/tries/actions
$rootScope.wsessions=[];
$scope.wsessions=[];
// Update the number of pages
$scope.totalPages = 0;
......@@ -40,15 +79,15 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.get(config.backend+'/instruction/'+ instruction.id +'/ws')
.success(function(data, status, headers, config) {
// Add to list
$rootScope.wsessions = data;
$scope.wsessions = data;
console.log(JSON.stringify($rootScope.wsessions));
console.log("WS/Tries/Actions for instruction "+ instruction.id +" recovered");
console.log(JSON.stringify($scope.wsessions));
console.log("#WS for instruction "+ instruction.id +" recovered: "+$scope.wsessions.length);
// Refresh navigation vars
$scope.currentPage = 1;
$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) {
console.log("Error from API: " + data);
......@@ -64,7 +103,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// Tries pagination - next tries
$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++;
};
......@@ -88,33 +127,33 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.update_current_try = function(){
$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(
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) {
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(){
console.log("ACTION!" + $scope.studentData.id+" try:"+$rootScope.actual_try.id);
console.log("ACTION!" + $scope.studentData.id+" try:"+$scope.actual_try.id);
$http
.post(config.backend+'/action', {
student: $scope.studentData.id,
type: 'Show',
timestamp: new Date(),
_try: $rootScope.actual_try.id
_try: $scope.actual_try.id
})
.then(
function(data, status, headers, config) {
$scope.load_tries($scope.selectedIns);
// Empty actual try and push the first action of next try
$rootScope.actual_try.actions = [];
$rootScope.actual_try.actions.push({ action: 'tryinit' });
$rootScope.actual_try.id = data.data.open_try;
console.log("New try: " + $rootScope.actual_try.id+"="+ data.data.open_try+": "+JSON.stringify(data));
$scope.actual_try.actions = [];
$scope.actual_try.actions.push({ action: 'tryinit' });
$scope.actual_try.id = data.data.open_try;
console.log("New try: " + $scope.actual_try.id+"="+ data.data.open_try+": "+JSON.stringify(data));
}
, function(data, status, headers, config) {
console.log("Error from API: " + data.error);
......@@ -133,13 +172,13 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.close_ws = function (){
$http
.post(config.backend+ '/workingsession/'+$rootScope.wsessions[0].id+'/close')
.post(config.backend+ '/workingsession/'+$scope.wsessions[0].id+'/close')
.then(
function(data, status, headers, config) {
$rootScope.wsessions[0].end=data.data.end;
$scope.wsessions[0].end=data.data.end;
$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) {
console.log("Error from API: " + data.error);
......@@ -165,7 +204,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.success(function(data, status, headers, config) {
// Actual WS
$rootScope.ws = {
$scope.ws = {
id: data.id
};
......@@ -173,14 +212,14 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// List of tries --> empty
// BORRAR después lo que no sirva
$rootScope.actual_try = {
$scope.actual_try = {
actions: [],
id: data.first_try_id,
result: null
};
// 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));
$scope.studentData.current_method=$scope.selectedMethod.name;
$scope.studentData.current_instruction=$scope.selectedIns.name;
......@@ -213,18 +252,18 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// For view
$scope.sessionRunning = false;
$rootScope.ws.end = new Date();
$scope.ws.end = new Date();
$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
})
.success(function(data, status, headers, config) {
console.log("WS stopped - updated: " + JSON.stringify(data));
// Empty actual WS and actual try
$rootScope.ws = {};
$rootScope.actual_try = {};
$scope.ws = {};
$scope.actual_try = {};
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
......@@ -245,7 +284,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
action: 'pausesession',
attributes: {
id_stu: $scope.studentData.id,
id_ws: $rootScope.ws.id
id_ws: $scope.ws.id
}
};
......@@ -265,7 +304,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
console.log("Action created: " + JSON.stringify(data));
// 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) {
......@@ -284,7 +323,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
action: 'resumesession',
attributes: {
id_stu: $scope.studentData.id,
id_ws: $rootScope.ws.id
id_ws: $scope.ws.id
}
};
......@@ -304,7 +343,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
console.log("Action created: " + JSON.stringify(data));
// 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) {
......@@ -349,8 +388,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
*/
$scope.is_currentOpenTry = function(t) {
if (t.end==null && $rootScope.ws.id==t.workingSession) {
$rootScope.actual_try.id=t.id;
if (t.end==null && $scope.ws.id==t.workingSession) {
$scope.actual_try.id=t.id;
return true;
}
return false;
......@@ -389,7 +428,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
};
// 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 = [];
......@@ -517,14 +556,14 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// It depends on the working session 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
if($rootScope.ws){
if($scope.ws){
// End the try with actual time
$scope.pcb_try.end = endDate;
// Save actions with a try (working session is running)
$http
.post(config.backend+'/try', {
"ws": $rootScope.ws.id,
"ws": $scope.ws.id,
"begin": $scope.pcb_try.begin,
"end": $scope.pcb_try.end,
"actions": $scope.pcb_actions,
......@@ -571,7 +610,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.unshow_sentence = function(){
// Begin a new try if there is a session initiated
if($rootScope.ws){
if($scope.ws){
$scope.pcb_try = {};
$scope.pcb_try.begin = new Date();
}
......@@ -650,7 +689,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
case 'endsession':
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)
$rootScope.ws = null;
$scope.ws = null;
break;
case 'pausesession':
console.log("PCB: blocked");
......@@ -695,19 +734,19 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
console.log('Action '+ data.action +' event received with the following data:');
console.log(JSON.stringify(data.attributes));
if($rootScope.ws){
if($scope.ws){
switch(data.action){
case 'Add':
console.log("ADD action to ws "+$rootScope.ws.id+":"+$rootScope.actual_try.id+" Scope:"+$scope.$id);
$rootScope.actual_try.actions.push(data);
console.log("ADD action to ws "+$scope.ws.id+":"+$scope.actual_try.id+" Scope:"+$scope.$id);
$scope.actual_try.actions.push(data);
break;
case 'Delete':
console.log("delete action!!!!!!!!!!!!!");
$rootScope.actual_try.actions.push(data);
$scope.actual_try.actions.push(data);
break;
case 'Select':
console.log("select action!!!!!!!!!!!!");
$rootScope.actual_try.actions.push(data);
$scope.actual_try.actions.push(data);
break;
case 'Show':
console.log("show action!!!!!!!!!!!!");
......@@ -721,27 +760,27 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.load_tries($scope.selectedIns);
/*
// 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
$rootScope.wsessions.push($rootScope.actual_try);
$scope.wsessions.push($scope.actual_try);
// 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
$rootScope.actual_try.actions = [];
$rootScope.actual_try.actions.push({ action: 'tryinit' });
$scope.actual_try.actions = [];
$scope.actual_try.actions.push({ action: 'tryinit' });
break;
/*
case 'unshow':
console.log("unshow action!!!!!!!!!!!!");
$rootScope.actual_try.actions = [];
$rootScope.actual_try.actions.push(data);
$scope.actual_try.actions = [];
$scope.actual_try.actions.push(data);
// If a session is initiated
if($rootScope.ws){
if($scope.ws){
// Start the timer for the new try
$scope.startTimer();
}
......
......@@ -204,46 +204,7 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf
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 @@
</table>
</p>
</div>
</div>
</div> <!--showLasTry -->
<button class="btn btn-primary pull-right" type="button" ng-click="showTries = !showTries">
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