Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e83306e8
authored
Oct 26, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
cleaning categories code
parent
23dd7bae
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
65 deletions
sails/src/api/models/StuPicto.js
sails/src/api/models/Student.js
sails/src/assets/scripts/modules/student/controllers/collections.js
sails/src/assets/scripts/modules/student/views/collections.html
sails/src/test/api/stu-spec.js
sails/src/api/models/StuPicto.js
View file @
e83306e8
...
...
@@ -93,8 +93,6 @@ module.exports = {
id_cat
:
null
,
coord_x
:
null
,
coord_y
:
null
,
free_category_coord_x
:
null
,
free_category_coord_y
:
null
,
status
:
'invisible'
,
highlight
:
false
,
color
:
null
,
...
...
@@ -115,20 +113,16 @@ module.exports = {
!
isFinite
(
validAttributes
.
id_cat
))
{
delete
validAttributes
.
id_cat
;
}
[
'coord_x'
,
'free_category_coord_x'
].
forEach
((
attribute
)
=>
{
if
(
typeof
validAttributes
[
attribute
]
!==
'number'
||
validAttributes
[
attribute
]
<
0
||
validAttributes
[
attribute
]
>
4
)
{
delete
validAttributes
[
attribute
];
}
});
[
'coord_y'
,
'free_category_coord_y'
].
forEach
((
attribute
)
=>
{
if
(
typeof
validAttributes
[
attribute
]
!==
'number'
||
validAttributes
[
attribute
]
<
0
||
validAttributes
[
attribute
]
>
9
)
{
delete
validAttributes
[
attribute
];
}
});
if
(
typeof
validAttributes
.
coord_x
!==
'number'
||
validAttributes
.
coord_x
<
0
||
validAttributes
.
coord_x
>
4
)
{
delete
validAttributes
.
coord_x
;
}
if
(
typeof
validAttributes
.
coord_y
!==
'number'
||
validAttributes
.
coord_y
<
0
||
validAttributes
.
coord_y
>
9
)
{
delete
validAttributes
.
coord_y
;
}
if
(
!
((
/^
(
invisible|enabled|disabled
)
$/
).
test
(
validAttributes
.
status
)))
{
delete
validAttributes
.
status
;
}
...
...
sails/src/api/models/Student.js
View file @
e83306e8
...
...
@@ -582,8 +582,7 @@ module.exports = {
' (json_extract(attributes, \'$.id_cat\') LIKE \'null\' AND '
+
' json_extract(attributes, \'$.coord_y\') = 0 OR '
+
' json_extract(attributes, \'$.id_cat\') NOT LIKE \'null\' AND '
+
' json_extract(attributes, \'$.coord_y\') >= 0 OR '
+
' json_extract(attributes, \'$.free_category_coord_y\') NOT LIKE \'null\');'
' json_extract(attributes, \'$.coord_y\') >= 0);'
;
StuPicto
.
query
(
query
,
function
(
err
,
result
)
{
...
...
sails/src/assets/scripts/modules/student/controllers/collections.js
View file @
e83306e8
...
...
@@ -25,38 +25,33 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
picto
:
{
id
:
null
,
uri
:
'/app/img/empty.gif'
,
category
:
null
,
source
:
1
,
owner
:
null
,
tags
:
null
},
attributes
:
{
id_cat
:
null
,
coord_x
:
null
,
coord_y
:
null
,
free_category_coord_x
:
null
,
free_category_coord_y
:
null
,
status
:
'invisible'
,
highlight
:
false
,
color
:
null
,
expression
:
null
}
};
$scope
.
showFreeCategory
=
!
$scope
.
studentData
.
attributes
.
categories
;
$scope
.
nav
.
tab
=
'collections'
;
$scope
.
freeCategoryPictos
=
null
;
$scope
.
mainGrid
=
null
;
$scope
.
loadingPictos
=
true
;
$scope
.
viewingGrid
=
null
;
$scope
.
gridsList
=
null
;
$scope
.
newGridName
=
""
;
// function to make category colores brighter
$scope
.
shadeColor
=
function
(
color
,
percent
)
{
/*
$scope.shadeColor = function (color, percent) {
if (!color)
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;
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
...
...
@@ -81,18 +76,14 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
*/
function
placePicto
(
picto
)
{
var
freeCategoryPositionX
=
picto
.
attributes
.
free_category_coord_x
;
var
freeCategoryPositionY
=
picto
.
attributes
.
free_category_coord_y
;
var
category
;
var
positionX
=
picto
.
attributes
.
coord_x
;
var
positionY
=
picto
.
attributes
.
coord_y
;
// Fill with grid (if not done before)
$scope
.
freeCategoryPictos
=
$scope
.
freeCategoryPictos
||
generateGrid
();
$scope
.
mainGrid
=
$scope
.
mainGrid
||
generateGrid
();
// Categories disabled
if
(
typeof
freeCategoryPositionX
===
'number'
&&
typeof
freeCategoryPositionY
===
'number'
)
{
$scope
.
freeCategoryPictos
[
freeCategoryPositionX
][
freeCategoryPositionY
]
=
picto
;
if
(
positionX
!==
null
&&
positionY
!==
null
)
{
$scope
.
mainGrid
[
positionX
][
positionY
]
=
picto
;
}
};
...
...
@@ -101,12 +92,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
*/
$scope
.
showActiveGrid
=
function
(
grid
)
{
$scope
.
loadingPictos
=
true
;
$scope
.
freeCategoryPictos
=
$scope
.
freeCategoryPictos
||
generateGrid
();
$scope
.
mainGrid
=
$scope
.
mainGrid
||
generateGrid
();
$http
.
get
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/activeGrid'
)
.
success
(
function
(
activeGrid
)
{
//console.log("show activegrid" , activeGrid);
$scope
.
showFreeCategory
=
!
activeGrid
.
categories
;
activeGrid
.
name
=
$translate
.
instant
(
activeGrid
.
name
);
$scope
.
viewingGrid
=
activeGrid
;
activeGrid
.
pictos
.
forEach
(
placePicto
);
...
...
@@ -125,11 +114,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
*/
$scope
.
showGrid
=
function
(
idGrid
)
{
$scope
.
loadingPictos
=
true
;
$scope
.
freeCategoryPictos
=
generateGrid
();
$scope
.
mainGrid
=
generateGrid
();
$http
.
get
(
config
.
backend
+
'/grid/'
+
idGrid
)
.
success
(
function
(
grid
)
{
$scope
.
showFreeCategory
=
!
grid
.
categories
;
grid
.
name
=
$translate
.
instant
(
grid
.
name
);
$scope
.
viewingGrid
=
grid
;
...
...
@@ -171,6 +159,8 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
return
;
if
(
!
grid
.
active
){
// only delete if grid not active
// Delete action
$http
.
delete
(
config
.
backend
+
'/grid/'
+
grid
.
id
+
'/stu/'
+
$scope
.
studentData
.
id
)
.
success
(
function
()
{
...
...
@@ -193,6 +183,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}).
error
(
function
()
{
ngToast
.
warning
(
$translate
.
instant
(
'grid_already_deleted'
));
});
}
else
{
// if grid active, show warning
ngToast
.
warning
(
$translate
.
instant
(
'cant_delete_active_grid'
));
}
...
...
@@ -205,12 +196,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$http
.
put
(
config
.
backend
+
'/grid/'
+
grid
.
id
+
'/stu/'
+
$scope
.
studentData
.
id
,
{
name
:
grid
.
name
,
id_stu
:
grid
.
student
})
id_stu
:
grid
.
student
})
.
success
(
function
(
grid
)
{
var
data
=
{
id
:
grid
.
id
,
name
:
grid
.
name
,
categories
:
grid
.
categories
,
student
:
grid
.
student
,
supervisor
:
grid
.
supervisor
};
...
...
@@ -267,15 +259,13 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
/**
* Delete picto
*/
$scope
.
delete
Free
Picto
=
function
(
studentPicto
)
{
$scope
.
deletePicto
=
function
(
studentPicto
)
{
if
(
!
$window
.
confirm
(
$translate
.
instant
(
'confirmation'
)))
return
;
$http
.
delete
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/picto/'
+
studentPicto
.
id
)
.
success
(
function
()
{
$scope
.
freeCategoryPictos
[
studentPicto
.
attributes
.
free_category_coord_x
]
[
studentPicto
.
attributes
.
free_category_coord_y
]
=
$scope
.
emptyStudentPicto
;
$scope
.
mainGrid
[
studentPicto
.
attributes
.
coord_x
][
studentPicto
.
attributes
.
coord_y
]
=
$scope
.
emptyStudentPicto
;
io
.
socket
.
post
(
'/stu/vocabulary'
,
{
action
:
'delete'
,
...
...
@@ -332,18 +322,18 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
var
studentPictoA
;
var
studentPictoB
;
currentGrid
=
$scope
.
freeCategoryPictos
;
currentGrid
=
$scope
.
mainGrid
;
studentPictoA
=
currentGrid
[
studentPictoAPositionX
][
studentPictoAPositionY
];
studentPictoB
=
currentGrid
[
studentPictoBPositionX
][
studentPictoBPositionY
];
if
(
studentPictoA
!==
$scope
.
emptyStudentPicto
)
{
studentPictoA
.
attributes
.
free_category_
coord_x
=
studentPictoBPositionX
;
studentPictoA
.
attributes
.
free_category_
coord_y
=
studentPictoBPositionY
;
studentPictoA
.
attributes
.
coord_x
=
studentPictoBPositionX
;
studentPictoA
.
attributes
.
coord_y
=
studentPictoBPositionY
;
}
if
(
studentPictoB
!==
$scope
.
emptyStudentPicto
)
{
studentPictoB
.
attributes
.
free_category_
coord_x
=
studentPictoAPositionX
;
studentPictoB
.
attributes
.
free_category_
coord_y
=
studentPictoAPositionY
;
studentPictoB
.
attributes
.
coord_x
=
studentPictoAPositionX
;
studentPictoB
.
attributes
.
coord_y
=
studentPictoAPositionY
;
}
currentGrid
[
studentPictoAPositionX
][
studentPictoAPositionY
]
=
studentPictoB
;
...
...
@@ -407,12 +397,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// Send the picto to the server
$http
.
post
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/picto/'
+
pictoId
,
{
attributes
:
{
id_cat
:
null
,
coord_x
:
null
,
coord_y
:
null
,
status
:
'enabled'
,
free_category_coord_x
:
$scope
.
showFreeCategory
?
col
:
null
,
free_category_coord_y
:
$scope
.
showFreeCategory
?
row
:
null
coord_x
:
col
,
coord_y
:
row
,
status
:
'enabled'
},
id_grid
:
$scope
.
viewingGrid
.
id
})
...
...
@@ -477,11 +464,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
//$scope.showGrid(id_child_grid);
$scope
.
loadingPictos
=
true
;
$scope
.
freeCategoryPictos
=
generateGrid
();
$scope
.
mainGrid
=
generateGrid
();
$http
.
get
(
config
.
backend
+
'/grid/'
+
id_child_grid
)
.
success
(
function
(
grid
)
{
$scope
.
showFreeCategory
=
!
grid
.
categories
;
grid
.
name
=
$translate
.
instant
(
grid
.
name
);
$scope
.
viewingGrid
=
grid
;
...
...
@@ -552,14 +538,12 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$http
.
post
(
config
.
backend
+
'/grid/stu/'
+
$scope
.
studentData
.
id
,
{
name
:
name
,
id_sup
:
$rootScope
.
user
.
id
,
categories
:
null
,
id_stu
:
$scope
.
studentData
.
id
})
.
success
(
function
(
grid
)
{
var
data
=
{
name
:
grid
.
name
,
active
:
false
,
categories
:
null
,
student
:
grid
.
student
,
supervisor
:
grid
.
supervisor
};
...
...
sails/src/assets/scripts/modules/student/views/collections.html
View file @
e83306e8
...
...
@@ -75,7 +75,7 @@
class=
"picto_options"
ng-if=
"studentPicto !== emptyStudentPicto"
>
<a
ng-click=
"delete
Free
Picto(studentPicto)"
ng-click=
"deletePicto(studentPicto)"
class=
"picto_remove"
title=
"{{ 'delete' | translate}}"
>
<i
class=
"color_red glyphicon glyphicon-remove-circle"
aria-hidden=
"true"
></i>
...
...
sails/src/test/api/stu-spec.js
View file @
e83306e8
...
...
@@ -319,9 +319,7 @@ describe('Student API', function () {
id_cat
:
12345
,
color
:
null
,
highlight
:
false
,
status
:
'invisible'
,
free_category_coord_x
:
null
,
free_category_coord_y
:
null
status
:
'invisible'
}
})
.
end
(
done
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment