Error getting pictos from symbolstix fixed

parent ec8594b7
......@@ -55,7 +55,7 @@ thisTrigger: BEGIN
office.id=new.id_off;
INSERT INTO stu_picto(id_stu,id_pic,attributes)
SELECT new.id,id_pic, concat('{"id_cat":', if (id_cat_pic is null, 'null',id_cat_pic),
SELECT new.id,id_pic, concat('{"id_cat":', if (id_cat_pic is null, 'null', id_cat_pic),
',"coord_x":',coord_x,
',"coord_y":',coord_y,
',"status":"invisible"',
......
......@@ -976,35 +976,45 @@ module.exports = {
var params = req.allParams();
var attrs = {};
// Get previous entry
StuPicto.findOne(params.prev_id_stu_pic)
.then((prev) => {
if (!prev)
throw new Error ("error on update");
// Create new one
var newsp = StuPicto.create({
student: params.id_stu,
picto: params.new_id_pic,
attributes: prev.attributes
.then((sp) => {
if (!sp) throw new Error ("error on update");
Student.findOne(params.id_stu)
.then((s) => {
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})
.then((pe) => {
if (!pe)
throw new Error ("Expression not found");
var old_picto = sp.picto;
sp.picto = params.new_id_pic;
sp.attributes.expression = pe.text;
// Save modified stu_picto entry for category
sp.save((err) => {
if (err) throw err;
// Update attributes.id_cat for all pictos
StuPicto.find({id_stu: params.id_stu})
.then(sps => {
for (var i=0; i<sps.length; i++) {
if (sps[i].attributes.id_cat == old_picto) {
sps[i].attributes.id_cat = params.new_id_pic;
sps[i].save();
}
}
return res.ok(sp);
})
.catch(e => {throw e});
});
})
.catch(e => {throw e});
})
.then(newsp => newsp)
.catch(err => {throw err});
var picto = Picto.findOne(params.new_id_pic)
.then(p => p)
.catch(err => {throw err});
return [prev, newsp, picto];
})
.spread(function(prev, newsp, picto) {
// Destroy previous entry
StuPicto.destroy({id: prev.id})
.then(() => {res.ok(newsp)})
.catch(err => {throw err});
.catch(e => {throw e})
})
.catch(err => {
return res.serverError('Unable to update category for student: ' + err);
return res.serverError('Unable to update category for student: ' + err);
});
},
......
......@@ -381,7 +381,7 @@ module.exports = {
var stuPictoToAdd = {
"id": stuPicto.id,
"picto": stuPicto.picto,
"expression": picto.expressions[0],
"expression": stuPicto.attributes.expression ? stuPicto.attributes.expression : picto.expressions[0].text,
"attributes": stuPicto.attributes,
"tags": picto.tags ? picto.tags : []
};
......
......@@ -42,6 +42,7 @@
"categories": "Categories",
"category_pictograms": "Category's pictograms",
"change_password": "Change password",
"change_cat_picto": "Change category pictogram",
"change_picture": "Change picture",
"child": "Child",
"click": "Click",
......
......@@ -42,6 +42,7 @@
"categories": "Categorías",
"category_pictograms": "Pictogramas de la categoría",
"change_password": "Cambiar contraseña",
"change_cat_picto": "Cambiar pictograma de la categoría",
"change_picture": "Cambiar fotografía",
"child": "Niño",
"click": "Clic",
......
......@@ -33,7 +33,7 @@
('empty-' + colIndex + '-' + rowIndex)
}}"
draggable droppable drop="handleDrop"
popover="{{studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression}}"
popover="{{studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression}}"
popover-trigger="mouseenter"
ng-init="colIndex = $index"
ng-repeat="studentPicto in studentPictoRow track by $index">
......@@ -41,13 +41,13 @@
<div
class="picto-legend-normal"
ng-if="studentPicto.attributes.legend == 'normal'">
{{ studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression }}
{{ studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression }}
</div>
<div
class="picto-legend-full"
ng-if="studentPicto.attributes.legend == 'full'">
{{ studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression }}
{{ studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression }}
</div>
<!-- /.picto-legend -->
<img
......@@ -121,19 +121,19 @@
class="picto pull-left ng-class:{'picto-out': studentData.attributes.size == 'large' && (rowIndex > 3 || colIndex > 7)};"
ng-repeat="studentPicto in studentPictoRow track by $index"
ng-init="colIndex = $index"
popover="{{studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression}}"
popover="{{studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression}}"
popover-trigger="mouseenter">
<!-- picto-legend -->
<div
class="picto-legend-normal"
ng-if="studentPicto.attributes.legend == 'normal'">
{{ studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression }}
{{ studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression }}
</div>
<div
class="picto-legend-full"
ng-if="studentPicto.attributes.legend == 'full'">
{{ studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression }}
{{ studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression }}
</div>
<!-- /.picto-legend -->
<img
......@@ -178,7 +178,10 @@
ng-click="change_category(studentPicto)"
ng-if="studentPicto !== emptyStudentPicto && studentPicto.attributes.coord_y != '0'"
class="picto_cat_edit">
<i class="glyphicon glyphicon-picture" aria-hidden="true"></i>
<i
class="glyphicon glyphicon-picture" aria-hidden="true"
title="{{ 'change_cat_picto' | translate}}">
</i>
</a>
</div>
<div
......@@ -223,7 +226,7 @@
class="picto-grid picto-category-grid"
ng-if="selectedCategory !== emptyStudentPicto && !showFreeCategory"
ng-style="{ 'background-color': shadeColor(selectedCategory.attributes.color, 0.3) }">
<h3 class="picto-category-grid__title">{{ selectedCategory.expression.text }}</h3>
<h3 class="picto-category-grid__title">{{ selectedCategory.expression }}</h3>
<div
ng-repeat="studentPictoRow in studentPictos[getCategoryId(selectedCategory)]"
ng-init="rowIndex = $index"
......@@ -237,7 +240,7 @@
('empty-' + colIndex + '-' + rowIndex)
}}"
draggable droppable drop="handleDrop"
popover="{{studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression}}"
popover="{{studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression}}"
popover-trigger="mouseenter"
ng-repeat="studentPicto in studentPictoRow track by $index"
ng-init="colIndex = $index">
......@@ -245,13 +248,13 @@
<div
class="picto-legend-normal"
ng-if="studentPicto.attributes.legend == 'normal'">
{{ studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression }}
{{ studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression }}
</div>
<div
class="picto-legend-full"
ng-if="studentPicto.attributes.legend == 'full'">
{{ studentPicto.attributes.expression==null ? studentPicto.expression.text : studentPicto.attributes.expression }}
{{ studentPicto.attributes.expression==null ? studentPicto.expression : studentPicto.attributes.expression }}
</div>
<!-- /.picto-legend -->
<img
......
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