issue #583 fixed

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