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
8d0f2c3d
authored
Apr 19, 2017
by
Jose Antonio
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Working - Duplicate scene
parent
a763dfc5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
3 deletions
sails/src/api/controllers/SceneController.js
sails/src/api/controllers/StudentController.js
sails/src/assets/scripts/modules/student/controllers/collections.js
sails/src/config/policies.js
sails/src/config/routes.js
sails/src/api/controllers/SceneController.js
View file @
8d0f2c3d
...
...
@@ -117,6 +117,50 @@ module.exports = {
});
},
/**
* Copies a scene with its stu_pictos
* @param {request} req {} (id of source scene)
*/
duplicate
:
function
(
req
,
res
){
Scene
.
findOne
({
id
:
req
.
params
.
id
})
.
populate
(
'stuPictos'
).
then
(
function
(
scene
){
Scene
.
create
({
name
:
scene
.
name
,
active
:
false
,
categories
:
scene
.
categories
,
supervisor
:
scene
.
supervisor
,
student
:
scene
.
student
}).
then
(
scene
=>
{
async
.
forEach
(
scene
.
stuPictos
,
function
(
stuPicto
,
cb
)
{
StuPicto
.
create
({
student
:
stuPicto
.
student
,
picto
:
stuPicto
.
picto
,
scene
:
scene
.
id
,
attributes
:
stuPicto
.
attributes
}).
catch
(
function
(
err
){
console
.
log
(
"Error creating stu_picto "
+
err
.
details
);
sails
.
log
.
error
(
err
.
details
);
});
},
function
(
err
)
{
// function called when loop is done
if
(
err
)
{
console
.
log
(
err
.
details
);
sails
.
log
.
error
(
err
.
details
);
return
res
.
json
({
'error'
:
err
.
details
});
}
else
return
res
.
ok
(
scene
);
});
}).
catch
(
function
(
err
){
return
res
.
serverError
(
"Error creating scene: "
+
err
);
});
});
},
//
// Logs a scene action and broadcast to anyone subscribed to this student
scene
:
function
(
req
,
res
)
{
...
...
sails/src/api/controllers/StudentController.js
View file @
8d0f2c3d
...
...
@@ -892,8 +892,9 @@ module.exports = {
/**
* Add an existing picto to the student's collection
* @param {request} req (with id_stu and id_picto as url parameters)
* @param {request} req (with id_s
cene,id_s
tu and id_picto as url parameters)
* {
* id_scene,
* id_stu,
* id_picto,
* attributes: { @see StuPicto.getValidAttributes() }
...
...
@@ -928,7 +929,7 @@ module.exports = {
add_picto
:
function
(
req
,
res
)
{
var
params
=
req
.
allParams
();
StuPicto
.
find
({
id_pic
:
params
.
id_picto
,
id_stu
:
params
.
id_stu
})
StuPicto
.
find
({
id_pic
:
params
.
id_picto
,
id_stu
:
params
.
id_stu
,
id_scene
:
params
.
id_scene
})
.
then
((
entries
)
=>
{
if
(
entries
&&
entries
.
length
>
0
)
{
var
err
=
new
Error
(
"Picto already in student's vocabulary"
);
...
...
sails/src/assets/scripts/modules/student/controllers/collections.js
View file @
8d0f2c3d
...
...
@@ -122,6 +122,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// get active scene
$scope
.
showActiveScene
=
function
(
scene
)
{
$scope
.
loadingPictos
=
true
;
$scope
.
freeCategoryPictos
=
$scope
.
freeCategoryPictos
||
generateGrid
();
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
=
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
||
generateGrid
();
...
...
@@ -143,7 +144,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// get active scene
$scope
.
showScene
=
function
(
idScene
)
{
$scope
.
loadingPictos
=
true
;
$scope
.
freeCategoryPictos
=
$scope
.
freeCategoryPictos
||
generateGrid
();
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
=
$scope
.
studentPictos
[
$scope
.
getCategoryId
(
$scope
.
selectedCategory
)]
||
generateGrid
();
...
...
@@ -283,6 +284,25 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
};
// Duplicate viewing scene
$scope
.
copy_scene
=
function
()
{
$http
.
get
(
config
.
backend
+
'/scene/'
+
$scope
.
viewingScene
.
id
+
'/copy'
)
.
success
(
function
(
newScene
)
{
io
.
socket
.
post
(
'/scene'
,
{
action
:
'add'
,
data
:
newScene
},
function
()
{});
$scope
.
loadScenesList
();
$translate
(
'scene_duplicated'
).
then
(
function
(
translation
)
{
ngToast
.
success
({
content
:
translation
});
});
}).
error
(
function
()
{});
};
$scope
.
deleteFreePicto
=
function
(
studentPicto
)
{
$translate
(
'confirmation'
).
then
(
t
=>
{
if
(
$window
.
confirm
(
t
))
{
...
...
sails/src/config/policies.js
View file @
8d0f2c3d
...
...
@@ -84,6 +84,7 @@ module.exports.policies = {
create
:
[
'tokenAuth'
,
'isSupervisorOfStudent'
],
update
:
[
'tokenAuth'
,
'isSupervisorOfStudent'
],
destroy
:
[
'tokenAuth'
,
'isSupervisorOfStudent'
],
duplicate
:
[
'tokenAuth'
,
'isSupervisorOfStudent'
],
getScene
:
[
'tokenAuth'
],
getStudentScenes
:
[
'tokenAuth'
],
scene
:
true
...
...
sails/src/config/routes.js
View file @
8d0f2c3d
...
...
@@ -77,6 +77,7 @@ module.exports.routes = {
'POST /scene'
:
'SceneController.scene'
,
'GET /scene/:id'
:
'SceneController.getScene'
,
'GET /scene/:id/copy'
:
'SceneController.duplicate'
,
'POST /scene/:id'
:
'SceneController.create'
,
'PUT /scene/:id'
:
'SceneController.update'
,
'DELETE /scene/:id'
:
'SceneController.destroy'
,
...
...
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