Commit aea59bf9 by Fernando Martínez Santiago

Merge remote-tracking branch 'origin/develop' into fernando_branch

parents 341288b6 e591ab9e
...@@ -368,7 +368,7 @@ CREATE TABLE IF NOT EXISTS `try` ( ...@@ -368,7 +368,7 @@ CREATE TABLE IF NOT EXISTS `try` (
`id_ws` int(11) NOT NULL, `id_ws` int(11) NOT NULL,
`begin` timestamp(3) DEFAULT CURRENT_TIMESTAMP(3), `begin` timestamp(3) DEFAULT CURRENT_TIMESTAMP(3),
`end` timestamp(3) NULL, `end` timestamp(3) NULL,
`result` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `result` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL CHECK (result IN ('SUCCESS','SPONTANEUS SUCCESS', 'SUPERVISED SUCCESS', 'FAIL','DISCARDED','MODEL')),
`description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `id_ws` (`id_ws`) KEY `id_ws` (`id_ws`)
......
...@@ -128,7 +128,7 @@ END;; ...@@ -128,7 +128,7 @@ END;;
-- 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 set NULL (integrity rule 6)
-- --
DROP TRIGGER IF EXISTS TRG_SESSION_CLOSED; DROP TRIGGER IF EXISTS TRG_SESSION_CLOSED;
CREATE TRIGGER TRG_SESSION_CLOSED CREATE TRIGGER TRG_SESSION_CLOSED
...@@ -181,7 +181,7 @@ END;; ...@@ -181,7 +181,7 @@ END;;
-- when: state COM, event a4 -- when: state COM, event a4
-- Integrity rule 5: when a session is continued after a pause and new try is created -- Integrity rule 5: when a session is continued after a pause and new try is created
-- when: state PAU, event a3 -- when: state PAU, event a3
-- Integrity rule 4: when a session is paused, last try must be discharged -- Integrity rule 4: when a session is paused, last try must be saved as not valid
-- when: state SES, event a3 -- when: state SES, event a3
DROP TRIGGER IF EXISTS TRG_NEW_EVENT; DROP TRIGGER IF EXISTS TRG_NEW_EVENT;
CREATE TRIGGER TRG_NEW_EVENT CREATE TRIGGER TRG_NEW_EVENT
...@@ -219,7 +219,7 @@ thisTrigger: BEGIN ...@@ -219,7 +219,7 @@ thisTrigger: BEGIN
WHERE WHERE
id_stu = NEW.id_stu; id_stu = NEW.id_stu;
IF (idopentry IS NOT NULL) THEN IF (idopentry IS NOT NULL) THEN
call deleteOpenTry(idws); UPDATE try set end=NOW(), result='DISCARDED' where id=idopentry;
END IF; END IF;
WHEN 'resumesession' THEN WHEN 'resumesession' THEN
SELECT id_ws, id_opentry INTO idws, idopentry SELECT id_ws, id_opentry INTO idws, idopentry
......
...@@ -608,6 +608,7 @@ module.exports = { ...@@ -608,6 +608,7 @@ module.exports = {
return res.json(l_met); return res.json(l_met);
} }
}); });
} }
}); });
}, },
...@@ -1005,7 +1006,11 @@ module.exports = { ...@@ -1005,7 +1006,11 @@ module.exports = {
// Leave all rooms // Leave all rooms
for (var i = 0; i < rooms.length; i++) { for (var i = 0; i < rooms.length; i++) {
sails.sockets.leave(req.socket, rooms[i]); //sails.sockets.leave(req.socket, rooms[i]); MODIFICADO POR FERNANDO. SI NO, NO SE ACTUALIZA UPDATE_PEERS
sails.hooks.rooms.unsubscribeFromRoom(
rooms[i],
req.socket
);
sails.log.debug("Unsusbscribe from room " + rooms[i]); sails.log.debug("Unsusbscribe from room " + rooms[i]);
} }
......
/** /**
* This hook is used for managing the rooms IDs. * This hook is used for managing the rooms IDs.
* Every room created should call one of this functions in order * Every room created should call one of this functions in order
* to obtain an ID. * to obtain an ID.
* @type {Object} * @type {Object}
*/ */
var socketRooms={};
module.exports = function roomsHook (sails) { module.exports = function roomsHook (sails) {
return { return {
getRoom: function (socket) {
return socketRooms[sails.sockets.getId(socket)];
},
/** /**
* Special function that subscribes a socket to a given room. * Special function that subscribes a socket to a given room.
* This creates the connection and logs to debug with this format: * This creates the connection and logs to debug with this format:
...@@ -18,16 +25,20 @@ module.exports = function roomsHook (sails) { ...@@ -18,16 +25,20 @@ module.exports = function roomsHook (sails) {
* } * }
* *
* @param {RoomID} room Room to subscribe * @param {RoomID} room Room to subscribe
* @param {Socket} socket Socket added to the subscription * @param {Socket} socket Socket added to the subscription<
*/ */
subscribeToRoom: function (room, socket) { subscribeToRoom: function (room, socket) {
sails.log.debug('"websocketSubscribe":', JSON.stringify({ sails.log.debug('"websocketSubscribe":', JSON.stringify({
room: room, room: room,
socket: socket.id socket: socket.id
})); }));
sails.sockets.join(socket, room, function () { sails.sockets.join(socket, room, function () {
sails.io.sockets.in(room).clients(function(error, ids) { sails.io.sockets.in(room).clients(function(error, ids) {
if (!error) { if (!error) {
socketRooms[sails.sockets.getId(socket)] =
socketRooms[sails.sockets.getId(socket)] ? [socketRooms[sails.sockets.getId(socket)],room]
: [room];
sails.hooks.events.broadcastEvent( sails.hooks.events.broadcastEvent(
room, room,
sails.hooks.events.roomSubscribersChange(ids.length) sails.hooks.events.roomSubscribersChange(ids.length)
...@@ -63,6 +74,12 @@ module.exports = function roomsHook (sails) { ...@@ -63,6 +74,12 @@ module.exports = function roomsHook (sails) {
room, room,
sails.hooks.events.roomSubscribersChange(ids.length) sails.hooks.events.roomSubscribersChange(ids.length)
); );
if (socketRooms[sails.sockets.getId(socket)]) {
var index=socketRooms[sails.sockets.getId(socket)].indexOf(room);
if (index > -1) {
socketRooms[sails.sockets.getId(socket)].splice(index, 1);
}
}
} }
}); });
}); });
......
...@@ -98,9 +98,11 @@ module.exports = { ...@@ -98,9 +98,11 @@ module.exports = {
}); });
}, },
// 3rd final function when everything is ready // 3rd final function when everything is ready
function (err){ function (err){
console.log("Final function recovering working sessions / tries / actions"); if (err) {
//console.log(JSON.stringify(l_ws)); console.log("Error recovering working sessions / tries / actions");
console.log("Error detail:"+JSON.stringify(err));
}
return callback(err, l_ws); return callback(err, l_ws);
// If one iteration give an error it is sent to the controller // If one iteration give an error it is sent to the controller
// with the list // with the list
......
...@@ -41,6 +41,7 @@ module.exports = { ...@@ -41,6 +41,7 @@ module.exports = {
}, },
current: { current: {
type: "integer", type: "integer",
defaultsTo: 1
}, },
description: { description: {
type: "string", type: "string",
...@@ -55,7 +56,7 @@ module.exports = { ...@@ -55,7 +56,7 @@ module.exports = {
/** /**
* Checks a previous session is not opened for that supervisor. If so, * Checks a previous session is not opened for that supervisor. If so,
* session is closed (current is set to 0) * session is closed (current is set NULL)
* @param {Object} attrs All session properties to be stored * @param {Object} attrs All session properties to be stored
* @param {Function} next Function to be executed when the check process * @param {Function} next Function to be executed when the check process
* has been completed (an error object will be passed * has been completed (an error object will be passed
...@@ -66,9 +67,8 @@ module.exports = { ...@@ -66,9 +67,8 @@ module.exports = {
.then(function(wss) { .then(function(wss) {
if (wss) { if (wss) {
async.each(wss, function(ws, cb) { async.each(wss, function(ws, cb) {
ws.current = 0; WorkingSession.update(ws.id, {current:null}, function(err, update) {
WorkingSession.update(ws.id, ws, function(err, update) { if (err) throw new Error("Error when udpating open sessions: "+JSON.stringify(err));
if (err) throw new Error("Error when udpating open sessions");
cb(); cb();
}); });
}); });
......
...@@ -200,6 +200,7 @@ ...@@ -200,6 +200,7 @@
"register": "Sign in", "register": "Sign in",
"remember": "Remember me", "remember": "Remember me",
"reports": "Reports", "reports": "Reports",
"room_changed": "A partner is offline. Session paused."
"save": "Save", "save": "Save",
"save_as_template": "Save as template", "save_as_template": "Save as template",
"search": "Search", "search": "Search",
...@@ -298,7 +299,8 @@ ...@@ -298,7 +299,8 @@
"vibration": "Vibration", "vibration": "Vibration",
"view": "View", "view": "View",
"voice": "Voice", "voice": "Voice",
"warning_last_session_bad": "&nbsp;Last session was bad closed. <p/> &nbsp;Please, you must evaluate last tries before starting a new session", "warning_last_session_bad": "&nbsp;Last session was bad closed. <p/> &nbsp;Please, you must evaluate last tries and press 'close seesion' button",
"warning_no_tablet_online":"No Pictogran Tablet online detected",
"woman": "Woman", "woman": "Woman",
"year_totals": "Year totals", "year_totals": "Year totals",
"yes": "Yes", "yes": "Yes",
......
...@@ -201,6 +201,7 @@ ...@@ -201,6 +201,7 @@
"register_button": "Registrar", "register_button": "Registrar",
"remember": "No cerrar sesión", "remember": "No cerrar sesión",
"reports": "Informes", "reports": "Informes",
"room_changed":"Un participante abandonó la sesión. Sesión en pausa.",
"save": "Guardar", "save": "Guardar",
"save_as_template": "Guardar como plantilla", "save_as_template": "Guardar como plantilla",
"search": "Buscar", "search": "Buscar",
...@@ -299,7 +300,8 @@ ...@@ -299,7 +300,8 @@
"vibration": "Vibración", "vibration": "Vibración",
"view": "Vista", "view": "Vista",
"voice": "Voz", "voice": "Voz",
"warning_last_session_bad": "&nbsp;La última sesión no se cerró correctamente. <p/> &nbsp;Por favor, evalúe los ensayos correspondientes antes de iniciar una nueva sesión ", "warning_last_session_bad": "&nbsp;La última sesión no se cerró correctamente. <p/> &nbsp;Por favor, evalúe los ensayos y pulse 'cerrar sesión' ",
"warning_no_tablet_online":"No se detectó ningún usuario de Pictogram Tablet online",
"woman": "Mujer", "woman": "Mujer",
"year_totals": "Totales año", "year_totals": "Totales año",
"yes": "Sí", "yes": "Sí",
......
...@@ -297,7 +297,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -297,7 +297,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/action', { .post(config.backend+'/action', {
"type": "pausesession", "type": "pausesession",
"student": $scope.studentData.id, "student": $scope.studentData.id,
"supervisor": $scope.user.id "supervisor": $scope.user.id,
"timestamp": (new Date()).toISOString()
}) })
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Gettinf rid of last try and adding pause action to the list of actions // Gettinf rid of last try and adding pause action to the list of actions
...@@ -318,7 +319,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -318,7 +319,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/action', { .post(config.backend+'/action', {
"type": "resumesession", "type": "resumesession",
"student": $scope.studentData.id, "student": $scope.studentData.id,
"supervisor": $scope.user.id "supervisor": $scope.user.id,
"timestamp": (new Date()).toISOString()
}) })
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Adding pause action to the list of actions // Adding pause action to the list of actions
...@@ -378,6 +380,22 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -378,6 +380,22 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// //
io.socket.on('update_peers', function (data) {
if($scope.ws && $scope.actual_try.actions && $scope.paused == false && data.count<$scope.studentData.prev_num_peers) {
$scope.pause_ws();
$scope.pauseTimer();
$translate('room_changed').then(function (translation) {
ngToast.create({
className: 'warning',
content: translation,
dismissOnTimeout: false,
dismissButton: true
});
});
}
});
// Remove all listeners to this event // Remove all listeners to this event
io.socket.off('action'); io.socket.off('action');
...@@ -388,7 +406,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -388,7 +406,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// doesn't know new data has come in. Inside the socket.io callback, // doesn't know new data has come in. Inside the socket.io callback,
// as the last action, added $scope.apply() that lets angular know // as the last action, added $scope.apply() that lets angular know
// what data has updated, and refresh what needs to be refreshed. // what data has updated, and refresh what needs to be refreshed.
//only events (i) from a student (and ii)when a try is opened are managed
if($scope.ws && $scope.actual_try.actions && !data.attributes.id_sup && $scope.paused == false){ if($scope.ws && $scope.actual_try.actions && !data.attributes.id_sup && $scope.paused == false){
switch(data.action){ switch(data.action){
...@@ -410,6 +428,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -410,6 +428,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
} }
} }
$scope.$apply(); $scope.$apply();
}); });
}); });
...@@ -33,7 +33,8 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl( ...@@ -33,7 +33,8 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl(
name: '' name: ''
}, },
stuSup: [], stuSup: [],
num_peers: 1 num_peers: 1,
prev_num_peers: 1
}; };
// For the user form data in setup section // For the user form data in setup section
...@@ -52,7 +53,10 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl( ...@@ -52,7 +53,10 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl(
// $translate('num_peers').then(function (translation) { // $translate('num_peers').then(function (translation) {
// ngToast.success(translation + ': ' + data.count); // ngToast.success(translation + ': ' + data.count);
//}); //});
$scope.studentData.prev_num_peers = $scope.studentData.num_peers;
$scope.studentData.num_peers = data.count; $scope.studentData.num_peers = data.count;
console.log('Usuarios conectados:'+$scope.studentData.num_peers+ " previamente:"+$scope.studentData.prev_num_peers);
$scope.$apply();
}); });
io.socket.on('reconnect', function () { io.socket.on('reconnect', function () {
......
<div class="panel panel-default student_tab_panel"> <div class="panel panel-default student_tab_panel">
<div class="panel-body"> <div class="panel-body">
<div ng-show="studentData.num_peers<2" >
<table style="border: 1px solid #666666; padding:5px; background-color:#f5f5f5;" width="50%">
<tr>
<td><h4 translate>warning_no_tablet_online</h4></td>
</tr>
</table>
</div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<form role="form" action="#"> <form role="form" action="#" ng-hide="ws_recover ">
<select class="form-control" name="met_select" id="met_select" ng-model="selectedMethod" ng-options="m.name for m in methods" ng-change="load_instructions(selectedMethod)"> <select class="form-control" name="met_select" id="met_select" ng-model="selectedMethod" ng-options="m.name for m in methods" ng-change="load_instructions(selectedMethod)">
<option value="" translate>select_a_method</option> <option value="" translate>select_a_method</option>
</select> </select>
...@@ -15,7 +22,7 @@ ...@@ -15,7 +22,7 @@
<div class="row" ng-hide="!selectedIns"> <div class="row" ng-hide="!selectedIns">
<p class="session_controls"> <p class="session_controls">
<div class="col-md-4"> <div class="col-md-4">
<a ng-click="startTimer(); new_ws()" ng-disabled="!selectedIns" ng-hide="sessionRunning" class="btn btn-success btn-sm" role="button" id="session_new" translate>new_session</a> <a ng-click="startTimer(); new_ws()" ng-disabled="!selectedIns " ng-hide="sessionRunning || studentData.num_peers<2" class="btn btn-success btn-sm" role="button" id="session_new" translate>new_session</a>
<a class="text_large" ng-click="pause_ws(); pauseTimer();" ng-hide="!sessionRunning || paused" id="session_pause" popover="{{ 'pause_session' | translate}}" popover-trigger="mouseenter"> <a class="text_large" ng-click="pause_ws(); pauseTimer();" ng-hide="!sessionRunning || paused" id="session_pause" popover="{{ 'pause_session' | translate}}" popover-trigger="mouseenter">
<span class="glyphicon glyphicon-pause" aria-hidden="true" title="{{ 'pause_session' | translate }}"></span> <span class="glyphicon glyphicon-pause" aria-hidden="true" title="{{ 'pause_session' | translate }}"></span>
</a> </a>
...@@ -115,12 +122,9 @@ ...@@ -115,12 +122,9 @@
<span class="glyphicon glyphicon-chevron-up" aria-hidden="true" popover="{{ 'next_sessions' | translate}}" popover-trigger="mouseenter"></span> <span class="glyphicon glyphicon-chevron-up" aria-hidden="true" popover="{{ 'next_sessions' | translate}}" popover-trigger="mouseenter"></span>
</a> </a>
</div> </div>
<div class="list-group">
<div class="list-group-item" ng-repeat="s in wsessions | orderBy: '-begin' | limitTo: numPerPage:(currentPage-1)*numPerPage"> <div ng-show="ws_recover" >
<div ng-show="showLastTry && wsessions.length > 0"> <table style="border: 1px solid #666666; padding:5px; background-color:#f5f5f5;" width="50%">
<h4><strong>{{ 'last_session' | translate}}</strong>: {{ studentData.current_method }}, {{ studentData.current_instruction }}</h4>
<div ng-show="ws_recover" >
<table style="border: 1px solid #666666; padding:5px; background-color:#f5f5f5;" width="100%">
<tr> <tr>
<td><h4 translate>warning_last_session_bad</h4></td> <td><h4 translate>warning_last_session_bad</h4></td>
<td> <td>
...@@ -128,7 +132,11 @@ ...@@ -128,7 +132,11 @@
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
<div class="list-group">
<div class="list-group-item" ng-repeat="s in wsessions | orderBy: '-begin' | limitTo: numPerPage:(currentPage-1)*numPerPage">
<div ng-show="showLastTry && wsessions.length > 0">
<h4><strong>{{ 'last_session' | translate}}</strong>: {{ studentData.current_method }}, {{ studentData.current_instruction }}</h4>
</div> </div>
<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">
{{ 'tries' | translate }} {{ 'tries' | translate }}
......
/** /**
* WebSocket Server Settings * WebSocket Server Settings
* (sails.config.sockets) * (sails.config.sockets)
...@@ -11,8 +12,8 @@ ...@@ -11,8 +12,8 @@
*/ */
module.exports.sockets = { module.exports.sockets = {
pingTimeout: 300000, // set timeout to 5 minutes pingTimeout: 20000, // set timeout to 20 secs
/*************************************************************************** /***************************************************************************
* * * *
...@@ -23,8 +24,7 @@ module.exports.sockets = { ...@@ -23,8 +24,7 @@ module.exports.sockets = {
* automatically. * * automatically. *
* * * *
***************************************************************************/ ***************************************************************************/
/*onConnect: function(session, socket) { /* onConnect: function(session, socket) {
}, },
*/ */
...@@ -34,11 +34,16 @@ module.exports.sockets = { ...@@ -34,11 +34,16 @@ module.exports.sockets = {
* disconnects * * disconnects *
* * * *
***************************************************************************/ ***************************************************************************/
/*onDisconnect: function(session, socket) { afterDisconnect: function (session, socket, cb) {
// By default: do nothing. var rooms=sails.hooks.rooms.getRoom(socket);
if (rooms)
for (var i = 0; i < rooms.length; i++) {
console.log("Unubscribed room in socket afterDisconnect: " + rooms[i]);
sails.hooks.rooms.unsubscribeFromRoom(rooms[i], socket);
}
}, },
*/
/*************************************************************************** /***************************************************************************
* * * *
......
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