pictos no mostrados en sesión, corregido

parent b791bd7d
...@@ -47,6 +47,9 @@ android { ...@@ -47,6 +47,9 @@ android {
LocalFlavor { LocalFlavor {
resValue "string", "server", "https://192.168.1.37:1337" resValue "string", "server", "https://192.168.1.37:1337"
} }
DevFlavor {
resValue "string", "server", "https://dev.yottacode.com"
}
DefaultFlavor { DefaultFlavor {
resValue "string", "server", "https://pre.yottacode.com" resValue "string", "server", "https://pre.yottacode.com"
signingConfig signingConfigs.release_config signingConfig signingConfigs.release_config
......
...@@ -1015,15 +1015,17 @@ module.exports = { ...@@ -1015,15 +1015,17 @@ module.exports = {
sails.log.debug("Inside action. Student:" + attributes.id_stu); 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 " + sails.hooks.rooms.student(attributes.id_stu));
// BROADCAST to everyone subscribed to this student // BROADCAST to everyone subscribed to this student
const socketToOmit = (req.isSocket) ? req.socket : undefined; const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcast( sails.hooks.events.broadcastEvent(
sails.hooks.rooms.student(attributes.id_stu), sails.hooks.rooms.student(attributes.id_stu),
'action',
{ {
"action": action, name: 'action',
"attributes": attributes data: {
"action": action,
"attributes": attributes
}
}, },
socketToOmit socketToOmit
); );
...@@ -1043,8 +1045,10 @@ module.exports = { ...@@ -1043,8 +1045,10 @@ module.exports = {
description: desc description: desc
}) })
.exec(function (err, created) { .exec(function (err, created) {
if (err) if (err) {
sails.log.error(err.details);
res.serverError(err.details); res.serverError(err.details);
}
else if (created) else if (created)
res.json({ res.json({
action: created action: created
...@@ -1056,6 +1060,8 @@ module.exports = { ...@@ -1056,6 +1060,8 @@ module.exports = {
msg: "Action "+ action +" action from student " + attributes.id_stu msg: "Action "+ action +" action from student " + attributes.id_stu
}); });
*/ */
} else {
sails.log.debug("No socket request for action");
} }
}, },
...@@ -1070,7 +1076,7 @@ module.exports = { ...@@ -1070,7 +1076,7 @@ module.exports = {
if (req.isSocket) { if (req.isSocket) {
const socketToOmit = (req.isSocket) ? req.socket : undefined; const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcast( sails.hooks.events.broadcastEvent(
sails.hooks.rooms.student(attributes.id_stu), sails.hooks.rooms.student(attributes.id_stu),
'action', 'action',
{ {
......
// @TODO 357 // @TODO 357
module.exports = { module.exports = {
// create action // create action
// adds a try // adds a try
// //
create: function(req, res) { create: function(req, res) {
var params = req.allParams(); var params = req.allParams();
if (!params.ws) return res.json(500, {error: "No workingSession defined"}); if (!params.ws) return res.json(500, {error: "No workingSession defined"});
if (!params.begin) return res.json(500, {error: "No begin 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.end) return res.json(500, {error: "No end defined"});
if (!params.actions) return res.json(500, {error: "No actions in try 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.supervisor) return res.json(500, {error: "No supervisor in try defined"});
if (!params.student) return res.json(500, {error: "No student in try defined"}); if (!params.student) return res.json(500, {error: "No student in try defined"});
Try.create({ Try.create({
"workingSession":params.ws, "workingSession":params.ws,
"begin": params.begin, "begin": params.begin,
"end": params.end "end": params.end
}).exec(function(err, tr){ }).exec(function(err, tr){
if(err || !tr){ if(err || !tr){
sails.log.debug("Creating new Try: " + err); sails.log.debug("Creating new Try: " + err);
return res.json(500, {error: 'Try not created'}); return res.json(500, {error: 'Try not created'});
} }
if(tr){ if(tr){
var l_actions = []; var l_actions = [];
// with .eachSeries the order of resulting array will be equal // with .eachSeries the order of resulting array will be equal
// to the original array // to the original array
async.eachSeries(params.actions, function(a, callback) { async.eachSeries(params.actions, function(a, callback) {
sails.log.debug("Loop adding actions: " + a.action + " to try " + tr.id); sails.log.debug("Loop adding actions: " + a.action + " to try " + tr.id);
var desc = null; var desc = null;
if(a.attributes.picto) desc = a.attributes.picto; // select, add and delete actions data 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 if(a.attributes.pictos) desc = a.attributes.pictos; // show action data
Action.create({ Action.create({
type: a.action, type: a.action,
timestamp: a.attributes.timestamp, timestamp: a.attributes.timestamp,
supervisor: params.supervisor, supervisor: params.supervisor,
student: params.student, student: params.student,
description: desc, description: desc,
_try: tr.id _try: tr.id
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new "+ a.action +" action: " + err); if(err || !action) sails.log.debug("Creating new "+ a.action +" action: " + err);
if(action){ if(action){
sails.log.debug("Action Created: " + action.type); sails.log.debug("Action Created: " + action.type);
l_actions.push(action); l_actions.push(action);
} }
callback(); callback();
}); });
// Finish function when each callback is done // Finish function when each callback is done
// Optionaly it can be passed and err parameter // Optionaly it can be passed and err parameter
}, function(err){ }, function(err){
if( err ) { if( err ) {
// One of the iterations produced an error. // One of the iterations produced an error.
// All processing will now stop. // All processing will now stop.
console.log('An error ocurred with an action'); console.log('An error ocurred with an action');
} else { } else {
console.log('All actions have been processed successfully'); console.log('All actions have been processed successfully');
// Return the try // Return the try
// with the array of actions // with the array of actions
return res.json({ return res.json({
"id": tr.id, "id": tr.id,
"workingSession": tr.workingSession, "workingSession": tr.workingSession,
"begin": tr.begin, "begin": tr.begin,
"end": tr.end, "end": tr.end,
"actions": l_actions "actions": l_actions
}); });
} }
}); });
/* /*
// InitSession Action // InitSession Action
Action.create({ Action.create({
"type": "InitSession", "type": "InitSession",
"timestamp": ws.begin, "timestamp": ws.begin,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"student": ws.student, "student": ws.student,
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action InitSession: " + err); if(err || !action) sails.log.debug("Creating new Action InitSession: " + err);
if(action) sails.log.debug("Created Action: " + action.type); if(action) sails.log.debug("Created Action: " + action.type);
}); });
// TryInit Action // TryInit Action
Action.create({ Action.create({
"type": "TryInit", "type": "TryInit",
"timestamp": ws.begin, "timestamp": ws.begin,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"student": ws.student, "student": ws.student,
"_try": tr.id "_try": tr.id
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action TryInit: " + err); if(err || !action) sails.log.debug("Creating new Action TryInit: " + err);
if(action){ if(action){
sails.log.debug("Created Action: " + action.type); sails.log.debug("Created Action: " + action.type);
// Return the working session created // Return the working session created
// with the array of one try (the first) // with the array of one try (the first)
// with the array of one action (the first too) // with the array of one action (the first too)
return res.json({ return res.json({
"id": ws.id, "id": ws.id,
"begin": ws.begin, "begin": ws.begin,
"student": ws.student, "student": ws.student,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"tries": [ "tries": [
{ {
"id": tr.id, "id": tr.id,
"instruction": tr.instruction, "instruction": tr.instruction,
"begin": tr.begin, "begin": tr.begin,
"workingSession": tr.workingSession, "workingSession": tr.workingSession,
"actions": [ action ] "actions": [ action ]
} }
] ]
}); });
} }
}); });
*/ */
} }
}); });
} }
}; };
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