issue #583 fixed

parent ac58b697
...@@ -100,25 +100,27 @@ module.exports = { ...@@ -100,25 +100,27 @@ module.exports = {
* } * }
*/ */
getInfo: function (req, res) { getInfo: function (req, res) {
Student.findOne({id: req.params.id_stu}) Student.findOne({id: req.params.id_stu}).populate('lastInstruction')
.then(function (student) { .then(function (student) {
if (!student) if (!student)
throw new Error("student not found"); throw new Error("student not found");
student.current_method = null; student.current_method = student.lastInstruction[0] ? student.lastInstruction[0].met_name : "no_method";
student.current_instruction = null; student.current_instruction = student.lastInstruction[0] ? student.lastInstruction[0].ins_name : "no_instruction";
// recover last instruction to complete student info // recover last instruction to complete student info
var stu_last_inst = VStuLastInstruction.findOne({student: student.id}) var stu_last_inst = VStuLastInstruction.findOne({student: student.id})
.then(function (stu_last_inst) { .then(function (stu_last_inst) {
return stu_last_inst; return stu_last_inst;
}); })
.error(err => {throw err});
// determine supervision level of the requester on the student // determine supervision level of the requester on the student
var stu_sup = StuSup.findOne({id_stu: student.id, id_sup: req.token.id}) var stu_sup = StuSup.findOne({id_stu: student.id, id_sup: req.token.id})
.then(function (stu_sup) { .then(function (stu_sup) {
return stu_sup return stu_sup;
}); })
.error(err => {throw err});
return [student, stu_last_inst, stu_sup]; return [student, stu_last_inst, stu_sup];
}) })
......
...@@ -392,39 +392,63 @@ module.exports = { ...@@ -392,39 +392,63 @@ module.exports = {
* ] * ]
*/ */
students: function (req, res) { students: function (req, res) {
Supervisor.findOne({ id: req.params.id }).then(function (supervisor) { Supervisor.findOne({ id: req.params.id })
if (supervisor) { .then(function (supervisor) {
StuSup.find({ supervisor: supervisor.id }).populate('student').then(function (stuSups) { if (!supervisor)
var students = stuSups.map(function (stuSup) { throw new Error("Not a valid supervisor")
// Get all stu_sup relations
StuSup.find({ supervisor: supervisor.id })
.populate('student')
.then(function (stuSups) {
var students = [];
async.each(stuSups,
function(stuSup, cb) {
var student = stuSup.student; var student = stuSup.student;
student.supervision = req.token.office ? 2 : 1; student.supervision = req.token.office ? 2 : 1;
return student; VStuLastInstruction.findOne({student: student.id})
.then(function (stu_last_inst) {
student.current_method = stu_last_inst ? stu_last_inst.met_name : "no_method";
student.current_instruction = stu_last_inst ? stu_last_inst.ins_name : "no_instruction";
students.push(student);
cb();
})
.error(err => {
students.push(student);
cb();
}); });
},
function(err) {}
);
return students;
})
.then(function (students) {
// Get all students from the office if user is administrator
if (req.token.isSupAdmin && req.token.office && req.token.office.id) { if (req.token.isSupAdmin && req.token.office && req.token.office.id) {
Student.find({ office: req.token.office.id }).then(function (officeStudents) {
students = students.concat(officeStudents); Student.find({ office: req.token.office.id }).populate('lastInstruction')
students = students.map((student) => { .then(function (officeStudents) {
officeStudents = officeStudents.map((student) => {
student.supervision = student.supervision || 0; student.supervision = student.supervision || 0;
student.current_method = student.lastInstruction[0] ? student.lastInstruction[0].met_name : "no_method";
student.current_instruction = student.lastInstruction[0] ? student.lastInstruction[0].ins_name : "no_instruction";
return student; return student;
}); });
students = students.concat(officeStudents);
res.ok(lodash.uniq(students, false, 'id')); res.ok(lodash.uniq(students, false, 'id'));
}) })
.catch(function () { .catch(function (err) {
res.serverError(); res.serverError("Error " + err);
}); });
} else { } else
res.ok(students); res.ok(students);
}
}) })
.catch(function () { .catch(err => {throw err});
res.serverError();
});
} else {
res.badRequest();
}
}) })
.catch(function () { .catch(function (err) {
res.serverError(); res.serverError("Error " + err);
}); });
}, },
......
...@@ -75,17 +75,22 @@ module.exports = { ...@@ -75,17 +75,22 @@ module.exports = {
}, },
// Relación con StuSup // Relación con StuSup
stuSup: { stuSup: {
collection: 'StuSup', collection: 'stusup',
via: 'student' via: 'student'
}, },
// Relación con Method. [1 Student to N Method] // Relación con Method. [1 Student to N Method]
methods: { methods: {
collection: 'Method', collection: 'method',
via: 'student' via: 'student'
}, },
// Relación con StuPicto. [1 Student to N StuPicto] // Relación con StuPicto. [1 Student to N StuPicto]
stuPicto: { stuPicto: {
collection: 'StuPicto', collection: 'stupicto',
via: 'student'
},
// Relación con VStuLastInstruction [1 Student to 1 StuPicto]
lastInstruction: {
collection: 'vstulastinstruction',
via: 'student' via: 'student'
}, },
...@@ -166,7 +171,7 @@ module.exports = { ...@@ -166,7 +171,7 @@ module.exports = {
legend_size: 'normal', legend_size: 'normal',
size: 'normal', size: 'normal',
picto_background: '#0000ff', picto_background: '#0000ff',
tape_background: '#00ffff' tape_background: '#00ffff',
}; };
sails.log.verbose('Requested attributes for Student', attributes); sails.log.verbose('Requested attributes for Student', attributes);
......
...@@ -46,7 +46,7 @@ module.exports = { ...@@ -46,7 +46,7 @@ module.exports = {
required: true, required: true,
primaryKey: true, primaryKey: true,
unique: true, unique: true,
type: "integer", model: "Student"
} }
} }
}; };
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<div class="col-md-10"> <div class="col-md-10">
<div style="margin-left: 5px"><h4>{{studentData.name}} {{studentData.surname}}</h4></div> <div style="margin-left: 5px"><h4>{{studentData.name}} {{studentData.surname}}</h4></div>
<div style="margin-left: 5px" class="text-left"> <div style="margin-left: 5px" class="text-left">
<span>{{studentData.current_instruction | translate}} </span> <span>{{studentData.current_instruction | translate}} </span><br/>
<span class="text-muted">({{studentData.current_method | translate}})</span> <span class="text-muted">({{studentData.current_method | translate}})</span>
</div> </div>
</div> </div>
......
...@@ -40,6 +40,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -40,6 +40,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
console.log("currentStudents: " + $scope.user.office.currentStudents); console.log("currentStudents: " + $scope.user.office.currentStudents);
console.log("maxStudents: " + $scope.user.office.maxStudents); console.log("maxStudents: " + $scope.user.office.maxStudents);
// Compute number of licenses left
if ($scope.user.office.currentStudents >= $scope.user.office.maxStudents) { if ($scope.user.office.currentStudents >= $scope.user.office.maxStudents) {
$scope.num_licenses_left = 0; $scope.num_licenses_left = 0;
} else { } else {
...@@ -51,6 +52,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -51,6 +52,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
$scope.user.office = { name: '' }; $scope.user.office = { name: '' };
} }
// Hide new student form
$scope.hidestudentadd = true; $scope.hidestudentadd = true;
// Get list of supervisor's students // Get list of supervisor's students
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<h4>{{student.name}} {{student.surname}}</h4> <h4>{{student.name}} {{student.surname}}</h4>
</td> </td>
<td> <td>
<p> {{student.current_method}} <br />{{student.current_instruction}}</p> <p> <span> {{student.current_method | translate}} </span> <br /> <span class="text-muted">{{student.current_instruction | translate}}</span> </p>
</td> </td>
<td> <!-- BUTTONS --> <td> <!-- BUTTONS -->
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
* * * *
****************************************************************************/ ****************************************************************************/
// module.exports.csrf = false; // module.exports.csrf = true;
/**************************************************************************** /****************************************************************************
* * * *
......
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