fixed #584 and #478

parent 1120a249
...@@ -42,12 +42,6 @@ ...@@ -42,12 +42,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/LocalFlavorDebug/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/LocalFlavorDebug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/LocalFlavorDebug/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/LocalFlavorDebug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/LocalFlavorDebug/shaders" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/LocalFlavorDebug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/LocalFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/LocalFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/assets" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/assets" type="java-test-resource" />
...@@ -56,6 +50,12 @@ ...@@ -56,6 +50,12 @@
<sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testLocalFlavorDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/LocalFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/LocalFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/LocalFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/LocalFlavor/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/LocalFlavor/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/LocalFlavor/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/LocalFlavor/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/LocalFlavor/assets" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/LocalFlavor/assets" type="java-resource" />
......
...@@ -42,12 +42,6 @@ ...@@ -42,12 +42,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavorDebug/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavorDebug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavorDebug/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavorDebug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavorDebug/shaders" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavorDebug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/DefaultFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/DefaultFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/assets" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/assets" type="java-test-resource" />
...@@ -56,6 +50,12 @@ ...@@ -56,6 +50,12 @@
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavorDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/DefaultFlavor/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/DefaultFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/DefaultFlavor/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/assets" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/assets" type="java-resource" />
...@@ -64,14 +64,6 @@ ...@@ -64,14 +64,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/shaders" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/assets" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/assets" type="java-test-resource" />
...@@ -80,6 +72,14 @@ ...@@ -80,6 +72,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
......
...@@ -149,69 +149,28 @@ module.exports = { ...@@ -149,69 +149,28 @@ module.exports = {
}, },
// //
// create action // Adds a new student into the database
// adds a new student into the database
// //
create: function (req, res) { create: function (req, res) {
var params = req.params.all(); var params = req.params.all();
Student.create(params) Student.create(params)
.exec(function (err, created) { .then(function(created) {
if (err) { sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created));
console.log(err); return res.ok({ student: created });
sails.log.debug(err); })
return res.json(500, err); .error(function(err) {
} if (err.message.search("Maximum number of enrolments reached") > 0) {
if (created) { // This is a MySQL error triggered by TRG_NEW_STUDENT_MAXENROLMENTS trigger
sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created)); // (see triggers-enroments-integrity-constraints.sql)
// As the format is not that of a normal error, we just get message
// Assign the initial collection of pictos to the student sails.log.debug(err.message);
PictoCore.find() return res.serverError(err.message);
.exec(function (pictoCoreError, pictoCore) { }
var i; else {
sails.log.debug(err);
if (pictoCoreError || !pictoCore || pictoCore.length === 0) { return res.serverError(err);
sails.log.debug('PictoCore: ' + pictoCoreError); }
return; });
}
sails.log.debug('PictoCore Length: ' + pictoCore.length);
sails.log.debug(pictoCore);
// Every picto from 'picto_core_cat' is going to be created
// in 'stu_picto'
for (i = 0; i < pictoCore.length; i++) {
sails.log.debug('Loop: ' + i);
sails.log.debug('Picto Category: ' + pictoCore[i].category);
sails.log.debug('User id: ' + created.id);
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
}
})
.exec(function (stuPictoError, added) {
if (stuPictoError) sails.log.debug('StuPicto.create: ' +
stuPictoError);
if (added) {
sails.log.debug(
'Picto ' + added.picto +
' added to student ' + created.id +
' with attributes: ' + JSON.stringify(added.attributes));
}
});
}
});
return res.json({
student: created
});
}
});
}, },
/** /**
......
...@@ -233,6 +233,53 @@ module.exports = { ...@@ -233,6 +233,53 @@ 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
......
...@@ -156,7 +156,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -156,7 +156,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}, function () {}); }, function () {});
$translate('picto_removed').then(function (translation) { $translate('picto_removed').then(function (translation) {
ngToast.danger({ content: translation }); ngToast.success({ content: translation });
}); });
}).error(function () {}); }).error(function () {});
...@@ -182,7 +182,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -182,7 +182,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}, function () {}); }, function () {});
$translate('picto_removed').then(function (translation) { $translate('picto_removed').then(function (translation) {
ngToast.danger({ content: translation }); ngToast.success({ content: translation });
}); });
}).error(function () {}); }).error(function () {});
......
...@@ -83,7 +83,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr ...@@ -83,7 +83,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
// Add empty array of instructions // Add empty array of instructions
data.instructions = []; data.instructions = [];
console.log('Created new empty Method:' + JSON.stringify(data)); console.log('Created new empty Method:' + JSON.stringify(data));
$scope.methods.push(data); $scope.methods.unshift(data);
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
console.log("Error from API: " + data.error); console.log("Error from API: " + data.error);
...@@ -108,8 +108,6 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr ...@@ -108,8 +108,6 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
} }
}; };
// Delete template // Delete template
$scope.delete_template = function(){ $scope.delete_template = function(){
...@@ -177,7 +175,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr ...@@ -177,7 +175,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.success({
content: $translate.instant('method_name_duplicated', {method_name: method.name}), content: $translate.instant('method_name_duplicated', {method_name: method.name}),
......
...@@ -12,10 +12,9 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -12,10 +12,9 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$translate, $translate,
ngToast) { ngToast) {
// For tab navigation (here too, if the user refresh the page...) // For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'session'; $scope.nav.tab = 'session';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// SESSION // SESSION
// Prepare session recording information // Prepare session recording information
...@@ -59,13 +58,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -59,13 +58,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.numPerPage = 5; $scope.numPerPage = 5;
$scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage); $scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
$scope.ws_recover = $scope.wsessions[0]!=null && $scope.wsessions[0].end==null; $scope.ws_recover = $scope.wsessions[0]!=null && $scope.wsessions[0].end==null;
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
}); });
// Initially, show the last try // Initially, show the last try
...@@ -94,7 +88,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -94,7 +88,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// If to avoid the default select option "-- select one instruction --" // If to avoid the default select option "-- select one instruction --"
if(instruction){ if(instruction){
$http $http
.get(config.backend+'/instruction/'+ instruction.id +'/ws') .get(config.backend+'/instruction/'+ instruction.id +'/ws')
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Add to list // Add to list
...@@ -104,11 +98,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -104,11 +98,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.numPerPage = 5; $scope.numPerPage = 5;
$scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage); $scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {});
});
} }
}; };
// Tries pagination - previous tries // Tries pagination - previous tries
...@@ -124,8 +115,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -124,8 +115,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// //
// Evaluate a try (result update request) // Evaluate a try (result update request)
//Modify the desc. of a try // Modify the desc. of a try
$scope.update_try = function(t){ $scope.update_try = function(t) {
var update_data={}; var update_data={};
if (t.description) if (t.description)
update_data.description = t.description; update_data.description = t.description;
...@@ -142,33 +133,28 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -142,33 +133,28 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
}; };
$scope.update_current_try = function(){ $scope.update_current_try = function(){
$http $http
.put(config.backend+'/try/' + $scope.actual_try.id, { result: $scope.actual_try.result, end: new Date() }) .put(config.backend+'/try/' + $scope.actual_try.id, { result: $scope.actual_try.result, end: new Date() })
.then( .then(
function(data, status, headers, config2) { function(data, status, headers, config2) {
$http $http
.post(config.backend+'/try/', {ws: $scope.ws, student: $scope.studentData.id, supervisor: $scope.user.id, begin:new Date() }) .post(config.backend+'/try/', {ws: $scope.ws, student: $scope.studentData.id, supervisor: $scope.user.id, begin:new Date() })
.then( .then(
function(data, status, headers, config) { function(data, status, headers, config) {
$scope.load_tries($scope.selectedIns); $scope.load_tries($scope.selectedIns);
// Empty actual try and push the first action of next try // Empty actual try and push the first action of next try
$scope.actual_try.actions = []; $scope.actual_try.actions = [];
$scope.actual_try.actions.push({ action: 'tryinit' }); $scope.actual_try.actions.push({ action: 'tryinit' });
$scope.actual_try.id = data.id; $scope.actual_try.id = data.id;
} },
,function(data, status, headers, config) { function(data, status, headers, config) {}
} )
) ,function(data, status, headers, config) {}
,function(data, status, headers, config) { }
} );
}
);
}; };
$scope.send_show_action = function(){ $scope.send_show_action = function(){};
};
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
...@@ -190,9 +176,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -190,9 +176,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
,function(data, status, headers, config) { ,function(data, status, headers, config) {
} }
); );
} };
// //
// Create new working session // Create new working session
...@@ -228,11 +212,9 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -228,11 +212,9 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.studentData.current_instruction=$scope.selectedIns.name; $scope.studentData.current_instruction=$scope.selectedIns.name;
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
$translate('error_creating_session').then(function (translation) { ngToast.danger({ content: $translate.instant('error_creating_session') });
ngToast.danger({ content: translation });
});
}); });
} };
// //
// update the description of a given working session // update the description of a given working session
...@@ -243,10 +225,10 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -243,10 +225,10 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.then(function(data, status, headers, config) { .then(function(data, status, headers, config) {
// TODO notify update? // TODO notify update?
}) })
,function(data, status, headers, config) { .error(function(data, status, headers, config) {
}; });
} };
// //
// Finish a working session updating its end time // Finish a working session updating its end time
...@@ -315,7 +297,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -315,7 +297,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
}) })
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Adding resume action to the list of actions // Adding resume action to the list of actions
$scope.actual_try.actions = []; $scope.actual_try.actions = [];
$scope.actual_try.actions.push({ action: 'resumesession'} ); $scope.actual_try.actions.push({ action: 'resumesession'} );
$scope.actual_try.id=data.open_try; $scope.actual_try.id=data.open_try;
}) })
...@@ -393,38 +375,39 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -393,38 +375,39 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
// Add new listener to the event // Add new listener to the event
io.socket.on('action', function(data) { io.socket.on('action', function(data) {
// Socket.io does not live inside the angular lifecycle, and thus Angular // Socket.io does not live inside the angular lifecycle, and thus Angular
// doesn't know new data has come in. Inside the socket.io callback, // doesn't know new data has come in. Inside the socket.io callback,
// as the last action, added $scope.apply() that lets angular know // as the last action, added $scope.apply() that lets angular know
// what data has updated, and refresh what needs to be refreshed. // what data has updated, and refresh what needs to be refreshed.
//only events (i) from a student (and ii)when a try is opened are managed // only events (i) from a student (and ii)when a try is opened are managed
if($scope.ws && $scope.actual_try.actions && $scope.paused == false){ if($scope.ws && $scope.actual_try.actions && $scope.paused == false){
switch(data.action){ switch(data.action){
case 'Add': case 'Add':
$scope.actual_try.actions.push(data); $scope.actual_try.actions.push(data);
break; break;
case 'Delete': case 'Delete':
$scope.actual_try.actions.push(data);
break;
case 'Select':
$scope.actual_try.actions.push(data);
break;
case 'Show':
// Empty actual try and push the first action of next try
if (!data.attributes.id_sup) {
$scope.load_tries($scope.selectedIns);
$scope.actual_try.actions = [];
$scope.actual_try.actions.push({ action: 'tryinit' });
}
else
$scope.actual_try.actions.push(data); $scope.actual_try.actions.push(data);
break;
case 'Select': break;
$scope.actual_try.actions.push(data);
break;
case 'Show':
// Empty actual try and push the first action of next try
if (!data.attributes.id_sup) {
$scope.load_tries($scope.selectedIns);
$scope.actual_try.actions = [];
$scope.actual_try.actions.push({ action: 'tryinit' });
}
else
$scope.actual_try.actions.push(data);
break;
}
} }
$scope.$apply();
}
$scope.$apply();
}); });
}); });
...@@ -31,11 +31,15 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -31,11 +31,15 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
// Flags for showing buttons according to role // Flags for showing buttons according to role
$scope.user = JSON.parse($window.sessionStorage.user); $scope.user = JSON.parse($window.sessionStorage.user);
// Identify if the user is office administrator
if ($scope.user.office) { if ($scope.user.office) {
if ($scope.user.office.admin === $scope.user.id) { if ($scope.user.office.admin === $scope.user.id) {
$scope.user.isAdmin = true; $scope.user.isAdmin = true;
} }
console.log("currentStudents: " + $scope.user.office.currentStudents);
console.log("maxStudents: " + $scope.user.office.maxStudents);
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 {
...@@ -47,15 +51,15 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -47,15 +51,15 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
$scope.user.office = { name: '' }; $scope.user.office = { name: '' };
} }
$scope.hidestudentadd = true;
// Get list of supervisor's students // Get list of supervisor's students
$http.get(config.backend + '/sup/' + $scope.user.id + '/students') $http.get(config.backend + '/sup/' + $scope.user.id + '/students')
.success(function (data) { .success(function (data) {
$scope.students = data; $scope.students = data;
}) })
.error(function () { .error(function () {
$translate('error_fetching_students').then(function (translation) { ngToast.danger({ content: $translate.instant('error_fetching_students') });
ngToast.danger({ content: translation });
});
}); });
// Reset form Student // Reset form Student
...@@ -81,15 +85,15 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -81,15 +85,15 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
$scope.hidestudentadd = true; $scope.hidestudentadd = true;
}; };
// Add Student /**
* Add Student
*/
$scope.add_student = function () { $scope.add_student = function () {
var student = $scope.formdatastudent; var student = $scope.formdatastudent;
// Validate password match // Validate password match
if (student.password_confirm.length && student.password !== student.password_confirm) { if (student.password_confirm.length && student.password !== student.password_confirm) {
$translate('password_match').then(function (translation) { ngToast.danger({ content: $translate.instant('password_match') });
ngToast.danger({ content: translation });
});
return; return;
} }
...@@ -101,40 +105,42 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -101,40 +105,42 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
$http.post(config.backend + '/stu', student) $http.post(config.backend + '/stu', student)
.success(function (data) { .success(function (data) {
$translate('student_added').then(function (translation) { ngToast.success({ content: $translate.instant('student_added') });
ngToast.success({ content: translation });
});
// default values // default values
data.student.supervision = 0; // by default, only related to office administrator data.supervision = 0; // by default, only related to office administrator
data.student.current_method = 'no_method'; data.current_method = $translate.instant('no_method');
data.student.current_instruction = 'no_instruction'; data.current_instruction = $translate.instant('no_instruction');
// Add to the list of students in view // Add to the list of students in view
$scope.students.push(data.student); $scope.students.push(data);
// Delete the fields of the form to avoid data binding // Delete the fields of the form to avoid data binding
// between the new element created and the form fields // between the new element created and the form fields
$scope.resetForm(); $scope.resetForm();
// Show the add form to new adding // Show the add form to new adding
$scope.hidestudentadd = false; $scope.hidestudentadd = true;
// Update counters
$scope.user.office.currentStudents += 1;
$scope.num_licenses_left -= 1;
}) })
.error(function (data) { .error(function (err) {
var errorMessage = 'student_not_added'; var errorMessage = 'student_not_added';
if (data && data.raw && data.raw.sqlState && data.raw.sqlState === '20001') { if (typeof err == "string" && err.search("Maximum number of enrolments reached") > 0)
errorMessage = 'max_licenses_reached'; errorMessage = 'max_licenses_reached';
} else if (data && data.status === 400) { else if (err && err.status === 400)
errorMessage = 'invalid_fields'; errorMessage = 'invalid_fields';
}
$translate(errorMessage).then(function (translation) { ngToast.danger({ content: $translate.instant(errorMessage) });
ngToast.danger({ content: translation });
});
}); });
}; };
// Delete Student /**
* Delete Student
*/
$scope.delete_student = function (student) { $scope.delete_student = function (student) {
$translate('confirmation').then(t => { $translate('confirmation').then(t => {
if ($window.confirm(t)) if ($window.confirm(t))
...@@ -153,11 +159,13 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl( ...@@ -153,11 +159,13 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
IOService.post('/stu/unsubscribe', { IOService.post('/stu/unsubscribe', {
action: 'unsubscribe' action: 'unsubscribe'
}); });
// Update counters
$scope.user.office.currentStudents -= 1;
$scope.num_licenses_left += 1;
}) })
.error(function () { .error(function () {
$translate('student_not_deleted').then(function (translation) { ngToast.danger({ content: $translate.instant('student_not_deleted') });
ngToast.danger({ content: translation });
});
}); });
}); });
}; };
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<!-- Table --> <!-- Table -->
<table id="table_students" class="table table-hover"> <table id="table_students" class="table table-hover">
<tr ng-repeat="student in students | filter:search_students | orderBy: 'name'"> <tr ng-repeat="student in students | filter:search_students | orderBy: ['surname', 'name']">
<td> <td>
<div class="thumbnail img_profile_small"> <div class="thumbnail img_profile_small">
<img ng-src="{{student.pic}}" alt="" title="" /> <img ng-src="{{student.pic}}" alt="" title="" />
...@@ -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 | translate}} <br />{{student.current_instruction | translate}}</p> <p> {{student.current_method}} <br />{{student.current_instruction}}</p>
</td> </td>
<td> <!-- BUTTONS --> <td> <!-- BUTTONS -->
......
...@@ -21,6 +21,8 @@ module.exports.pictogram = { ...@@ -21,6 +21,8 @@ module.exports.pictogram = {
* @return {String} Public url of user's avatar * @return {String} Public url of user's avatar
*/ */
getSupervisorAvatarUrl: function (filename) { getSupervisorAvatarUrl: function (filename) {
if (!filename)
filename = sails.config.pictogram.paths.deafultAvatarFileName;
return `/upload/supervisorAvatar/${filename}`; return `/upload/supervisorAvatar/${filename}`;
}, },
...@@ -30,6 +32,8 @@ module.exports.pictogram = { ...@@ -30,6 +32,8 @@ module.exports.pictogram = {
* @return {String} Public url of student's avatar * @return {String} Public url of student's avatar
*/ */
getStudentAvatarUrl: function (filename) { getStudentAvatarUrl: function (filename) {
if (!filename)
filename = sails.config.pictogram.paths.deafultAvatarFileName;
return `/upload/studentAvatar/${filename}`; return `/upload/studentAvatar/${filename}`;
}, },
......
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