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
7c9d9a5b
authored
Apr 18, 2017
by
Jose Antonio
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Working on scenes - collections controller
parent
7e362156
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
3 deletions
sails/src/api/controllers/SceneController.js
sails/src/api/hooks/events.js
sails/src/config/routes.js
sails/src/api/controllers/SceneController.js
View file @
7c9d9a5b
...
@@ -44,14 +44,29 @@ module.exports = {
...
@@ -44,14 +44,29 @@ module.exports = {
delete
scene
.
categories
;
//To avoid update these fields
delete
scene
.
categories
;
//To avoid update these fields
delete
scene
.
supervisor
;
delete
scene
.
supervisor
;
delete
scene
.
student
;
delete
scene
.
student
;
scene
.
name
=
req
.
param
(
'name'
)
||
instruction
.
name
;
scene
.
name
=
req
.
param
(
'name'
)
||
scene
.
name
;
scene
.
active
=
req
.
param
(
'active'
)
||
instruction
.
active
;
scene
.
active
=
req
.
param
(
'active'
)
||
scene
.
active
;
scene
.
save
(
function
(
error
)
{
scene
.
save
(
function
(
error
)
{
if
(
error
)
{
if
(
error
)
{
res
.
serverError
();
res
.
serverError
();
}
else
{
}
else
{
res
.
ok
(
scene
);
res
.
ok
(
scene
);
}
}
if
(
scene
.
active
){
Student
.
findOne
({
id
:
scene
.
student
})
.
then
(
student
=>
{
student
.
attributes
.
categories
=
scene
.
categories
;
delete
student
.
password
;
student
.
save
(
function
(
error
){
if
(
error
){
res
.
serverError
(
"Error saving student data"
);
}
else
{
return
res
.
ok
(
scene
);
}
})
});
}
});
});
})
})
.
catch
(
function
()
{
.
catch
(
function
()
{
...
@@ -100,6 +115,30 @@ module.exports = {
...
@@ -100,6 +115,30 @@ module.exports = {
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
return
res
.
serverError
(
"Error finding scene "
+
err
);
return
res
.
serverError
(
"Error finding scene "
+
err
);
});
});
}
},
//
// Logs a scene action and broadcast to anyone subscribed to this student
scene
:
function
(
req
,
res
)
{
var
action
=
req
.
param
(
'action'
);
var
scene
=
req
.
param
(
'scene'
);
var
roomName
=
'studentRoom'
+
scene
.
student
;
if
(
req
.
isSocket
)
{
sails
.
log
.
debug
(
"Inside scene - isSocket"
);
// Send to all sockets subscribed to this room except the own socket that sends the message
// Parameters: room, action, data to send, socket to avoid sending (the socket that send this)
sails
.
sockets
.
broadcast
(
roomName
,
'scene'
,
{
"action"
:
action
,
"scene"
:
scene
},
req
.
socket
);
res
.
json
({
msg
:
"Action "
+
action
+
" in scene "
+
scene
.
id
+
" from student "
+
scene
.
student
});
}
},
};
};
sails/src/api/hooks/events.js
View file @
7c9d9a5b
...
@@ -147,6 +147,22 @@ module.exports = function eventsHook(sails) {
...
@@ -147,6 +147,22 @@ module.exports = function eventsHook(sails) {
attributes
:
attributes
attributes
:
attributes
}
}
};
};
},
/**
* Scene is updated
* @param {action} type of the action
* @param {attributes} attributes of the action (id_stu, stu_picto)
* @return {Object} {name, data}
*/
scene
:
function
(
action
,
scene
)
{
return
{
name
:
'scene'
,
data
:
{
scene
:
scene
,
action
:
action
}
};
}
}
};
};
};
};
sails/src/config/routes.js
View file @
7c9d9a5b
...
@@ -73,6 +73,9 @@ module.exports.routes = {
...
@@ -73,6 +73,9 @@ module.exports.routes = {
'DELETE /picto/:id'
:
'PictoController.destroy'
,
'DELETE /picto/:id'
:
'PictoController.destroy'
,
'DELETE /picto/:id_sup/tag/:id_tag'
:
'PictoController.del_tag'
,
'DELETE /picto/:id_sup/tag/:id_tag'
:
'PictoController.del_tag'
,
/// Websocket request for propagating actions add, delete, modify...
'POST /scene'
:
'SceneController.scene'
,
'GET /scene/:id'
:
'SceneController.getScene'
,
'GET /scene/:id'
:
'SceneController.getScene'
,
'POST /scene/:id'
:
'SceneController.create'
,
'POST /scene/:id'
:
'SceneController.create'
,
'PUT /scene/:id'
:
'SceneController.update'
,
'PUT /scene/:id'
:
'SceneController.update'
,
...
...
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