issue #953 fixed

parent df7dd36c
...@@ -86,10 +86,14 @@ module.exports = { ...@@ -86,10 +86,14 @@ module.exports = {
if (!params.id_sup) if (!params.id_sup)
return res.badRequest("No supervisor defined"); return res.badRequest("No supervisor defined");
if (!params.lang)
return res.badRequest("No lang defined");
MetaMethod.create({ MetaMethod.create({
"name": params.name, "name": params.name,
"description": "", "description": "",
"supervisor": params.id_sup "supervisor": params.id_sup,
"lang": params.lang
}) })
.then(function(createdMethod){ .then(function(createdMethod){
return res.ok(createdMethod); return res.ok(createdMethod);
......
...@@ -132,16 +132,29 @@ module.exports = { ...@@ -132,16 +132,29 @@ module.exports = {
}, },
// FERNANDO: avoid method name duplicates /*
// * Saves a method as a template
// Saves a method as a template * @param {request} req
// * {
* id_stu: studentId,
* id_sup: supervisorID
* lang: student lang code
* }
* @param {response} res
* {
* id: methodId,
* supervisor: supervisorId
* lang: {string} language code
* description: {string}
* }
*/
save: function(req, res){ save: function(req, res){
var params = req.allParams(); var params = req.allParams();
if (!params.id_met) return res.json(500, {error: "No method defined"}); if (!params.id_met) return res.json(500, {error: "No method defined"});
if (!params.id_sup) return res.json(500, {error: "No supervisor defined"}); if (!params.id_sup) return res.json(500, {error: "No supervisor defined"});
if (!params.lang) return res.json(500, {error: "No lang defined"});
Method.findOne(params.id_met).populate('instructions').exec(function(err, method) { Method.findOne(params.id_met).populate('instructions').exec(function(err, method) {
if (err){ if (err){
...@@ -152,7 +165,8 @@ module.exports = { ...@@ -152,7 +165,8 @@ module.exports = {
MetaMethod.create({ MetaMethod.create({
"name": method.name, "name": method.name,
"description": method.description, "description": method.description,
"supervisor": params.id_sup "supervisor": params.id_sup,
"lang": params.lang
}).exec(function(err, createdMethod){ }).exec(function(err, createdMethod){
if (err){ if (err){
sails.log.debug("Create Method error: " + err); sails.log.debug("Create Method error: " + err);
......
...@@ -164,7 +164,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr ...@@ -164,7 +164,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
$scope.save_as_template = function(method){ $scope.save_as_template = function(method){
$http $http
.post(config.backend+'/method/save', { 'id_met': method.id, 'id_sup': $scope.user.id }) .post(config.backend+'/method/save', { 'id_met': method.id, 'id_sup': $scope.user.id, 'lang': $scope.user.lang })
.then( //success .then( //success
function(data, status, headers, config) { function(data, status, headers, config) {
console.log('Saved method as template:' + JSON.stringify(data)); console.log('Saved method as template:' + JSON.stringify(data));
...@@ -180,7 +180,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr ...@@ -180,7 +180,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
} }
,function(data, status, headers, config) { //error ,function(data, status, headers, config) { //error
console.log("Error from API: " + data.error+"("+data.status+")"); console.log("Error from API: " + data.error+"("+data.status+")");
ngToast.success({ ngToast.warning({
content: $translate.instant('method_name_duplicated', {method_name: method.name}), content: $translate.instant('method_name_duplicated', {method_name: method.name}),
timeout: 6000 // By default 4000 timeout: 6000 // By default 4000
}); });
......
...@@ -33,12 +33,13 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s ...@@ -33,12 +33,13 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
// Functions // Functions
// //
// Add new method template (metamethod) selected to the student // Add new method template (metamethod)
$scope.add_method = function(){ $scope.add_method = function(){
var new_data = { var new_data = {
name: $translate.instant("new_method"), name: $translate.instant("new_method"),
id_sup: $scope.user.id id_sup: $scope.user.id,
lang: $scope.user.lang,
}; };
$http $http
......
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