Solving problems with sessions and timestamps

parent 77b7ae86
......@@ -43,7 +43,7 @@ public abstract class Action {
final String param_id_dev="id_dev";
final String param_timestamp="timestamp";
final Date currentTime = new Date();
SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss.SSSZ");
try {
JSONObject jsonObject = new JSONObject()
.put(param_id_stu, PCBcontext.getPcbdb().getCurrentUser().get_id_stu())
......
......@@ -196,7 +196,7 @@ END
CREATE TRIGGER trg_insert_users_detail
INSTEAD OF INSERT ON users_detail
FOR EACH ROW
WHEN NEW.pwd_stu NOT IS NULL
WHEN NEW.pwd_stu IS NOT NULL
BEGIN
INSERT OR REPLACE INTO student VALUES (NEW.id_stu, NEW.nickname_stu, NEW.pwd_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup);
......
......@@ -27,11 +27,11 @@ SET time_zone = "+00:00";
CREATE TABLE IF NOT EXISTS `action` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` varchar(20) COLLATE utf8_unicode_ci NOT NULL CHECK (type IN ('Add','Select','Delete','Show','Unshow','Pause','tryinit','tryend','initsession','endsession','pausesession','resumesession')),
`timestamp` timestamp DEFAULT CURRENT_TIMESTAMP,
`timestamp` timestamp(3) DEFAULT CURRENT_TIMESTAMP,
`id_sup` int(11) DEFAULT NULL,
`id_stu` int(11) NOT NULL,
`id_try` int(11) DEFAULT NULL,
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'serialization of properties of the picto at the time of the action',
`description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'serialization of properties of the picto at the time of the action',
`gps_lat` float DEFAULT NULL,
`gps_lon` float DEFAULT NULL,
PRIMARY KEY (`id`),
......@@ -42,7 +42,7 @@ CREATE TABLE IF NOT EXISTS `action` (
KEY `fk_stu_act` (`id_stu`),
KEY `id_try` (`id_try`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table registers and action performed by a user at a given time, all information of the action is in JSON format in the 'description' column and the operation performed is one of the possible for the 'type' column";
COMMENT="This table registers and action performed by a user at a given time, all information of the action is in JSON format in the 'description' column and the operation performed is one of the possible for the 'type' column. NOTE: timestamps must support fractional seconds, so MySQL versions >= 5.6.4 are required.";
-- --------------------------------------------------------
......@@ -70,10 +70,10 @@ COMMENT="Stores the expressions available in several languages for a given categ
CREATE TABLE IF NOT EXISTS `method` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
`id_stu` int(11) NOT NULL,
`registration` date DEFAULT NULL,
`notes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`notes` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_stu_met` (`id_stu`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
......@@ -91,8 +91,8 @@ CREATE TABLE IF NOT EXISTS `instruction` (
`name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`objective` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
`status` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL CHECK (status IN ('started','finished')),
`begin` timestamp NULL,
`end` timestamp NULL,
`begin` timestamp(3) NULL,
`end` timestamp(3) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="An instruction is a 'phase' in a method for learning AAC";
......@@ -122,7 +122,7 @@ COMMENT="One in a set of instructions predefined or stored by users. They are re
CREATE TABLE IF NOT EXISTS `meta_method` (
`id` tinyint(4) NOT NULL AUTO_INCREMENT,
`name` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
`id_sup` INT( 11 ) DEFAULT NULL,
UNIQUE(name,id_sup),
PRIMARY KEY (`id`)
......@@ -195,7 +195,7 @@ CREATE TABLE IF NOT EXISTS `picto_acl` (
`id_sup` int(11) NOT NULL DEFAULT '0',
`id_pic` int(11) NOT NULL DEFAULT '0',
`privilege` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
`timestamp` datetime,
`timestamp` timestamp(3),
PRIMARY KEY (`id`),
KEY `k_pic_aclp` (`id_pic`),
KEY `k_sup_aclp` (`id_sup`)
......@@ -264,7 +264,7 @@ COMMENT="Labels assigned to pictos by default or by supervisors";
CREATE TABLE IF NOT EXISTS `source` (
`id` tinyint(4) NOT NULL AUTO_INCREMENT,
`name` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2
COMMENT="Contains all possible sources of pictos";
......@@ -285,9 +285,9 @@ CREATE TABLE IF NOT EXISTS `student` (
`gender` char(1) COLLATE utf8_unicode_ci NOT NULL,
`country` char(2) COLLATE utf8_unicode_ci NOT NULL,
`pic` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'defaultAvatar.jpg',
`notes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`notes` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
`lang` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
`attributes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Attributes describing student along with his/her configuration',
`attributes` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Attributes describing student along with his/her configuration',
`id_off` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
......@@ -366,10 +366,10 @@ COMMENT="Supervisors information";
CREATE TABLE IF NOT EXISTS `try` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_ws` int(11) NOT NULL,
`begin` timestamp DEFAULT CURRENT_TIMESTAMP,
`end` timestamp NULL,
`begin` timestamp(3) DEFAULT CURRENT_TIMESTAMP,
`end` timestamp(3) NULL,
`result` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id_ws` (`id_ws`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
......@@ -388,10 +388,10 @@ CREATE TABLE IF NOT EXISTS `working_session` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_sup` int(11) NOT NULL,
`id_ins` int(11) NOT NULL,
`begin` timestamp DEFAULT CURRENT_TIMESTAMP,
`end` timestamp NULL,
`begin` timestamp(3) DEFAULT CURRENT_TIMESTAMP,
`end` timestamp(3) NULL,
`current` boolean NULL DEFAULT 1,
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id_sup` (`id_sup`),
KEY `id_ins` (`id_ins`),
......
......@@ -142,9 +142,9 @@ thisTrigger: BEGIN
LEAVE thisTrigger;
END IF;
IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN
CALL deleteOpenTry(new.id);
END IF;
IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN
CALL deleteOpenTry(new.id);
END IF;
END;;
......
......@@ -42,7 +42,7 @@ module.exports = {
if (!params.type) return res.json(500, {error: "No type of action defined"});
// Optional params
var timestamp = null; if(params.timestamp) timestamp = params.timestamp;
var timestamp = null; if(params.timestamp) timestamp = params.timestamp.toISOString();
var sup = null; if(params.supervisor) sup = params.supervisor;
var _try = null; if(params._try) _try = params._try;
var description = null; if(params.description) description = params.description;
......@@ -59,18 +59,20 @@ module.exports = {
"description": description,
"gpsLat": gpsLat,
"gpsLon": gpsLon
}).exec(function(err, created){
if(err || !created) return res.json(500, { error: "Error saving an action "+ params.type +": " + err });
if(created) {
StuOpenTry.findOne({id_stu : params.student}).exec(function(err, data){
if(err || !data){
sails.log.error("Error finding try for student "+ params.student + ' when creating action '+ params.type);
return res.json(500, {error: 'Action '+ params.type +' not created'});
}
sails.log.debug("Try for student "+params.student+ ":"+JSON.stringify(data));
return res.json(200,{open_try: data.openTry });
})
}
})
.then(function(created){
if (!created)
throw new Error("Action.create returned NULL");
StuOpenTry.findOne({id_stu : params.student})
.then(function(data){
if(!data)
throw new Error("Error finding try for student "+ params.student + ' when creating action '+ params.type);
return res.ok({open_try: data.openTry });
})
})
.fail(function(err) {
res.serverError("Error saving an action "+ params.type +": " + err);
});
},
......@@ -100,7 +102,7 @@ module.exports = {
Action.create({
type: a.action,
timestamp: a.attributes.timestamp,
timestamp: a.attributes.timestamp.toISOString(),
supervisor: sup,
student: params.student,
description: desc
......
......@@ -271,7 +271,8 @@ module.exports = {
* {
* id: pictoId,
* source: 1,
* owner: supervisorId
* owner: supervisorId,
* uri: 'https://path/to/picto/in/the/web'
* }
*/
upload: function (req, res) {
......
......@@ -83,17 +83,17 @@ module.exports = {
res.serverError();
});
} else {
res.badRequest('Invalid user or password');
res.badRequest('Invalid password');
}
} else {
res.badRequest('Invalid user or password');
res.badRequest('Invalid user');
}
})
.catch(function () {
res.badRequest('Invalid user or password');
});
} else {
res.badRequest('Invalid user or password');
res.badRequest('No email or or password');
}
},
......
......@@ -7,13 +7,17 @@
module.exports = {
//
//close action
// close a WS
//
/**
* Closes a working session
* @param req
* {
* id_ws: <working session ID>,
* }
*/
close: function(req, res) {
if (!req.params.id_ws) return res.json(500, {error: "No working session defined"});
if (!req.params.id_ws)
res.badRequest("No working session defined");
StuOpenTry.findOne( { id_ws : req.params.id_ws } ).exec(function(err, t) {
if (err) {
......@@ -36,119 +40,195 @@ module.exports = {
return res.json(200, {result:'no recovery required'});
});
},
},
// create action
// adds a working session and a InitSession action
//
// @TODO 357
/**
* Creates a new working session
* @param {request} req
* {
id_sup: <supervisor ID>
id_stu: <student ID>
id_ins: <instruction ID>
* }
* @param {response} res
* {
* // TODO: specify return values
* }
*/
create: function(req, res) {
var params = req.allParams();
if (!params.id_sup) return res.json(500, {error: "No supervisor defined"});
if (!params.id_ins) return res.json(500, {error: "No instruction defined"});
if (!params.id_stu) return res.json(500, {error: "No student defined"});
if (!params.desc) params.desc = "";
console.log(JSON.stringify(params));
var data = {};
data.supervisor = params.id_sup;
data.instruction = params.id_ins;
data.description = params.desc;
if (!params.id_sup) return res.badRequest("No supervisor defined");
if (!params.id_ins) return res.badRequest("No instruction defined");
if (!params.id_stu) return res.badRequest("No student defined");
if (!params.desc) params.desc = "";
var data = {};
data.supervisor = params.id_sup;
data.instruction = params.id_ins;
data.description = params.desc;
StuOpenTry.findOne( {or: [
StuOpenTry.findOne({or: [ // pending open try?
{ id_sup : params.id_sup },
{ id_stu : params.id_stu }
]} ).exec(function(err, t) {
if (err) {
sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err});
}
if(!t || t.openTry==null) //WS closed correctly
WorkingSession.create(data).exec(function(err, ws){
if(err || !ws){
sails.log.error("Creating new Working Sesion error "+err);
return res.json(500, {error: 'Working Session not created'});
}
// Create the InitSession Action
Action.create({
"type": "initsession",
"timestamp": ws.begin,
"supervisor": ws.supervisor,
"student": params.id_stu
}).exec(function(err, action){
if(err || !action) {
sails.log.error("Creating initial action for new Working Sesion. Error "+err);
return res.json(500, {error: 'Working Session not created'});
}
StuOpenTry.findOne( {id_stu : params.id_stu } ).exec(function(err, t) {
if (err) {
sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err});
}
// Return the working session and try created
sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(ws)+". Action:"+JSON.stringify(action));
return res.json({
"id": ws.id,
"first_try_id":t.openTry,
"recovered_ws": null
})
})
});
});
else { //Not closed previous WS must be recovered and closed
sails.log.debug("Recovering WS required for student "+params.id_stu);
var ws_end;
if (t.end==null) ws_end = t.begin;
else ws_end = t.end;
WorkingSession.update({id: t.id_ws}, {end: ws_end.toISOString()}).exec(function(err,u) {
if (err) {
sails.log.error("Error updating no closed WS " + t.id_ws);
return res.json(500, {error: 'Working Session not created'});
}
WorkingSession.create(data).exec(function(err, ws){
if(err || !ws){
sails.log.error("Creating new Working Sesion error "+err);
return res.json(500, {error: 'Working Session not created'});
}
// Create the InitSession Action
Action.create({
"type": "initsession",
"timestamp": ws.begin,
"supervisor": ws.supervisor,
"student": params.id_stu
}).exec(function(err, action){
if(err || !action) {
sails.log.error("Creating initial action for new Working Sesion. Error "+err);
return res.json(500, {error: 'Working Session not created'});
}
StuOpenTry.findOne( {id_stu : params.id_stu} ).exec(function(err, t) {
if (err) {
sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err});
}
// Return the working session and try created
sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(action));
return res.json({
"id": ws.id,
"first_try_id":t.openTry,
"recovered_ws": null
})
})
});
});
});
]})
.then(function(t) {
var ws = null;
if (t && t.openTry) { // YES, so WS not closed, we update to close it
var ws_end = t.end ? t.end : t.begin;
ws = WorkingSession.update({id: t.id_ws}, {end: ws_end.toISOString()})
.then(function(ws) {
return ws;
});
}
return ws;
})
.then(function(oldws) { // now we can create new working session
return WorkingSession.create(data)
.then(function(ws) {
return ws;
});
})
.then(function(ws) { // now we have a new working session
if (!ws)
throw new Error("Error when calling WorkingSession.create");
// Create the InitSession Action
// This creates, also, a new try (see triggers-session-constraints.sql)
var action = Action.create({
"type": "initsession",
"timestamp": ws.begin.toISOString(),
"supervisor": ws.supervisor,
"student": params.id_stu
})
.then(function(action) {
if(!action)
throw new Error("Error when creating action 'initsession'");
return action;
});
return [action, ws];
}).spread(function(action, ws) {
StuOpenTry.findOne({id_stu : params.id_stu })
.then(function(opentry) {
if (!opentry)
throw new Error("Error when looking for open try");
// Return the working session and try created
sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(ws)+". Action:"+JSON.stringify(action));
return res.ok({
"id": ws.id,
"first_try_id":opentry.id,
"recovered_ws": null
});
});
})
.fail(function(err) {
res.serverError("Session not created: " + err);
});
// ---
//
// StuOpenTry.findOne( {or: [
// { id_sup : params.id_sup },
// { id_stu : params.id_stu }
// ]} ).exec(function(err, t) {
// if (err)
// res.serverError("Recovering from ws: "+err);
//
// if(t || t.openTry==null) { //WS closed correctly
// sails.log.debug("No open try, let's create session");
//
// WorkingSession.create(data).exec(function(err, ws){
// if(err || !ws)
// return res.serverError("Creating new Working Sesion error "+err);
//
// // Create the InitSession Action
// // This creates, also, a new try (see triggers-session-constraints.sql)
// Action.create({
// "type": "initsession",
// "timestamp": ws.begin,
// "supervisor": ws.supervisor,
// "student": params.id_stu
// }).exec(function(err, action){
// if(err || !action)
// res.serverError("Creating initial action for new Working Sesion. Error "+err);
//
// StuOpenTry.findOne( {id_stu : params.id_stu } ).exec(function(err, t) {
// if (err)
// res.serverError('Could not open try for new session: '+err);
//
// // Return the working session and try created
// sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(ws)+". Action:"+JSON.stringify(action));
// res.ok({
// "id": ws.id,
// "first_try_id":t.openTry,
// "recovered_ws": null
// })
// })
// });
// });
// }
// else { //Not closed previous WS must be recovered and closed
// sails.log.debug("Open try found, recovering WS for student "+params.id_stu);
//
// var ws_end;
// if (t.end==null)
// ws_end = t.begin;
// else
// ws_end = t.end;
// WorkingSession.update({id: t.id_ws}, {end: ws_end.toISOString()}).exec(function(err,u) {
// if (err)
// res.serverError("Error updating non closed WS " + t.id_ws);
//
// WorkingSession.create(data).exec(function(err, ws){
// if(err || !ws)
// res.serverError("Creating new Working Sesion error "+err);
//
// // Create the InitSession Action
// Action.create({
// "type": "initsession",
// "timestamp": ws.begin,
// "supervisor": ws.supervisor,
// "student": params.id_stu
// }).exec(function(err, action){
// if(err || !action)
// res.serverError("Creating initial action for new Working Sesion. Error " + err);
//
// StuOpenTry.findOne( {id_stu : params.id_stu} ).exec(function(err, t) {
// if (err)
// res.serverError("Error Recovering from ws "+err);
//
// // Return the working session and try created
// res.ok({
// "id": ws.id,
// "first_try_id":t.openTry,
// "recovered_ws": null
// })
// })
// });
// });
// });
// }
// });
},
// update action
// ends a working session and a creates an EndSession action
//
// @TODO 357
/**
* Updates working session information and a creates an EndSession action if
* update info is to end session
* @param {request} req
* {
* // TODO: specify parameters
* }
* @param {response} res
* {
* // TODO: specify return values
* }
*/
update: function(req, res) {
var params = req.allParams();
console.log(JSON.stringify(params));
WorkingSession.update({id:params.id}, params).exec(function(err, ws){
if(err || !ws){
......@@ -162,7 +242,7 @@ module.exports = {
// Create the EndSession Action
Action.create({
"type": "endsession",
"timestamp": ws[0].end,
"timestamp": ws[0].end.toISOString(),
"supervisor": ws[0].supervisor,
"student": params.id_stu
}).exec(function(err, action){
......
......@@ -30,7 +30,7 @@ module.exports = {
columnName: "id_ins",
required: true,
type: "integer",
model: "Instruction"
model: "Instruction"
},
begin: {
type: "datetime",
......@@ -40,21 +40,50 @@ module.exports = {
type: "datetime"
},
current: {
type: "integer",
},
type: "integer",
},
description: {
type: "string",
size: 1024
},
// Relación con Try. [1 WorkingSession to N Try]
// Relación con Try. [1 WorkingSession to N Try]
tries: {
collection: 'Try',
via: "workingSession"
}
},
/**
* Checks a previous session is not opened for that supervisor. If so,
* session is closed (current is set to 0)
* @param {Object} attrs All session properties to be stored
* @param {Function} next Function to be executed when the check process
* has been completed (an error object will be passed
* to the function if necesary)
*/
beforeCreate: function (attrs, next) {
WorkingSession.find({id_sup: attrs.supervisor, current: 1})
.then(function(wss) {
if (wss) {
async.each(wss, function(ws, cb) {
ws.current = 0;
WorkingSession.update(ws.id, ws, function(err, update) {
if (err) throw new Error("Error when udpating open sessions");
cb();
});
});
}
next();
})
.fail(function(err) {
next(err);
})
},
//
// Returns the number of working sessions per year (REPORTS)
//
//
per_year: function(id_stu, year, callback) {
var l = [];
......@@ -65,18 +94,18 @@ module.exports = {
// eachSeries
async.eachSeries(
// 1st array of items
months,
months,
// 2nd function to operate over one item
function(month, next) {
var month_1 = year +'-'+ month +'-01'; // 2015-1-01
var month_2 = (month<12) ? (year +'-'+ (month+1) +'-01') : ((year+1) +'-01-01'); // 2015-2-01 ó 2016-01-01
WorkingSession.count({
'id_stu' : id_stu,
'begin' : {
'>=' : month_1,
'<' : month_2
WorkingSession.count({
'id_stu' : id_stu,
'begin' : {
'>=' : month_1,
'<' : month_2
}
}).exec(function(err, ws) {
if (err)
......@@ -84,7 +113,7 @@ module.exports = {
if(!ws)
console.log("No ws in this month");
if(ws)
console.log(JSON.stringify(ws));
......@@ -99,7 +128,7 @@ module.exports = {
},
// 3rd final function when all is ready
function (err){
function (err){
console.log("It's the final functiooonnnnnnnn.....");
console.log(JSON.stringify(l));
return callback(err, l);
......@@ -111,7 +140,7 @@ module.exports = {
//
// Returns the number of working sessions per month (REPORTS)
//
//
per_month: function(id_stu, month, callback) {
var l = [];
......@@ -122,18 +151,18 @@ module.exports = {
// eachSeries
async.eachSeries(
// 1st array of items
months,
months,
// 2nd function to operate over one item
function(month, next) {
var month_1 = year + '-'+ month +'-01'; // 2015-1-01
var month_2 = (month<12) ? (year +'-'+ (month+1) +'-01') : ((year+1) +'-01-01'); // 2015-2-01 ó 2016-01-01
WorkingSession.count({
'id_stu' : id_stu,
'begin' : {
'>=' : month_1,
'<' : month_2
WorkingSession.count({
'id_stu' : id_stu,
'begin' : {
'>=' : month_1,
'<' : month_2
}
}).exec(function(err, ws) {
if (err)
......@@ -141,7 +170,7 @@ module.exports = {
if(!ws)
console.log("No ws in this month");
if(ws)
console.log(JSON.stringify(ws));
......@@ -154,7 +183,7 @@ module.exports = {
},
// 3rd final function when all is ready
function (err){
function (err){
console.log("It's the final functiooonnnnnnnn.....");
console.log(JSON.stringify(l));
return callback(err, l);
......
......@@ -80,6 +80,7 @@
"enlarge": "Enlarge",
"enormous": "Enormous",
"error_adding_picto": "Error adding picto",
"error_creating_session": "Error when creating session",
"error_deleting_picto": "Error deleting picto",
"error_downloading_supervisors": "Error downloading supervisors",
"error_downloading_offices": "Error downloading offices",
......
......@@ -83,6 +83,7 @@
"expand_navigation": "Desplegar navegación",
"expression": "Expresión:",
"error_adding_picto": "Error al añadir el picto",
"error_creating_session": "Error al crear sesión",
"error_deleting_picto": "Error borrando el picto",
"error_downloading_supervisors": "Error al descargar los supervisores",
"error_downloading_offices": "Error al descargar las oficinas",
......
......@@ -3,7 +3,14 @@
//-----------------------
// Student Session Controller
//-----------------------
dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtrl($scope, $stateParams, $http, config, $window) {
dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtrl(
$scope,
$stateParams,
$http,
config,
$window,
$translate,
ngToast) {
......@@ -206,7 +213,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/ws', {
"id_sup": $scope.user.id,
"id_stu": $scope.studentData.id,
"id_ins": $scope.selectedIns
"id_ins": $scope.selectedIns.id
})
.success(function(data, status, headers, config) {
......@@ -229,7 +236,9 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.studentData.current_instruction=$scope.selectedIns.name;
})
.error(function(data, status, headers, config) {
$translate('error_creating_session').then(function (translation) {
ngToast.danger({ content: translation });
});
});
};
......@@ -237,12 +246,10 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// update the description of a given working session
//
$scope.update_ws = function (ws){
$http
.put(config.backend+'/ws/' + ws.id, { "description" : ws.description })
.then(function(data, status, headers, config) {
// TODO notify update?
})
,function(data, status, headers, config) {
......@@ -260,8 +267,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$http
.put(config.backend+'/ws/' + $scope.ws.id, { "end": $scope.ws.end,
"id_stu": $scope.studentData.id
})
"id_stu": $scope.studentData.id
})
.success(function(data, status, headers, config) {
// Empty actual WS and actual try
......@@ -376,26 +383,22 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// what data has updated, and refresh what needs to be refreshed.
if($scope.ws){
console.log(data.action);
switch(data.action){
case 'Add':
$scope.actual_try.actions.push(data);
break;
case 'Delete':
$scope.actual_try.actions.push(data);
break;
case 'Select':
$scope.actual_try.actions.push(data);
break;
case 'Show':
$scope.load_tries($scope.selectedIns);
$scope.load_tries($scope.selectedIns);
// Empty actual try and push the first action of next try
$scope.actual_try.actions = [];
$scope.actual_try.actions.push({ action: 'tryinit' });
break;
}
}
......
......@@ -44,10 +44,10 @@
<img ng-src="{{ a.attributes.picto.picto.uri }}" />
<div class="action-type">
<span ng-if="a.action == 'add'" class="glyphicon glyphicon-plus color_green" aria-hidden="true"></span>
<span ng-if="a.action == 'select'" class="glyphicon glyphicon-hand-up color_blue" aria-hidden="true"></span>
<span ng-if="a.action == 'delete'" class="glyphicon glyphicon-remove color_red" aria-hidden="true"></span>
<span ng-if="a.action == 'show'" class="glyphicon glyphicon-eye-open color_blue" aria-hidden="true"></span>
<span ng-if="a.action == 'unshow'" class="glyphicon glyphicon-edit color_blue" aria-hidden="true"></span>
<span ng-if="a.action == 'Select'" class="glyphicon glyphicon-hand-up color_blue" aria-hidden="true"></span>
<span ng-if="a.action == 'Delete'" class="glyphicon glyphicon-remove color_red" aria-hidden="true"></span>
<span ng-if="a.action == 'Show'" class="glyphicon glyphicon-eye-open color_blue" aria-hidden="true"></span>
<span ng-if="a.action == 'Unshow'" class="glyphicon glyphicon-edit color_blue" aria-hidden="true"></span>
<span ng-if="a.action == 'tryinit'" class="glyphicon glyphicon-log-in" aria-hidden="true"></span>
<span ng-if="a.action == 'tryend'" class="glyphicon glyphicon-log-out" aria-hidden="true"></span>
<span ng-if="a.action == 'pausesession'" class="glyphicon glyphicon-pause" aria-hidden="true"></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