Commit f395e976 by Jose Antonio

Issue #241, closed

parent ffbf1e07
...@@ -1205,6 +1205,7 @@ module.exports = { ...@@ -1205,6 +1205,7 @@ module.exports = {
@params {request} req { @params {request} req {
id_stu: {integer} studentID, id_stu: {integer} studentID,
legend_value: {string} 'none' | 'normal' | 'full' legend_value: {string} 'none' | 'normal' | 'full'
id_scene: {integer} sceneID
} }
@params {response} res { @params {response} res {
id: {integer} studentID, id: {integer} studentID,
...@@ -1213,16 +1214,20 @@ module.exports = { ...@@ -1213,16 +1214,20 @@ module.exports = {
*/ */
update_legend: function (req, res) { update_legend: function (req, res) {
var params = req.allParams(); var params = req.allParams();
Student.update_legend(params.id_stu, params.legend_value, function (err) { if(params.id_scene){
if (err) { Student.update_legend(params.id_scene, params.legend_value, function (err) {
sails.log.debug(JSON.stringify(err)); if (err) {
return res.serverError("Error on legend update: "); sails.log.debug(JSON.stringify(err));
} return res.serverError("Error on legend update: ");
return res.ok({ }
id: params.id_stu, return res.ok({
legend_value: params.legend_value, // picto attributes for student id: params.id_stu,
}); legend_value: params.legend_value, // picto attributes for student
}) });
})
}else{
return res.badRequest("id_scene required");
}
}, },
/** /**
......
...@@ -102,6 +102,7 @@ module.exports = { ...@@ -102,6 +102,7 @@ module.exports = {
var stuPictoToAdd = { var stuPictoToAdd = {
"id": stuPicto.id, "id": stuPicto.id,
"picto": stuPicto.picto, "picto": stuPicto.picto,
"id_scene": stuPicto.scene,
"attributes": stuPicto.attributes, "attributes": stuPicto.attributes,
"tags": picto.tags ? picto.tags : [] "tags": picto.tags ? picto.tags : []
}; };
......
...@@ -409,6 +409,7 @@ module.exports = { ...@@ -409,6 +409,7 @@ module.exports = {
var stuPictoToAdd = { var stuPictoToAdd = {
"id": stuPicto.id, "id": stuPicto.id,
"picto": stuPicto.picto, "picto": stuPicto.picto,
"id_scene": stuPicto.id_scene,
"attributes": stuPicto.attributes, "attributes": stuPicto.attributes,
"tags": picto.tags ? picto.tags : [] "tags": picto.tags ? picto.tags : []
}; };
...@@ -556,10 +557,10 @@ module.exports = { ...@@ -556,10 +557,10 @@ module.exports = {
* Updates legend in student pictos * Updates legend in student pictos
* legend is not updated for categories * legend is not updated for categories
*/ */
update_legend: function(id_stu, legend_value, cb) { update_legend: function(id_scene, legend_value, cb) {
var query='UPDATE stu_picto' + var query='UPDATE stu_picto' +
' SET attributes = json_set(attributes, \'$.legend\',\''+legend_value+'\')' + ' SET attributes = json_set(attributes, \'$.legend\',\''+legend_value+'\')' +
' WHERE id_stu=' + id_stu + ' AND ' + ' WHERE id_scene=' + id_scene + ' AND ' +
' (json_extract(attributes, \'$.id_cat\') LIKE \'null\' AND ' + ' (json_extract(attributes, \'$.id_cat\') LIKE \'null\' AND ' +
' json_extract(attributes, \'$.coord_y\') = 0 OR ' + ' json_extract(attributes, \'$.coord_y\') = 0 OR ' +
' json_extract(attributes, \'$.id_cat\') NOT LIKE \'null\' AND ' + ' json_extract(attributes, \'$.id_cat\') NOT LIKE \'null\' AND ' +
......
...@@ -608,7 +608,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -608,7 +608,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
} }
} }
}); });
// Returned data from the modal window
modalInstance.result.then(function (all_legend) {
if(all_legend){
ngToast.success({ content: $translate.instant('reloading_pictos') });
$scope.showScene($scope.viewingScene.id);
}
});
}; };
// Modal window to create scenes // Modal window to create scenes
......
...@@ -52,7 +52,9 @@ dashboardControllers.controller('PictoConfigCtrl', function ($window, $scope, $t ...@@ -52,7 +52,9 @@ dashboardControllers.controller('PictoConfigCtrl', function ($window, $scope, $t
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
if ($scope.update_all_legend) { if ($scope.update_all_legend) {
$http $http
.put(config.backend+'/stu/'+ stu.id + '/legend/' + $scope.studentPicto.attributes.legend) .put(config.backend+'/stu/'+ stu.id + '/legend/' + $scope.studentPicto.attributes.legend,{
id_scene: $scope.studentPicto.id_scene
})
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
resolve(result); resolve(result);
}) })
...@@ -78,10 +80,6 @@ dashboardControllers.controller('PictoConfigCtrl', function ($window, $scope, $t ...@@ -78,10 +80,6 @@ dashboardControllers.controller('PictoConfigCtrl', function ($window, $scope, $t
studentPicto.attributes = $scope.studentPicto.attributes; studentPicto.attributes = $scope.studentPicto.attributes;
$modalInstance.close($scope.studentPicto.attributes.expression); $modalInstance.close($scope.studentPicto.attributes.expression);
if ($scope.update_all_legend) {
ngToast.success({ content: $translate.instant('reloading_pictos') });
$window.location.reload();
}
}) })
}); });
...@@ -89,7 +87,7 @@ dashboardControllers.controller('PictoConfigCtrl', function ($window, $scope, $t ...@@ -89,7 +87,7 @@ dashboardControllers.controller('PictoConfigCtrl', function ($window, $scope, $t
$scope.close = function () { $scope.close = function () {
// Lo que se devuelve a collection // Lo que se devuelve a collection
$modalInstance.dismiss('cancel'); $modalInstance.dismiss($scope.update_all_legend);
// Devolver el picto actualizado, situándolo en su posición // Devolver el picto actualizado, situándolo en su posición
}; };
......
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