Commit 1849ee61 by Jose Antonio

Working on scenes

parent 897c69d3
...@@ -34,6 +34,8 @@ module.exports = { ...@@ -34,6 +34,8 @@ module.exports = {
// Update a scene data // Update a scene data
// //
update: function (req, res) { update: function (req, res) {
if (typeof req.params.id == 'undefined' || !req.params.id)
return res.badRequest("scene id not defined");
Scene.findOne({ id: req.params.id }).then(function (scene) { Scene.findOne({ id: req.params.id }).then(function (scene) {
if (!scene) { if (!scene) {
res.badRequest(); res.badRequest();
...@@ -63,6 +65,8 @@ module.exports = { ...@@ -63,6 +65,8 @@ module.exports = {
* @param {response} res {} * @param {response} res {}
*/ */
destroy: function (req, res) { destroy: function (req, res) {
if (typeof req.params.id == 'undefined' || !req.params.id)
return res.badRequest("scene id not defined");
Scene.destroy({ id: req.params.id }).exec(function (error) { Scene.destroy({ id: req.params.id }).exec(function (error) {
if (error) if (error)
return res.badRequest(); return res.badRequest();
...@@ -77,33 +81,25 @@ module.exports = { ...@@ -77,33 +81,25 @@ module.exports = {
* @param {response} res {} * @param {response} res {}
*/ */
getScene: function(req, res){ getScene: function(req, res){
if (typeof req.params.id == 'undefined' || !req.params.id)
return res.badRequest("scene id not defined");
Scene.findOne({id: req.params.id}) Scene.findOne({id: req.params.id})
.populate('stuPictos').then(function(scene){ .populate('stuPictos').then(function(scene){
if(!scene) if(!scene){
return res.badRequest(); return res.badRequest();
else }
console.log(scene); else{
return res.ok(scene); Scene.pictos(scene.id, function(err, pictos){
if (err){
return res.serverError("Error obtaining pictos: "+ err);
}
scene.pictos=pictos;
return res.ok(scene);
});
}
}).catch(function (err){ }).catch(function (err){
return res.serverError("Error finding scene "+err); return res.serverError("Error finding scene "+err);
}); });
},
/**
* Return all the scenes of a student
* @param {request} req {} (studentId)
* @param {response} res {}
*/
getScene: function(req, res){
Scene.find({ student: req.params.id_stu})
.populate('stuPictos').then(function(scenes){
if(!scenes)
return res.badRequest();
else
return res.ok(scenes);
}).catch(function (err){
return res.serverError("Error retrieving scenes "+err);
});
} }
}; };
...@@ -824,20 +824,19 @@ module.exports = { ...@@ -824,20 +824,19 @@ module.exports = {
* @param {response} res {} * @param {response} res {}
*/ */
getActiveScene: function(req, res){ getActiveScene: function(req, res){
Scene.findOne({ student: req.params.id_stu, active: true}) if (typeof req.params.id_stu == 'undefined' || !req.params.id_stu)
.populate('stuPictos').then(function(scene){ return res.badRequest("id_stu not defined");
Scene.findOne({student: req.params.id_stu, active: true})
.populate('stuPictos')
.then(function(scene){
if(!scene) if(!scene)
return res.badRequest(); return res.badRequest("Scene not found");
else else
console.log(scene);
Scene.pictos(scene.id, function(err, pictos){ Scene.pictos(scene.id, function(err, pictos){
if (err){ if (err){
return res.serverError("Error obtaining pictos: "+ err); return res.serverError("Error obtaining pictos: "+ err);
} }
scene.pictos=pictos; scene.pictos=pictos;
console.log(scene);
return res.ok(scene); return res.ok(scene);
}); });
}).catch(function (err){ }).catch(function (err){
...@@ -845,6 +844,25 @@ module.exports = { ...@@ -845,6 +844,25 @@ module.exports = {
}); });
}, },
/**
* Return all scenes of a student
* @param {request} req {} (with studentId as url parameter)
* @param {response} res {}
*/
getScenes: function(req, res){
if (typeof req.params.id_stu == 'undefined' || !req.params.id_stu)
return res.badRequest("id_stu not defined");
Scene.find({student: req.params.id_stu})
.then(function(scenes){
if(!scenes)
return res.badRequest("No scenes found");
else
return res.ok(scenes);
}).catch(function (err){
return res.serverError("Error finding scene "+err);
});
},
// //
// Returns all working sessions for the given student // Returns all working sessions for the given student
// //
...@@ -943,6 +961,7 @@ module.exports = { ...@@ -943,6 +961,7 @@ module.exports = {
StuPicto.create({ StuPicto.create({
student: student.id, student: student.id,
picto: picto.id, picto: picto.id,
scene: params.id_scene,
attributes: params.attributes attributes: params.attributes
}) })
, ,
......
...@@ -134,7 +134,7 @@ module.exports = function eventsHook(sails) { ...@@ -134,7 +134,7 @@ module.exports = function eventsHook(sails) {
}, },
/** /**
* Vocabulary is updated * Vocabulary is updated (active scene)
* @param {action} type of the action * @param {action} type of the action
* @param {attributes} attributes of the action (id_stu, stu_picto) * @param {attributes} attributes of the action (id_stu, stu_picto)
* @return {Object} {name, data} * @return {Object} {name, data}
......
...@@ -31,21 +31,21 @@ module.exports = { ...@@ -31,21 +31,21 @@ module.exports = {
categories: { categories: {
type: "boolean" type: "boolean"
}, },
supervisor: { //FK de supervisor 1 a NN supervisor: { //FK de supervisor 1 a N
columnName: "id_sup", columnName: "id_sup",
required: true, required: false,
type: "integer", type: "integer",
model: "Supervisor" model: "supervisor"
}, },
student: { // FK de student 1 a N student: { // FK de student 1 a N
columnName: "id_stu", columnName: "id_stu",
required: true, required: true,
type: "integer", type: "integer",
model: "Student" model: "student"
}, },
// Relacion con Stu_picto // Relacion con Stu_picto
stuPictos:{ stuPictos:{
collection: "StuPicto", collection: "stupicto",
via: "scene" via: "scene"
} }
}, },
...@@ -67,8 +67,6 @@ module.exports = { ...@@ -67,8 +67,6 @@ module.exports = {
.then((stuPictos) => { .then((stuPictos) => {
if (!stuPictos || stuPictos.length == 0) if (!stuPictos || stuPictos.length == 0)
return []; return [];
console.log(stuPictos);
return stuPictos; return stuPictos;
}) })
.catch((err) => { .catch((err) => {
...@@ -86,7 +84,6 @@ module.exports = { ...@@ -86,7 +84,6 @@ module.exports = {
return [scene, stuPictos, student]; return [scene, stuPictos, student];
}) })
.spread((scene, stuPictos, student) => { .spread((scene, stuPictos, student) => {
console.log(stuPictos);
async.eachSeries(stuPictos, function(stuPicto, next_cb) { async.eachSeries(stuPictos, function(stuPicto, next_cb) {
// Populate expressions to get it with the picto // Populate expressions to get it with the picto
...@@ -127,6 +124,6 @@ module.exports = { ...@@ -127,6 +124,6 @@ module.exports = {
}) })
.catch((err) => { .catch((err) => {
callback(err, l); callback(err, l);
}); // end Student.findOne }); // end Scene.findOne
} }
}; };
...@@ -32,8 +32,8 @@ module.exports = { ...@@ -32,8 +32,8 @@ module.exports = {
type: 'integer', type: 'integer',
model: 'Picto' model: 'Picto'
}, },
scene:{ //FK de Scene 1 a N scene: { //FK de Scene 1 a N
columName: "id_scene", columnName: "id_scene",
type: "integer", type: "integer",
model: "Scene" model: "Scene"
}, },
......
...@@ -47,6 +47,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -47,6 +47,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$scope.studentPictos = {}; $scope.studentPictos = {};
$scope.freeCategoryPictos = null; $scope.freeCategoryPictos = null;
$scope.loadingPictos = true; $scope.loadingPictos = true;
$scope.viewingScene = null;
$scope.isCategory = function (studentPicto) { $scope.isCategory = function (studentPicto) {
return studentPicto.attributes.id_cat === null && return studentPicto.attributes.id_cat === null &&
...@@ -127,10 +128,12 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -127,10 +128,12 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid(); $scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid();
// Get user's pictos // Get user's pictos
$http.get(config.backend + '/stu/' + $scope.studentData.id + '/pictos') $http.get(config.backend + '/stu/' + $scope.studentData.id + '/activeScene')
.success(function (studentPictos) { .success(function (activeScene) {
$scope.showFreeCategory = !$scope.studentData.attributes.categories; $scope.showFreeCategory = !$scope.studentData.attributes.categories;
studentPictos.forEach(placePicto); $scope.viewingScene = activeScene.id;
activeScene.pictos.forEach(placePicto);
//studentPictos.forEach(placePicto);
$scope.loadingPictos = false; $scope.loadingPictos = false;
setTimeout(function () { $scope.$apply(); }); setTimeout(function () { $scope.$apply(); });
...@@ -384,7 +387,8 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -384,7 +387,8 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
status: 'enabled', status: 'enabled',
free_category_coord_x: $scope.showFreeCategory ? col : null, free_category_coord_x: $scope.showFreeCategory ? col : null,
free_category_coord_y: $scope.showFreeCategory ? row : null free_category_coord_y: $scope.showFreeCategory ? row : null
} },
id_scene: $scope.viewingScene
}) })
.success(function (studentPicto) { .success(function (studentPicto) {
placePicto(studentPicto); placePicto(studentPicto);
......
...@@ -74,7 +74,6 @@ module.exports.routes = { ...@@ -74,7 +74,6 @@ module.exports.routes = {
'DELETE /picto/:id_sup/tag/:id_tag': 'PictoController.del_tag', 'DELETE /picto/:id_sup/tag/:id_tag': 'PictoController.del_tag',
'GET /scene/:id': 'SceneController.getScene', 'GET /scene/:id': 'SceneController.getScene',
'GET /stu/:id_stu/scenes': 'SceneController.getStudentScenes',
'POST /scene/:id': 'SceneController.create', 'POST /scene/:id': 'SceneController.create',
'PUT /scene/:id': 'SceneController.update', 'PUT /scene/:id': 'SceneController.update',
'DELETE /scene/:id': 'SceneController.destroy', 'DELETE /scene/:id': 'SceneController.destroy',
...@@ -89,6 +88,7 @@ module.exports.routes = { ...@@ -89,6 +88,7 @@ module.exports.routes = {
'POST /stu/:id_stu/sup/:id_sup': 'StudentController.link_supervisor', 'POST /stu/:id_stu/sup/:id_sup': 'StudentController.link_supervisor',
'GET /stu/:id_stu/pictos': 'StudentController.pictos', 'GET /stu/:id_stu/pictos': 'StudentController.pictos',
'GET /stu/:id_stu/activeScene': 'StudentController.getActiveScene', 'GET /stu/:id_stu/activeScene': 'StudentController.getActiveScene',
'GET /stu/:id_stu/scenes': 'StudentController.getScenes',
'GET /stu/:id_stu/methods': 'StudentController.methods', 'GET /stu/:id_stu/methods': 'StudentController.methods',
'GET /stu/:id_stu/lasttries': 'StudentController.lasttries', 'GET /stu/:id_stu/lasttries': 'StudentController.lasttries',
......
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