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
23dd7bae
authored
Oct 24, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
working on grid
parent
4ee8217a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
184 deletions
sails/src/assets/scripts/modules/student/controllers/collections.js
sails/src/assets/scripts/modules/student/controllers/newgrid.js
sails/src/assets/scripts/modules/student/views/collections.html
sails/src/assets/scripts/modules/student/views/pictoconfig.html
sails/src/assets/scripts/modules/student/controllers/collections.js
View file @
23dd7bae
...
...
@@ -44,29 +44,12 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
};
$scope
.
showFreeCategory
=
!
$scope
.
studentData
.
attributes
.
categories
;
$scope
.
nav
.
tab
=
'collections'
;
$scope
.
selectedCategory
=
$scope
.
emptyStudentPicto
;
$scope
.
studentPictos
=
{};
$scope
.
freeCategoryPictos
=
null
;
$scope
.
loadingPictos
=
true
;
$scope
.
viewingGrid
=
null
;
$scope
.
gridsList
=
null
;
$scope
.
newGridCat
=
null
;
$scope
.
newGridName
=
""
;
$scope
.
isCategory
=
function
(
studentPicto
)
{
return
studentPicto
.
attributes
.
id_cat
===
null
&&
studentPicto
.
attributes
.
coord_y
!==
0
&&
typeof
studentPicto
.
attributes
.
free_category_coord_x
!==
'number'
&&
typeof
studentPicto
.
attributes
.
free_category_coord_y
!==
'number'
;
};
$scope
.
getCategoryId
=
function
(
studentPicto
)
{
return
$scope
.
isCategory
(
studentPicto
)
?
studentPicto
.
picto
.
id
:
studentPicto
.
attributes
.
id_cat
;
};
// function to make category colores brighter
$scope
.
shadeColor
=
function
(
color
,
percent
)
{
if
(
!
color
)
...
...
@@ -97,43 +80,32 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
* Places a picto in the grid
*/
function
placePicto
(
picto
)
{
var
positionX
=
picto
.
attributes
.
coord_x
;
var
positionY
=
picto
.
attributes
.
coord_y
;
var
freeCategoryPositionX
=
picto
.
attributes
.
free_category_coord_x
;
var
freeCategoryPositionY
=
picto
.
attributes
.
free_category_coord_y
;
var
category
;
// Fill with grid (if not done before)
$scope
.
freeCategoryPictos
=
$scope
.
freeCategoryPictos
||
generateGrid
();
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
=
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
||
generateGrid
();
// Categories disabled
if
(
typeof
freeCategoryPositionX
===
'number'
&&
typeof
freeCategoryPositionY
===
'number'
)
{
$scope
.
freeCategoryPictos
[
freeCategoryPositionX
][
freeCategoryPositionY
]
=
picto
;
}
// Categories enabled
if
(
positionX
!==
null
&&
positionY
!==
null
)
{
category
=
$scope
.
isCategory
(
picto
)
?
$scope
.
getCategoryId
(
$scope
.
emptyStudentPicto
)
:
$scope
.
getCategoryId
(
picto
);
$scope
.
studentPictos
[
category
]
=
$scope
.
studentPictos
[
category
]
||
generateGrid
();
$scope
.
studentPictos
[
category
][
positionX
][
positionY
]
=
picto
;
}
};
// get and show active grid
/**
* get and show active grid
*/
$scope
.
showActiveGrid
=
function
(
grid
)
{
$scope
.
loadingPictos
=
true
;
$scope
.
freeCategoryPictos
=
$scope
.
freeCategoryPictos
||
generateGrid
();
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
=
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
||
generateGrid
();
$http
.
get
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/activeGrid'
)
.
success
(
function
(
activeGrid
)
{
console
.
log
(
"show activegrid"
,
activeGrid
);
//
console.log("show activegrid" , activeGrid);
$scope
.
showFreeCategory
=
!
activeGrid
.
categories
;
activeGrid
.
name
=
$translate
.
instant
(
activeGrid
.
name
);
$scope
.
viewingGrid
=
activeGrid
;
...
...
@@ -148,14 +120,12 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
// Get a grid and show it
/**
* Get a grid and show it
*/
$scope
.
showGrid
=
function
(
idGrid
)
{
$scope
.
loadingPictos
=
true
;
//$scope.freeCategoryPictos = $scope.freeCategoryPictos || generateGrid();
// $scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] =
// $scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid();
$scope
.
freeCategoryPictos
=
generateGrid
();
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
=
generateGrid
();
$http
.
get
(
config
.
backend
+
'/grid/'
+
idGrid
)
.
success
(
function
(
grid
)
{
...
...
@@ -174,7 +144,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
// Load the grid list
/**
* Load the grid list
*/
$scope
.
loadGridsList
=
function
()
{
$http
.
get
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/grids'
)
.
success
(
function
(
grids
)
{
...
...
@@ -189,46 +161,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
// Show the pictograms of a category when it is clicked
$scope
.
show_category
=
function
(
studentPicto
)
{
if
(
$scope
.
isCategory
(
studentPicto
))
{
$scope
.
selectedCategory
=
studentPicto
;
$location
.
hash
(
'picto-category-grid'
);
$anchorScroll
();
}
};
// Delete student picto
$scope
.
delete_picto
=
function
(
studentPicto
)
{
$translate
(
'confirmation'
).
then
(
t
=>
{
if
(
$window
.
confirm
(
t
))
{
$http
.
delete
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/picto/'
+
studentPicto
.
id
)
.
success
(
function
()
{
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
studentPicto
)]
[
studentPicto
.
attributes
.
coord_x
]
[
studentPicto
.
attributes
.
coord_y
]
=
$scope
.
emptyStudentPicto
;
io
.
socket
.
post
(
'/stu/vocabulary'
,
{
action
:
'delete'
,
attributes
:
{
id_stu
:
$scope
.
studentData
.
id
,
id_grid
:
$scope
.
viewingGrid
.
id
,
stu_picto
:
studentPicto
}
},
function
()
{});
$translate
(
'picto_removed'
).
then
(
function
(
translation
)
{
ngToast
.
success
({
content
:
translation
});
});
}).
error
(
function
()
{});
}
});
};
// Delete student grid, if is not active
//If grid is viewingGrid, load activeGrid
/**
* Delete student grid, if is not active
* If grid is viewingGrid, load activeGrid
*/
$scope
.
delete_grid
=
function
(
grid
)
{
if
(
!
$window
.
confirm
(
$translate
.
instant
(
'confirmation'
)))
...
...
@@ -262,7 +198,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}
};
// Update student grid
/**
* Update student grid
*/
$scope
.
update_grid
=
function
(
grid
)
{
$http
.
put
(
config
.
backend
+
'/grid/'
+
grid
.
id
+
'/stu/'
+
$scope
.
studentData
.
id
,
{
...
...
@@ -287,7 +225,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}).
error
(
function
()
{});
};
// Activate student grid
/**
* Activate student grid
*/
$scope
.
activate_grid
=
function
(
grid
)
{
$http
.
put
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/activeGrid/'
+
grid
.
id
,
{
id_grid
:
grid
.
id
})
...
...
@@ -304,7 +244,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}).
error
(
function
()
{});
};
// Duplicate viewing grid
/**
* Duplicate viewing grid
*/
$scope
.
copy_grid
=
function
()
{
$http
.
get
(
config
.
backend
+
'/grid/'
+
$scope
.
viewingGrid
.
id
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/copy'
)
...
...
@@ -322,6 +264,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
};
/**
* Delete picto
*/
$scope
.
deleteFreePicto
=
function
(
studentPicto
)
{
if
(
!
$window
.
confirm
(
$translate
.
instant
(
'confirmation'
)))
return
;
...
...
@@ -345,8 +290,11 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}).
error
(
function
()
{});
};
// View student picto
/**
* View student picto
*/
$scope
.
view_picto
=
function
(
studentPicto
)
{
if
(
studentPicto
.
attributes
.
status
===
'enabled'
)
{
studentPicto
.
attributes
.
status
=
'disabled'
;
}
else
if
(
studentPicto
.
attributes
.
status
===
'disabled'
)
{
...
...
@@ -370,6 +318,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}).
error
(
function
()
{});
};
/**
* Drag and drop
*/
$scope
.
handleDrop
=
function
(
originId
,
destinationId
)
{
var
studentPictoAElement
=
document
.
getElementById
(
originId
);
var
studentPictoBElement
=
document
.
getElementById
(
destinationId
);
...
...
@@ -381,16 +332,11 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
var
studentPictoA
;
var
studentPictoB
;
if
(
$scope
.
showFreeCategory
)
{
currentGrid
=
$scope
.
freeCategoryPictos
;
}
else
{
currentGrid
=
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)];
}
studentPictoA
=
currentGrid
[
studentPictoAPositionX
][
studentPictoAPositionY
];
studentPictoB
=
currentGrid
[
studentPictoBPositionX
][
studentPictoBPositionY
];
if
(
$scope
.
showFreeCategory
)
{
if
(
studentPictoA
!==
$scope
.
emptyStudentPicto
)
{
studentPictoA
.
attributes
.
free_category_coord_x
=
studentPictoBPositionX
;
studentPictoA
.
attributes
.
free_category_coord_y
=
studentPictoBPositionY
;
...
...
@@ -399,16 +345,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
studentPictoB
.
attributes
.
free_category_coord_x
=
studentPictoAPositionX
;
studentPictoB
.
attributes
.
free_category_coord_y
=
studentPictoAPositionY
;
}
}
else
{
if
(
studentPictoA
!==
$scope
.
emptyStudentPicto
)
{
studentPictoA
.
attributes
.
coord_x
=
studentPictoBPositionX
;
studentPictoA
.
attributes
.
coord_y
=
studentPictoBPositionY
;
}
if
(
studentPictoB
!==
$scope
.
emptyStudentPicto
)
{
studentPictoB
.
attributes
.
coord_x
=
studentPictoAPositionX
;
studentPictoB
.
attributes
.
coord_y
=
studentPictoAPositionY
;
}
}
currentGrid
[
studentPictoAPositionX
][
studentPictoAPositionY
]
=
studentPictoB
;
currentGrid
[
studentPictoBPositionX
][
studentPictoBPositionY
]
=
studentPictoA
;
...
...
@@ -440,62 +376,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
//
// Change category's pictogram
//
$scope
.
change_category
=
function
(
picto_cat
)
{
var
modalInstance
=
$modal
.
open
({
animation
:
true
,
templateUrl
:
'modules/student/views/addpicto.html'
,
controller
:
'AddPictoCtrl'
,
size
:
'lg'
,
resolve
:
{
student
:
function
()
{
return
$scope
.
studentData
;
},
supervisor
:
function
()
{
return
$rootScope
.
user
;
},
onlyOwn
:
function
()
{
return
false
;
}
}
});
// Returned data from the modal window
modalInstance
.
result
.
then
(
function
(
pictoId
)
{
if
(
!
pictoId
)
return
;
$http
.
put
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/cat'
,
{
prev_id_stu_pic
:
picto_cat
.
id
,
new_id_pic
:
pictoId
})
.
success
(
function
(
studentPicto
)
{
$scope
.
showGrid
(
$scope
.
viewingGrid
.
id
);
//Reload selectedCategory data
$scope
.
selectedCategory
=
studentPicto
;
// notify
io
.
socket
.
post
(
'/stu/vocabulary'
,
{
action
:
'update_category'
,
attributes
:
{
id_stu
:
$scope
.
studentData
.
id
,
id_grid
:
$scope
.
viewingGrid
.
id
,
stu_picto
:
studentPicto
}
},
function
()
{});
})
.
error
(
function
()
{
ngToast
.
danger
({
content
:
$translate
.
instant
(
'error_updating_category'
)
});
});
});
};
//
// Adds a new pictogram
//
/**
* Adds a new pictogram
*/
$scope
.
open_add
=
function
(
col
,
row
,
mainCatGrid
)
{
var
modalInstance
=
$modal
.
open
({
animation
:
true
,
...
...
@@ -524,9 +407,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
:
(
$scope
.
showFreeCategory
||
mainCatGrid
)
?
null
:
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)
,
coord_x
:
$scope
.
showFreeCategory
?
null
:
co
l
,
coord_y
:
$scope
.
showFreeCategory
?
null
:
row
,
id_cat
:
null
,
coord_x
:
nul
l
,
coord_y
:
null
,
status
:
'enabled'
,
free_category_coord_x
:
$scope
.
showFreeCategory
?
col
:
null
,
free_category_coord_y
:
$scope
.
showFreeCategory
?
row
:
null
...
...
@@ -555,7 +438,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
// Modal window to manage picto tags
/**
* Modal window to manage picto tags
*/
$scope
.
open_tags
=
function
(
studentPicto
)
{
var
modalInstance
=
$modal
.
open
({
animation
:
true
,
...
...
@@ -581,14 +466,37 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
modalInstance
.
result
.
then
(
function
()
{});
};
/**
* Climb to child grid clicking on a picto
*/
$scope
.
child_grid
=
function
(
id_child_grid
){
// Check if picto have child grid
if
(
id_child_grid
==
null
)
return
;
$scope
.
showGrid
(
id_child_grid
);
// Show child grid
//$scope.showGrid(id_child_grid);
$scope
.
loadingPictos
=
true
;
$scope
.
freeCategoryPictos
=
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
;
grid
.
pictos
.
forEach
(
placePicto
);
$scope
.
loadingPictos
=
false
;
})
.
error
(
function
()
{
$scope
.
showActiveGrid
();
console
.
log
(
"La escena no existe"
);
});
};
// Modal window to open picto config
/**
* Modal window to open picto config
*/
$scope
.
open_config
=
function
(
studentPicto
)
{
console
.
log
(
studentPicto
);
var
modalInstance
=
$modal
.
open
({
...
...
@@ -623,7 +531,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
// Modal window to create grids
/**
* Modal window to create grids
*/
$scope
.
open_new_grid
=
function
()
{
var
modalInstance
=
$modal
.
open
({
animation
:
true
,
...
...
@@ -642,14 +552,14 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$http
.
post
(
config
.
backend
+
'/grid/stu/'
+
$scope
.
studentData
.
id
,
{
name
:
name
,
id_sup
:
$rootScope
.
user
.
id
,
categories
:
$scope
.
newGridCat
,
categories
:
null
,
id_stu
:
$scope
.
studentData
.
id
})
.
success
(
function
(
grid
)
{
var
data
=
{
name
:
grid
.
name
,
active
:
false
,
categories
:
grid
.
categories
,
categories
:
null
,
student
:
grid
.
student
,
supervisor
:
grid
.
supervisor
};
...
...
sails/src/assets/scripts/modules/student/controllers/newgrid.js
View file @
23dd7bae
...
...
@@ -14,8 +14,6 @@ dashboardControllers.controller('NewGridCtrl', function (
ngToast
)
{
$scope
.
close
=
function
(
name
)
{
$modalInstance
.
close
(
name
);
};
...
...
sails/src/assets/scripts/modules/student/views/collections.html
View file @
23dd7bae
...
...
@@ -128,16 +128,8 @@
<hr>
<div
class=
"text-center"
>
<div
class=
"btn-group text-left"
title=
"{{ 'add' | translate}}"
>
<button
type=
"button"
class=
"btn btn-success dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
>
<i
class=
"fa fa-plus"
aria-hidden=
"true"
></i>
</button>
<ul
class=
"dropdown-menu"
>
<li><a
ng-click=
"newGridCat=true;open_new_grid()"
>
{{ 'new_grid_with_categories' | translate}}
</a></li>
<li><a
ng-click=
"newGridCat=false;open_new_grid()"
>
{{ 'new_grid_without_categories' | translate}}
</a></li>
</ul>
</div>
<button
type=
"button"
class=
"btn btn-primary"
ng-click=
"copy_grid()"
title=
"{{ 'duplicate' | translate}}"
><i
class=
"fa fa-files-o"
aria-hidden=
"true"
></i></button>
<button
type=
"button"
class=
"btn btn-success"
ng-click=
"open_new_grid()"
aria-expanded=
"false"
><i
class=
"fa fa-plus"
aria-hidden=
"true"
></i></button>
<button
type=
"button"
class=
"btn btn-primary"
ng-click=
"copy_grid()"
title=
"{{ 'duplicate' | translate}}"
><i
class=
"fa fa-files-o"
aria-hidden=
"true"
></i></button>
<button
type=
"button"
class=
"btn btn-danger"
ng-click=
"delete_grid(viewingGrid)"
title=
"{{ 'delete' | translate}}"
><i
class=
"fa fa-trash"
aria-hidden=
"true"
></i></button>
</div>
</div>
...
...
sails/src/assets/scripts/modules/student/views/pictoconfig.html
View file @
23dd7bae
...
...
@@ -38,13 +38,6 @@
</div>
<div
class=
"row"
>
<div
class=
"col-md-6"
>
<!-- <div class="checkbox">
<select class="form-control" data-toggle="toggle" ng-model="studentPicto.attributes.legend" ng-change="update_properties()">
<option value="none" selected>Sin leyenda</option>
<option value="normal">Leyenda normal</option>
<option value="full">Solo leyenda</option>
</select>
</div> -->
<input
type=
"radio"
ng-model=
"studentPicto.attributes.legend"
value=
"none"
>
<span
translate
>
legend_none
</span>
<br/>
...
...
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