solved problems with student creation (picto core addition and list refresh)

parent 2a41c00b
...@@ -53,6 +53,16 @@ thisTrigger: BEGIN ...@@ -53,6 +53,16 @@ thisTrigger: BEGIN
current_students=current_students+1 current_students=current_students+1
WHERE WHERE
office.id=new.id_off; 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),
',"coord_x":',coord_x,
',"coord_y":',coord_y,
',"status":"invisible"',
',"highlight":false',
',"color":', if (color is null, 'null',concat('"',color,'"')),
'}') as attributes
FROM picto_core P;
END;; END;;
-- Integrity rule 3: office.current_enrolments and supervisor assigments updating. -- Integrity rule 3: office.current_enrolments and supervisor assigments updating.
......
...@@ -158,7 +158,7 @@ module.exports = { ...@@ -158,7 +158,7 @@ module.exports = {
Student.create(params) Student.create(params)
.then(function(created) { .then(function(created) {
sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created)); sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created));
return res.ok({ student: created }); return res.ok(created);
}) })
.error(function(err) { .error(function(err) {
if (err.message.search("Maximum number of enrolments reached") > 0) { if (err.message.search("Maximum number of enrolments reached") > 0) {
...@@ -169,8 +169,8 @@ module.exports = { ...@@ -169,8 +169,8 @@ module.exports = {
return res.serverError(err.message); return res.serverError(err.message);
} }
else { else {
sails.log.debug(err); sails.log.debug(err.message);
return res.serverError(err); return res.serverError(err.message);
} }
}); });
}, },
......
...@@ -238,53 +238,6 @@ module.exports = { ...@@ -238,53 +238,6 @@ module.exports = {
}, },
/** /**
* Sets initial vocabulary of students to Picto Core
* @param {Object} attrs All student properties stored
* @param {Function} next Function to be executed when the check process
* has been completed (an error object will be passed
* to the function if necesary)
*/
afterCreate: function (attrs, next) {
// Assign the initial collection of pictos to the student
PictoCore.find()
.then(function(pictoCore) {
var i;
// Every picto from 'picto_core_cat' is going to be created
// in 'stu_picto'
for (var i = 0; i < pictoCore.length; i++) {
StuPicto.create({
student: created.id,
picto: pictoCore[i].picto,
attributes: {
id_cat: pictoCore[i].category,
coord_x: pictoCore[i].coord_x,
coord_y: pictoCore[i].coord_y,
status: 'invisible', // Default, the pictos don't appear to the user
color: pictoCore[i].color
}
})
.then(function (stuPictoError, added) {
if (added) {
sails.log.debug(
'Picto ' + added.picto +
' added to student ' + created.id +
' with attributes: ' + JSON.stringify(added.attributes));
}
})
.error(function(err) {
sails.log.debug('StuPicto.create: ' + err);
throw err;
});
}
next();
})
.error(function(err) {
next(err);
});
},
/**
* Checks the given properties before updating a new Student * Checks the given properties before updating a new Student
* @param {Object} attrs All student properties to be stored * @param {Object} attrs All student properties to be stored
* @param {Function} next Function to be executed when the check process * @param {Function} next Function to be executed when the check process
......
...@@ -137,6 +137,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -137,6 +137,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
errorMessage = 'invalid_fields'; errorMessage = 'invalid_fields';
ngToast.danger({ content: $translate.instant(errorMessage) }); ngToast.danger({ content: $translate.instant(errorMessage) });
}); });
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<!-- Default panel contents --> <!-- Default panel contents -->
<div class="panel-heading"><h3 class="panel-title" translate>students</h3> <div class="panel-heading"><h3 class="panel-title" translate>students</h3>
<span ng-if="user.isAdmin">({{user.office.currentStudents}}/{{user.office.maxStudents}} - <span translate="licenses_left" translate-values="{number: num_licenses_left}"></span>)</span> <!-- span ng-if="user.isAdmin">({{user.office.currentStudents}}/{{user.office.maxStudents}} - <span translate="licenses_left" translate-values="{number: num_licenses_left}"></span>)</span -->
<div class="panel-body"> <div class="panel-body">
<!-- Add Student Form --> <!-- Add Student Form -->
......
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