issue #701 close - category pictos can be modified

parent a2a259e1
...@@ -980,38 +980,41 @@ module.exports = { ...@@ -980,38 +980,41 @@ module.exports = {
.then((sp) => { .then((sp) => {
if (!sp) throw new Error ("error on update"); if (!sp) throw new Error ("error on update");
// Get student to get language
Student.findOne(params.id_stu) Student.findOne(params.id_stu)
.then((s) => { .then((s) => {
if (!s) throw new Error("Student not found"); if (!s) throw new Error("Student not found");
console.log("id_pic: " + sp.picto + ", lang: " + s.lang);
PictoExp.findOne({id_pic: sp.picto, lang: s.lang}) PictoExp.findOne({id_pic: sp.picto, lang: s.lang})
.then((pe) => { .then((pe) => {
if (!pe) if (!pe) throw new Error ("Expression not found");
throw new Error ("Expression not found");
var old_picto = sp.picto; // store old picto id to update pictos in category
sp.picto = params.new_id_pic; var old_picto = sp.picto;
if (sp.attributes.expression == undefined || sp.attributes.expression == null)
sp.attributes.expression = pe.text; sp.attributes.expression = pe.text;
// Save modified stu_picto entry for category sp.picto = params.new_id_pic;
sp.save((err) => {
if (err) throw err; // Save modified stu_picto entry for category
// Update attributes.id_cat for all pictos sp.save((err) => {
StuPicto.find({id_stu: params.id_stu}) if (err) throw err;
.then(sps => { // Update attributes.id_cat for all pictos
for (var i=0; i<sps.length; i++) { StuPicto.find({id_stu: params.id_stu})
if (sps[i].attributes.id_cat == old_picto) { .then(sps => {
sps[i].attributes.id_cat = params.new_id_pic; for (var i=0; i<sps.length; i++) {
sps[i].save(); if (sps[i].attributes.id_cat == old_picto) {
} sps[i].attributes.id_cat = params.new_id_pic;
sps[i].save();
} }
return res.ok(sp); }
}) return res.ok(sp);
.catch(e => {throw e}); })
}); .catch(err => {throw err});
});
}) })
.catch(e => {throw e}); .catch(err => {throw err});
}) })
.catch(e => {throw e}) .catch(err => {throw err})
}) })
.catch(err => { .catch(err => {
return res.serverError('Unable to update category for student: ' + err); return res.serverError('Unable to update category for student: ' + err);
......
...@@ -52,7 +52,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -52,7 +52,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$scope.selectedCategory = $scope.emptyStudentPicto; $scope.selectedCategory = $scope.emptyStudentPicto;
$scope.studentPictos = {}; $scope.studentPictos = {};
$scope.freeCategoryPictos = null; $scope.freeCategoryPictos = null;
$scope.categories = [];
$scope.loadingPictos = true; $scope.loadingPictos = true;
$scope.isCategory = function (studentPicto) { $scope.isCategory = function (studentPicto) {
...@@ -109,10 +108,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -109,10 +108,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] = $scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] =
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid(); $scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid();
if ($scope.isCategory(picto)) {
$scope.categories.push(picto);
}
// Categories disabled // Categories disabled
if (typeof freeCategoryPositionX === 'number' && if (typeof freeCategoryPositionX === 'number' &&
typeof freeCategoryPositionY === 'number') { typeof freeCategoryPositionY === 'number') {
...@@ -126,6 +121,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -126,6 +121,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$scope.getCategoryId(picto); $scope.getCategoryId(picto);
$scope.studentPictos[category] = $scope.studentPictos[category] || generateGrid(); $scope.studentPictos[category] = $scope.studentPictos[category] || generateGrid();
$scope.studentPictos[category][positionX][positionY] = picto; $scope.studentPictos[category][positionX][positionY] = picto;
console.log("picto placed at " + positionX + " " + positionY);
} }
}; };
...@@ -140,7 +136,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -140,7 +136,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// 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 + '/pictos')
.success(function (studentPictos) { .success(function (studentPictos) {
$scope.categories = [];
$scope.showFreeCategory = !$scope.studentData.attributes.categories; $scope.showFreeCategory = !$scope.studentData.attributes.categories;
studentPictos.forEach(placePicto); studentPictos.forEach(placePicto);
...@@ -337,8 +332,8 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -337,8 +332,8 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
new_id_pic: pictoId new_id_pic: pictoId
}) })
.success(function (studentPicto) { .success(function (studentPicto) {
console.log(attributes); console.log(JSON.stringify(studentPicto));
placePicto(studentPicto); $scope.loadPictos();
// notify // notify
io.socket.post('/stu/vocabulary', { io.socket.post('/stu/vocabulary', {
......
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