pictos no mostrados en sesión, corregido

parent b791bd7d
......@@ -47,6 +47,9 @@ android {
LocalFlavor {
resValue "string", "server", "https://192.168.1.37:1337"
}
DevFlavor {
resValue "string", "server", "https://dev.yottacode.com"
}
DefaultFlavor {
resValue "string", "server", "https://pre.yottacode.com"
signingConfig signingConfigs.release_config
......
......@@ -1015,15 +1015,17 @@ module.exports = {
sails.log.debug("Inside action. Student:" + attributes.id_stu);
if (req.isSocket) {
sails.log.debug("websockets - room " + roomName);
sails.log.debug("websockets - room " + sails.hooks.rooms.student(attributes.id_stu));
// BROADCAST to everyone subscribed to this student
const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcast(
sails.hooks.events.broadcastEvent(
sails.hooks.rooms.student(attributes.id_stu),
'action',
{
"action": action,
"attributes": attributes
name: 'action',
data: {
"action": action,
"attributes": attributes
}
},
socketToOmit
);
......@@ -1043,8 +1045,10 @@ module.exports = {
description: desc
})
.exec(function (err, created) {
if (err)
if (err) {
sails.log.error(err.details);
res.serverError(err.details);
}
else if (created)
res.json({
action: created
......@@ -1056,6 +1060,8 @@ module.exports = {
msg: "Action "+ action +" action from student " + attributes.id_stu
});
*/
} else {
sails.log.debug("No socket request for action");
}
},
......@@ -1070,7 +1076,7 @@ module.exports = {
if (req.isSocket) {
const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcast(
sails.hooks.events.broadcastEvent(
sails.hooks.rooms.student(attributes.id_stu),
'action',
{
......
// @TODO 357
module.exports = {
// create action
// adds a try
//
create: function(req, res) {
var params = req.allParams();
if (!params.ws) return res.json(500, {error: "No workingSession defined"});
if (!params.begin) return res.json(500, {error: "No begin defined"});
if (!params.end) return res.json(500, {error: "No end defined"});
if (!params.actions) return res.json(500, {error: "No actions in try defined"});
if (!params.supervisor) return res.json(500, {error: "No supervisor in try defined"});
if (!params.student) return res.json(500, {error: "No student in try defined"});
Try.create({
"workingSession":params.ws,
"begin": params.begin,
"end": params.end
}).exec(function(err, tr){
if(err || !tr){
sails.log.debug("Creating new Try: " + err);
return res.json(500, {error: 'Try not created'});
}
if(tr){
var l_actions = [];
// with .eachSeries the order of resulting array will be equal
// to the original array
async.eachSeries(params.actions, function(a, callback) {
sails.log.debug("Loop adding actions: " + a.action + " to try " + tr.id);
var desc = null;
if(a.attributes.picto) desc = a.attributes.picto; // select, add and delete actions data
if(a.attributes.pictos) desc = a.attributes.pictos; // show action data
Action.create({
type: a.action,
timestamp: a.attributes.timestamp,
supervisor: params.supervisor,
student: params.student,
description: desc,
_try: tr.id
}).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new "+ a.action +" action: " + err);
if(action){
sails.log.debug("Action Created: " + action.type);
l_actions.push(action);
}
callback();
});
// Finish function when each callback is done
// Optionaly it can be passed and err parameter
}, function(err){
if( err ) {
// One of the iterations produced an error.
// All processing will now stop.
console.log('An error ocurred with an action');
} else {
console.log('All actions have been processed successfully');
// Return the try
// with the array of actions
return res.json({
"id": tr.id,
"workingSession": tr.workingSession,
"begin": tr.begin,
"end": tr.end,
"actions": l_actions
});
}
});
/*
// InitSession Action
Action.create({
"type": "InitSession",
"timestamp": ws.begin,
"supervisor": ws.supervisor,
"student": ws.student,
}).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action InitSession: " + err);
if(action) sails.log.debug("Created Action: " + action.type);
});
// TryInit Action
Action.create({
"type": "TryInit",
"timestamp": ws.begin,
"supervisor": ws.supervisor,
"student": ws.student,
"_try": tr.id
}).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action TryInit: " + err);
if(action){
sails.log.debug("Created Action: " + action.type);
// Return the working session created
// with the array of one try (the first)
// with the array of one action (the first too)
return res.json({
"id": ws.id,
"begin": ws.begin,
"student": ws.student,
"supervisor": ws.supervisor,
"tries": [
{
"id": tr.id,
"instruction": tr.instruction,
"begin": tr.begin,
"workingSession": tr.workingSession,
"actions": [ action ]
}
]
});
}
});
*/
}
});
}
// create action
// adds a try
//
create: function(req, res) {
var params = req.allParams();
if (!params.ws) return res.json(500, {error: "No workingSession defined"});
if (!params.begin) return res.json(500, {error: "No begin defined"});
if (!params.end) return res.json(500, {error: "No end defined"});
if (!params.actions) return res.json(500, {error: "No actions in try defined"});
if (!params.supervisor) return res.json(500, {error: "No supervisor in try defined"});
if (!params.student) return res.json(500, {error: "No student in try defined"});
Try.create({
"workingSession":params.ws,
"begin": params.begin,
"end": params.end
}).exec(function(err, tr){
if(err || !tr){
sails.log.debug("Creating new Try: " + err);
return res.json(500, {error: 'Try not created'});
}
if(tr){
var l_actions = [];
// with .eachSeries the order of resulting array will be equal
// to the original array
async.eachSeries(params.actions, function(a, callback) {
sails.log.debug("Loop adding actions: " + a.action + " to try " + tr.id);
var desc = null;
if(a.attributes.picto) desc = a.attributes.picto; // select, add and delete actions data
if(a.attributes.pictos) desc = a.attributes.pictos; // show action data
Action.create({
type: a.action,
timestamp: a.attributes.timestamp,
supervisor: params.supervisor,
student: params.student,
description: desc,
_try: tr.id
}).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new "+ a.action +" action: " + err);
if(action){
sails.log.debug("Action Created: " + action.type);
l_actions.push(action);
}
callback();
});
// Finish function when each callback is done
// Optionaly it can be passed and err parameter
}, function(err){
if( err ) {
// One of the iterations produced an error.
// All processing will now stop.
console.log('An error ocurred with an action');
} else {
console.log('All actions have been processed successfully');
// Return the try
// with the array of actions
return res.json({
"id": tr.id,
"workingSession": tr.workingSession,
"begin": tr.begin,
"end": tr.end,
"actions": l_actions
});
}
});
/*
// InitSession Action
Action.create({
"type": "InitSession",
"timestamp": ws.begin,
"supervisor": ws.supervisor,
"student": ws.student,
}).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action InitSession: " + err);
if(action) sails.log.debug("Created Action: " + action.type);
});
// TryInit Action
Action.create({
"type": "TryInit",
"timestamp": ws.begin,
"supervisor": ws.supervisor,
"student": ws.student,
"_try": tr.id
}).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action TryInit: " + err);
if(action){
sails.log.debug("Created Action: " + action.type);
// Return the working session created
// with the array of one try (the first)
// with the array of one action (the first too)
return res.json({
"id": ws.id,
"begin": ws.begin,
"student": ws.student,
"supervisor": ws.supervisor,
"tries": [
{
"id": tr.id,
"instruction": tr.instruction,
"begin": tr.begin,
"workingSession": tr.workingSession,
"actions": [ action ]
}
]
});
}
});
*/
}
});
}
};
......@@ -7,246 +7,246 @@
module.exports = {
//
//close action
// close a WS
//
close: function(req, res) {
if (!req.params.id_ws) return res.json(500, {error: "No working session defined"});
StuOpenTry.findOne( { id_ws : req.params.id_ws } ).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 recovery*/ {
sails.log.debug("Recovering WS required for WS "+req.params.id_ws);
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 could not be closed'});
}});
return res.json(200, {end: ws_end.toISOString()});
}
else
return res.json(200, {result:'no recovery required'});
});
},
// create action
// adds a working session and a InitSession action
//
// @TODO 357
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 = "";
var data = {};
data.supervisor = params.id_sup;
data.instruction = params.id_ins;
//
//close action
// close a WS
//
close: function(req, res) {
if (!req.params.id_ws) return res.json(500, {error: "No working session defined"});
StuOpenTry.findOne( { id_ws : req.params.id_ws } ).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 recovery*/ {
sails.log.debug("Recovering WS required for WS "+req.params.id_ws);
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 could not be closed'});
}});
return res.json(200, {end: ws_end.toISOString()});
}
else
return res.json(200, {result:'no recovery required'});
});
},
// create action
// adds a working session and a InitSession action
//
// @TODO 357
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 = "";
var data = {};
data.supervisor = params.id_sup;
data.instruction = params.id_ins;
data.description = params.desc;
StuOpenTry.findOne( {or: [
{ 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
})
})
});
});
});
}
});
},
// update action
// ends a working session and a creates an EndSession action
//
// @TODO 357
update: function(req, res) {
var params = req.allParams();
WorkingSession.update({id:params.id}, params).exec(function(err, ws){
if(err || !ws){
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){ //Closing WS
// Create the EndSession Action
Action.create({
"type": "endsession",
"timestamp": ws[0].end,
"supervisor": ws[0].supervisor,
"student": params.id_stu
}).exec(function(err, action){
if(err || !action) {
sails.log.debug("Error creating new Action EndSession: " + err);
return res.json(500, {error: 'Working Session not updated'});
}
});
// Implementation of Integrity rule #8 for sessions management
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)'});
}});
}
});
}
// Return the working session updated
return res.json(ws);
});
},
//
// Returns the number of working sessions per year (REPORTS)
//
per_year: function(req, res) {
if (!req.params.id_stu)
return res.json(500, {error: "No student defined"});
if (!req.params.year)
return res.json(500, {error: "No year defined"});
WorkingSession.per_year(req.params.id_stu, req.params.year, function(err, l_ws) {
if (err) throw err;
return res.json(l_ws);
});
},
//
// Returns the number of working sessions per month (REPORTS)
//
per_month: function(req, res) {
if (!req.params.id_stu)
return res.json(500, {error: "No student defined"});
if (!req.params.month)
return res.json(500, {error: "No month defined"});
WorkingSession.per_month(req.params.id_stu, req.params.month, function(err, l_ws) {
if (err) throw err;
return res.json(l_ws);
});
},
//
// Returns all tries for the given instruction
//
// @TODO 357
tries: function(req, res) {
if (!req.params.id_ws) {
return res.json(500, {error: "No working session defined"});
}
Try.find({
WorkingSession: req.params.id_ws, // With this working session id
or : [
{ result: null }, // This is necessary here because it's not enough with the following query to recover null results
{ result: { '!' : ['BROKEN', 'DISCARDED'] }} // And without this results
]
}).populate('actions').exec(function(err, tries) {
if (err) throw err;
if(!tries || tries.length == 0) return res.json([]); // Empty array of tries
else return res.json(tries);
});
},
StuOpenTry.findOne( {or: [
{ 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
})
})
});
});
});
}
});
},
// update action
// ends a working session and a creates an EndSession action
//
// @TODO 357
update: function(req, res) {
var params = req.allParams();
WorkingSession.update({id:params.id}, params).exec(function(err, ws){
if(err || !ws){
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){ //Closing WS
// Create the EndSession Action
Action.create({
"type": "endsession",
"timestamp": ws[0].end,
"supervisor": ws[0].supervisor,
"student": params.id_stu
}).exec(function(err, action){
if(err || !action) {
sails.log.debug("Error creating new Action EndSession: " + err);
return res.json(500, {error: 'Working Session not updated'});
}
});
// Implementation of Integrity rule #8 for sessions management
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)'});
}});
}
});
}
// Return the working session updated
return res.json(ws);
});
},
//
// Returns the number of working sessions per year (REPORTS)
//
per_year: function(req, res) {
if (!req.params.id_stu)
return res.json(500, {error: "No student defined"});
if (!req.params.year)
return res.json(500, {error: "No year defined"});
WorkingSession.per_year(req.params.id_stu, req.params.year, function(err, l_ws) {
if (err) throw err;
return res.json(l_ws);
});
},
//
// Returns the number of working sessions per month (REPORTS)
//
per_month: function(req, res) {
if (!req.params.id_stu)
return res.json(500, {error: "No student defined"});
if (!req.params.month)
return res.json(500, {error: "No month defined"});
WorkingSession.per_month(req.params.id_stu, req.params.month, function(err, l_ws) {
if (err) throw err;
return res.json(l_ws);
});
},
//
// Returns all tries for the given instruction
//
// @TODO 357
tries: function(req, res) {
if (!req.params.id_ws) {
return res.json(500, {error: "No working session defined"});
}
Try.find({
WorkingSession: req.params.id_ws, // With this working session id
or : [
{ result: null }, // This is necessary here because it's not enough with the following query to recover null results
{ result: { '!' : ['BROKEN', 'DISCARDED'] }} // And without this results
]
}).populate('actions').exec(function(err, tries) {
if (err) throw err;
if(!tries || tries.length == 0) return res.json([]); // Empty array of tries
else return res.json(tries);
});
},
};
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