cleaning categories code

parent 23dd7bae
...@@ -93,8 +93,6 @@ module.exports = { ...@@ -93,8 +93,6 @@ module.exports = {
id_cat: null, id_cat: null,
coord_x: null, coord_x: null,
coord_y: null, coord_y: null,
free_category_coord_x: null,
free_category_coord_y: null,
status: 'invisible', status: 'invisible',
highlight: false, highlight: false,
color: null, color: null,
...@@ -115,20 +113,16 @@ module.exports = { ...@@ -115,20 +113,16 @@ module.exports = {
!isFinite(validAttributes.id_cat)) { !isFinite(validAttributes.id_cat)) {
delete validAttributes.id_cat; delete validAttributes.id_cat;
} }
['coord_x', 'free_category_coord_x'].forEach((attribute) => { if (typeof validAttributes.coord_x !== 'number' ||
if (typeof validAttributes[attribute] !== 'number' || validAttributes.coord_x < 0 ||
validAttributes[attribute] < 0 || validAttributes.coord_x > 4) {
validAttributes[attribute] > 4) { delete validAttributes.coord_x;
delete validAttributes[attribute];
} }
}); if (typeof validAttributes.coord_y !== 'number' ||
['coord_y', 'free_category_coord_y'].forEach((attribute) => { validAttributes.coord_y < 0 ||
if (typeof validAttributes[attribute] !== 'number' || validAttributes.coord_y > 9) {
validAttributes[attribute] < 0 || delete validAttributes.coord_y;
validAttributes[attribute] > 9) {
delete validAttributes[attribute];
} }
});
if (!((/^(invisible|enabled|disabled)$/).test(validAttributes.status))) { if (!((/^(invisible|enabled|disabled)$/).test(validAttributes.status))) {
delete validAttributes.status; delete validAttributes.status;
} }
......
...@@ -582,8 +582,7 @@ module.exports = { ...@@ -582,8 +582,7 @@ module.exports = {
' (json_extract(attributes, \'$.id_cat\') LIKE \'null\' AND ' + ' (json_extract(attributes, \'$.id_cat\') LIKE \'null\' AND ' +
' json_extract(attributes, \'$.coord_y\') = 0 OR ' + ' json_extract(attributes, \'$.coord_y\') = 0 OR ' +
' json_extract(attributes, \'$.id_cat\') NOT LIKE \'null\' AND ' + ' json_extract(attributes, \'$.id_cat\') NOT LIKE \'null\' AND ' +
' json_extract(attributes, \'$.coord_y\') >= 0 OR ' + ' json_extract(attributes, \'$.coord_y\') >= 0);'
' json_extract(attributes, \'$.free_category_coord_y\') NOT LIKE \'null\');'
; ;
StuPicto.query(query, function(err, result) { StuPicto.query(query, function(err, result) {
......
...@@ -25,38 +25,33 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -25,38 +25,33 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
picto: { picto: {
id: null, id: null,
uri: '/app/img/empty.gif', uri: '/app/img/empty.gif',
category: null,
source: 1, source: 1,
owner: null, owner: null,
tags: null tags: null
}, },
attributes: { attributes: {
id_cat: null,
coord_x: null, coord_x: null,
coord_y: null, coord_y: null,
free_category_coord_x: null,
free_category_coord_y: null,
status: 'invisible', status: 'invisible',
highlight: false, highlight: false,
color: null, color: null,
expression: null expression: null
} }
}; };
$scope.showFreeCategory = !$scope.studentData.attributes.categories;
$scope.nav.tab = 'collections'; $scope.nav.tab = 'collections';
$scope.freeCategoryPictos = null; $scope.mainGrid = null;
$scope.loadingPictos = true; $scope.loadingPictos = true;
$scope.viewingGrid = null; $scope.viewingGrid = null;
$scope.gridsList = null; $scope.gridsList = null;
$scope.newGridName = ""; $scope.newGridName = "";
// function to make category colores brighter // function to make category colores brighter
$scope.shadeColor = function (color, percent) { /*$scope.shadeColor = function (color, percent) {
if (!color) if (!color)
return; return;
var f=parseInt(color.slice(1),16),t=percent<0?0:255,p=percent<0?percent*-1:percent,R=f>>16,G=f>>8&0x00FF,B=f&0x0000FF; var f=parseInt(color.slice(1),16),t=percent<0?0:255,p=percent<0?percent*-1:percent,R=f>>16,G=f>>8&0x00FF,B=f&0x0000FF;
return "#"+(0x1000000+(Math.round((t-R)*p)+R)*0x10000+(Math.round((t-G)*p)+G)*0x100+(Math.round((t-B)*p)+B)).toString(16).slice(1); return "#"+(0x1000000+(Math.round((t-R)*p)+R)*0x10000+(Math.round((t-G)*p)+G)*0x100+(Math.round((t-B)*p)+B)).toString(16).slice(1);
}; };*/
/* /*
* Generates the grid of pictos with empty ones * Generates the grid of pictos with empty ones
...@@ -81,18 +76,14 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -81,18 +76,14 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
*/ */
function placePicto(picto) { function placePicto(picto) {
var freeCategoryPositionX = picto.attributes.free_category_coord_x; var positionX = picto.attributes.coord_x;
var freeCategoryPositionY = picto.attributes.free_category_coord_y; var positionY = picto.attributes.coord_y;
var category;
// Fill with grid (if not done before) // Fill with grid (if not done before)
$scope.freeCategoryPictos = $scope.freeCategoryPictos || generateGrid(); $scope.mainGrid = $scope.mainGrid || generateGrid();
// Categories disabled if (positionX !== null && positionY !== null) {
if (typeof freeCategoryPositionX === 'number' && $scope.mainGrid[positionX][positionY] = picto;
typeof freeCategoryPositionY === 'number') {
$scope.freeCategoryPictos[freeCategoryPositionX][freeCategoryPositionY] = picto;
} }
}; };
...@@ -101,12 +92,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -101,12 +92,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
*/ */
$scope.showActiveGrid = function (grid) { $scope.showActiveGrid = function (grid) {
$scope.loadingPictos = true; $scope.loadingPictos = true;
$scope.freeCategoryPictos = $scope.freeCategoryPictos || generateGrid(); $scope.mainGrid = $scope.mainGrid || generateGrid();
$http.get(config.backend + '/stu/' + $scope.studentData.id + '/activeGrid') $http.get(config.backend + '/stu/' + $scope.studentData.id + '/activeGrid')
.success(function (activeGrid) { .success(function (activeGrid) {
//console.log("show activegrid" , activeGrid);
$scope.showFreeCategory = !activeGrid.categories;
activeGrid.name = $translate.instant(activeGrid.name); activeGrid.name = $translate.instant(activeGrid.name);
$scope.viewingGrid = activeGrid; $scope.viewingGrid = activeGrid;
activeGrid.pictos.forEach(placePicto); activeGrid.pictos.forEach(placePicto);
...@@ -125,11 +114,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -125,11 +114,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
*/ */
$scope.showGrid = function (idGrid) { $scope.showGrid = function (idGrid) {
$scope.loadingPictos = true; $scope.loadingPictos = true;
$scope.freeCategoryPictos = generateGrid(); $scope.mainGrid = generateGrid();
$http.get(config.backend + '/grid/' + idGrid) $http.get(config.backend + '/grid/' + idGrid)
.success(function (grid) { .success(function (grid) {
$scope.showFreeCategory = !grid.categories;
grid.name = $translate.instant(grid.name); grid.name = $translate.instant(grid.name);
$scope.viewingGrid = grid; $scope.viewingGrid = grid;
...@@ -171,6 +159,8 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -171,6 +159,8 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
return; return;
if(!grid.active){ // only delete if grid not active if(!grid.active){ // only delete if grid not active
// Delete action
$http.delete(config.backend + '/grid/' + grid.id + '/stu/' + $scope.studentData.id) $http.delete(config.backend + '/grid/' + grid.id + '/stu/' + $scope.studentData.id)
.success(function () { .success(function () {
...@@ -193,6 +183,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -193,6 +183,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}).error(function () { }).error(function () {
ngToast.warning($translate.instant('grid_already_deleted')); ngToast.warning($translate.instant('grid_already_deleted'));
}); });
} else { // if grid active, show warning } else { // if grid active, show warning
ngToast.warning($translate.instant('cant_delete_active_grid')); ngToast.warning($translate.instant('cant_delete_active_grid'));
} }
...@@ -205,12 +196,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -205,12 +196,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$http.put(config.backend + '/grid/' + grid.id + '/stu/' + $scope.studentData.id, { $http.put(config.backend + '/grid/' + grid.id + '/stu/' + $scope.studentData.id, {
name: grid.name, name: grid.name,
id_stu:grid.student}) id_stu:grid.student
})
.success(function (grid) { .success(function (grid) {
var data= { var data= {
id: grid.id, id: grid.id,
name: grid.name, name: grid.name,
categories: grid.categories,
student: grid.student, student: grid.student,
supervisor: grid.supervisor}; supervisor: grid.supervisor};
...@@ -267,15 +259,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -267,15 +259,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
/** /**
* Delete picto * Delete picto
*/ */
$scope.deleteFreePicto = function (studentPicto) { $scope.deletePicto = function (studentPicto) {
if (!$window.confirm($translate.instant('confirmation'))) if (!$window.confirm($translate.instant('confirmation')))
return; return;
$http.delete(config.backend + '/stu/' + $scope.studentData.id + '/picto/' + studentPicto.id) $http.delete(config.backend + '/stu/' + $scope.studentData.id + '/picto/' + studentPicto.id)
.success(function () { .success(function () {
$scope.freeCategoryPictos $scope.mainGrid[studentPicto.attributes.coord_x][studentPicto.attributes.coord_y] = $scope.emptyStudentPicto;
[studentPicto.attributes.free_category_coord_x]
[studentPicto.attributes.free_category_coord_y] = $scope.emptyStudentPicto;
io.socket.post('/stu/vocabulary', { io.socket.post('/stu/vocabulary', {
action: 'delete', action: 'delete',
...@@ -332,18 +322,18 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -332,18 +322,18 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
var studentPictoA; var studentPictoA;
var studentPictoB; var studentPictoB;
currentGrid = $scope.freeCategoryPictos; currentGrid = $scope.mainGrid;
studentPictoA = currentGrid[studentPictoAPositionX][studentPictoAPositionY]; studentPictoA = currentGrid[studentPictoAPositionX][studentPictoAPositionY];
studentPictoB = currentGrid[studentPictoBPositionX][studentPictoBPositionY]; studentPictoB = currentGrid[studentPictoBPositionX][studentPictoBPositionY];
if (studentPictoA !== $scope.emptyStudentPicto) { if (studentPictoA !== $scope.emptyStudentPicto) {
studentPictoA.attributes.free_category_coord_x = studentPictoBPositionX; studentPictoA.attributes.coord_x = studentPictoBPositionX;
studentPictoA.attributes.free_category_coord_y = studentPictoBPositionY; studentPictoA.attributes.coord_y = studentPictoBPositionY;
} }
if (studentPictoB !== $scope.emptyStudentPicto) { if (studentPictoB !== $scope.emptyStudentPicto) {
studentPictoB.attributes.free_category_coord_x = studentPictoAPositionX; studentPictoB.attributes.coord_x = studentPictoAPositionX;
studentPictoB.attributes.free_category_coord_y = studentPictoAPositionY; studentPictoB.attributes.coord_y = studentPictoAPositionY;
} }
currentGrid[studentPictoAPositionX][studentPictoAPositionY] = studentPictoB; currentGrid[studentPictoAPositionX][studentPictoAPositionY] = studentPictoB;
...@@ -407,12 +397,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -407,12 +397,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// Send the picto to the server // Send the picto to the server
$http.post(config.backend + '/stu/' + $scope.studentData.id + '/picto/' + pictoId, { $http.post(config.backend + '/stu/' + $scope.studentData.id + '/picto/' + pictoId, {
attributes: { attributes: {
id_cat: null, coord_x: col,
coord_x: null, coord_y: row,
coord_y: null, status: 'enabled'
status: 'enabled',
free_category_coord_x: $scope.showFreeCategory ? col : null,
free_category_coord_y: $scope.showFreeCategory ? row : null
}, },
id_grid: $scope.viewingGrid.id id_grid: $scope.viewingGrid.id
}) })
...@@ -477,11 +464,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -477,11 +464,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
//$scope.showGrid(id_child_grid); //$scope.showGrid(id_child_grid);
$scope.loadingPictos = true; $scope.loadingPictos = true;
$scope.freeCategoryPictos = generateGrid(); $scope.mainGrid = generateGrid();
$http.get(config.backend + '/grid/' + id_child_grid) $http.get(config.backend + '/grid/' + id_child_grid)
.success(function (grid) { .success(function (grid) {
$scope.showFreeCategory = !grid.categories;
grid.name = $translate.instant(grid.name); grid.name = $translate.instant(grid.name);
$scope.viewingGrid = grid; $scope.viewingGrid = grid;
...@@ -552,14 +538,12 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -552,14 +538,12 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$http.post(config.backend + '/grid/stu/' + $scope.studentData.id, { $http.post(config.backend + '/grid/stu/' + $scope.studentData.id, {
name: name, name: name,
id_sup: $rootScope.user.id, id_sup: $rootScope.user.id,
categories: null,
id_stu: $scope.studentData.id id_stu: $scope.studentData.id
}) })
.success(function (grid) { .success(function (grid) {
var data = { var data = {
name: grid.name, name: grid.name,
active: false, active: false,
categories: null,
student: grid.student, student: grid.student,
supervisor: grid.supervisor supervisor: grid.supervisor
}; };
......
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
class="picto_options" class="picto_options"
ng-if="studentPicto !== emptyStudentPicto"> ng-if="studentPicto !== emptyStudentPicto">
<a <a
ng-click="deleteFreePicto(studentPicto)" ng-click="deletePicto(studentPicto)"
class="picto_remove" class="picto_remove"
title="{{ 'delete' | translate}}"> title="{{ 'delete' | translate}}">
<i class="color_red glyphicon glyphicon-remove-circle" aria-hidden="true"></i> <i class="color_red glyphicon glyphicon-remove-circle" aria-hidden="true"></i>
......
...@@ -319,9 +319,7 @@ describe('Student API', function () { ...@@ -319,9 +319,7 @@ describe('Student API', function () {
id_cat: 12345, id_cat: 12345,
color: null, color: null,
highlight: false, highlight: false,
status: 'invisible', status: 'invisible'
free_category_coord_x: null,
free_category_coord_y: null
} }
}) })
.end(done); .end(done);
......
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