issues #672 #673 and #669 fixed

parent 3b6886f9
......@@ -218,6 +218,13 @@ module.exports = {
stu.save().then(function (saved) {
res.ok(stu);
// Send websocket message
sails.hooks.events.broadcastEvent(
sails.hooks.rooms.student(stu.id),
sails.hooks.events.updateStudent(stu),
(req.isSocket) ? req.socket : undefined
);
})
.catch(function(err) {
res.severError();
......@@ -336,7 +343,7 @@ module.exports = {
/**
* Creates a relation between the student and a given supervisor.
* It broadcasts the even linkSupervisorToStudent to both the student room
* It broadcasts the event linkSupervisorToStudent to both the student room
* and the supervisor room.
* @param {request} { (with id_stu and id_sup as url parameters)
* asTherapist: true/false (optional) // assigns supervisor to student's office is true, set id_off to null otherwise
......@@ -392,7 +399,7 @@ module.exports = {
if (req.body.asTherapist)
sup.office = stu.office;
else
sup.office = NULL;
sup.office = null;
delete sup.password;
sup.save();
}
......@@ -1099,8 +1106,6 @@ module.exports = {
}
},
//
// Logs a config action and broadcast to anyone subscribed to this student
config: function (req, res) {
......
......@@ -393,74 +393,20 @@ module.exports = {
* ...
* ]
*/
students: function (req, res) {
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({ id_sup: supervisor.id })
.populate('student')
.then(function (stuSups) {
var students = [];
async.each(stuSups,
function(stuSup, cb) {
// Filter logically deleted students
if (stuSup.student.office == null)
cb();
var student = stuSup.student;
student.supervision = req.token.office ? 2 : 1;
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) {}
);
sails.debug.log("->"+students);
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 {
sails.debug.log(students);
res.ok(students);
}
})
.catch(err => {throw err});
})
.catch(function (err) {
res.serverError("Error " + err);
});
},
/*
Returns all the students associated to this supervisor
*/
students: function (req, res) {
if (!req.params.id) {
return res.json(500, {
error: 'No supervisor defined'
});
}
Supervisor.students(req.params.id, function (err, stus) {
if (err) throw err;
return res.json(stus);
});
},
/**
* Get the pictos owned by this supervisor
......
......@@ -56,6 +56,19 @@ module.exports = function eventsHook(sails) {
},
/**
* A student has been updated
* @param {Object} Data of the student
* @return {Object} {name, data}
*/
updateStudent: function (stuData) {
return {
name: 'updateStudent',
data: {
student: stuData
}
};
},
/**
* A supervisor has been linked to a student.
* @param {ID} supId ID of the supervisor
* @param {ID} stu_id ID of the student
......
......@@ -205,5 +205,80 @@ module.exports = {
}
}
);
},
students: function(id, callback) {
var l = [];
Supervisor.findOne(id)
.populate('office')
.then(function (sup) {
if (!sup)
throw new Error("Not a valid supervisor")
// Get all stu_sup relations
var stuSups = StuSup.find({ supervisor: id })
.populate('student')
.then(function (stuSups) {
if (!stuSups || stuSups.length == 0)
return [];
return stuSups;
})
.catch((err) => {
throw err;
});
return [sup, stuSups];
})
.spread(function (sup, stuSups) {
async.eachSeries(stuSups, function(stuSup, next_cb) {
// Filter logically deleted students
if (stuSup.student.office == null)
next_cb();
var student = stuSup.student;
student.supervision = sup.office ? 2 : 1;
// set current methdo and instruction if any
student.current_method = "no_method";
student.current_instruction = "no_instruction";
VStuLastInstruction.findOne({student: student.id})
.then(function (stu_last_inst) {
if (stu_last_inst) {
student.current_method = stu_last_inst.met_name;
student.current_instruction = stu_last_inst.ins_name;
}
l.push(student);
next_cb();
})
.error(err => {
l.push(student);
next_cb();
});
},
function (err) { // loop has end
// Get all students from the office if user is administrator
if (sup.office && sup.office.admin == sup.id) {
Student.find({ office: sup.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;
});
l.concat(officeStudents);
callback(null, lodash.uniq(l, false, 'id'));
})
.catch(function (err) {
callback(err, l);
});
}
callback(err, l);
}); // end async.eachSeries
})
.catch((err) => {
callback(err, l);
}); // end Supervisor.findOne
}
};
......@@ -60,7 +60,12 @@ function LoginCtrl(
.post(config.backend + '/sup/login', $scope.credentials)
.success(function (data) {
// default logo to Pictogram logo
if (!data.user.office || data.user.office.logo_url.length < 5)
if (!data.user.office) {
data.user.office = $scope.office;
data.user.isTutor = true;
} else
data.user.isTutor = false;
if (data.user.office.logo_url.length < 5)
data.user.office.logo_url = 'img/logo_pictogram.png';
$window.sessionStorage.token = data.token;
......
......@@ -8,7 +8,7 @@
<div class="col-lg-8">
<p class="text-center">
<img src="img/logo_pictogram.png" alt="Pictogram" title="Pictogram" />
<a href="/app"><img src="img/logo_pictogram.png" alt="Pictogram" title="Pictogram" style="border-style: none"/></a>
</p>
<div class="page-header">
<h2 translate>register</h2>
......
......@@ -308,14 +308,6 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
$translate('attributes_updated').then(function (translation) {
ngToast.success({ content: translation });
});
// websocket emit vocabulary delete action
io.socket.post('/stu/config', {
action: 'update',
attributes: {
id_stu: $scope.studentData.id,
attributes: $scope.studentData.attributes
}
}, function () {});
})
.error(function () {
$translate('attributes_not_updated').then(function (translation) {
......
......@@ -18,6 +18,7 @@ dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl($scope
$scope.user.office = user.office;
$scope.user.lang = user.lang;
$scope.user.isSupAdmin = user.isSupAdmin;
$scope.user.isTutor = user.isTutor;
// Link to setup
$scope.setup = function(){
......
......@@ -32,7 +32,7 @@
{{ 'students' | translate }}
</a>
</li>
<li>
<li ng-if="user.isTutor == false">
<a class="pointer" role="menuitem" tabindex="0" href="/app/#/instructions">
<i class="glyphicon glyphicon-tasks" aria-hidden="true"></i>
{{ 'instructions' | translate }}
......
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