Commit 1849ee61 by Jose Antonio

Working on scenes

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