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
3916a007
authored
Feb 23, 2017
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Weird pages when accessing pages without login fixed
parent
684534be
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
46 deletions
sails/src/api/hooks/events.js
sails/src/api/hooks/rooms.js
sails/src/assets/scripts/modules/student/controllers/student.js
sails/src/assets/scripts/modules/student/views/header.html
sails/src/assets/scripts/modules/supervisor/controllers/supervisor.js
sails/src/config/sockets.js
sails/src/api/hooks/events.js
View file @
3916a007
...
...
@@ -103,15 +103,16 @@ module.exports = function eventsHook(sails) {
/**
* Someone has subscribed/unsubscribed to/from a room. The number
* of subscribes is sent
* @param {number} subscriberCount Number of subscribers
* @param {Object} counts {
pcb_count: Number of subscribers from PCBs,
pdb_count: Number of subscribers from PDBs
}
* @return {Object} {name, data}
*/
roomSubscribersChange
:
function
(
subscriberCount
)
{
roomSubscribersChange
:
function
(
counts
)
{
return
{
name
:
'update_peers'
,
data
:
{
count
:
subscriberCount
}
data
:
counts
};
},
...
...
sails/src/api/hooks/rooms.js
View file @
3916a007
...
...
@@ -8,6 +8,8 @@
* @type {Object}
*/
var
socketRooms
=
{};
// {socketId => [roomId, ...]}
var
pcb_count
=
0
;
var
pdb_count
=
0
;
module
.
exports
=
function
roomsHook
(
sails
)
{
return
{
...
...
@@ -57,14 +59,19 @@ module.exports = function roomsHook (sails) {
// append to socketRooms
if
(
!
socketRooms
[
socket_id
])
socketRooms
[
socket_id
]
=
[
room
];
socketRooms
[
socket_id
]
=
[
{
room
:
room
,
ui
:
ui
}
];
else
socketRooms
[
socket_id
].
push
(
room
);
socketRooms
[
socket_id
].
push
({
room
:
room
,
ui
:
ui
});
if
(
ui
==
'PCB'
)
pcb_count
++
;
if
(
ui
==
'PDB'
)
pdb_count
++
;
// broadcast data
sails
.
hooks
.
events
.
broadcastEvent
(
room
,
sails
.
hooks
.
events
.
roomSubscribersChange
(
ids
.
length
)
sails
.
hooks
.
events
.
roomSubscribersChange
(
{
'pdb_count'
:
pcb_count
,
'pcb_count'
:
pdb_count
}
)
);
}
});
...
...
@@ -94,18 +101,23 @@ module.exports = function roomsHook (sails) {
sails
.
io
.
sockets
.
in
(
room
).
clients
(
function
(
error
,
ids
)
{
if
(
!
error
)
{
// broadcast event
sails
.
hooks
.
events
.
broadcastEvent
(
room
,
sails
.
hooks
.
events
.
roomSubscribersChange
(
ids
.
length
)
);
// look for the room the socket is subscribed to and remove it
if
(
socketRooms
[
sails
.
sockets
.
getId
(
socket
)])
{
var
index
=
socketRooms
[
sails
.
sockets
.
getId
(
socket
)].
indexOf
(
room
);
var
index
=
socketRooms
[
sails
.
sockets
.
getId
(
socket
)].
findIndex
(
x
=>
x
.
room
==
room
);
if
(
index
>
-
1
)
{
socketRooms
[
sails
.
sockets
.
getId
(
socket
)].
splice
(
index
,
1
);
if
(
socketRooms
[
sails
.
sockets
.
getId
(
socket
)][
index
].
ui
==
'PDB'
)
pdb_count
--
;
else
pcb_count
--
;
socketRooms
[
sails
.
sockets
.
getId
(
socket
)].
splice
(
index
,
1
);
// broadcast data
sails
.
hooks
.
events
.
broadcastEvent
(
room
,
sails
.
hooks
.
events
.
roomSubscribersChange
({
'pdb_count'
:
pcb_count
,
'pcb_count'
:
pdb_count
})
);
}
}
}
...
...
sails/src/assets/scripts/modules/student/controllers/student.js
View file @
3916a007
...
...
@@ -36,8 +36,8 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl(
name
:
''
},
stuSup
:
[],
num_peers
:
1
,
p
rev_num_peers
:
1
pcb_count
:
0
,
p
db_count
:
1
};
// For the user form data in setup section
...
...
@@ -52,13 +52,8 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl(
// WebSockets communication
//
io
.
socket
.
on
(
'update_peers'
,
function
(
data
)
{
// REMOVED (too invasive)
// $translate('num_peers').then(function (translation) {
// ngToast.success(translation + ': ' + data.count);
//});
$scope
.
studentData
.
prev_num_peers
=
$scope
.
studentData
.
num_peers
;
$scope
.
studentData
.
num_peers
=
data
.
count
;
console
.
log
(
'Usuarios conectados:'
+
$scope
.
studentData
.
num_peers
+
" previamente:"
+
$scope
.
studentData
.
prev_num_peers
);
$scope
.
studentData
.
pcb_count
=
data
.
pcb_count
;
$scope
.
studentData
.
pdb_count
=
data
.
pdb_count
;
$scope
.
$apply
();
});
...
...
sails/src/assets/scripts/modules/student/views/header.html
View file @
3916a007
...
...
@@ -27,20 +27,21 @@
</div>
</div>
<div
class=
"col-md-1"
>
<div
style=
"margin-left: 5px; margin-top: 10px"
class=
"text-left text-success"
ng-if=
"studentData.num_peers > 1"
popover=
"{{ 'num_peers' | translate }}"
popover-trigger=
"mouseenter"
>
<span
class=
"glyphicon glyphicon-transfer"
aria-hidden
></span>
{{studentData.num_peers}}
<div
style=
"margin-left: 5px; margin-top: 10px"
ng-class=
"{ 'text-left':true,
'text-success': studentData.pdb_count > 0,
'text-danger': studentData.pdb_count == 0}"
popover=
"{{ 'num_peers' | translate }}"
popover-trigger=
"mouseenter"
>
<i
class=
"fa fa-desktop"
aria-hidden=
"true"
></i>
{{studentData.pdb_count}}
</div>
<div
style=
"margin-left: 5px; margin-top: 10px"
class=
"text-left text-warning"
ng-if=
"studentData.num_peers == 1"
popover=
"{{ 'num_peers' | translate }}"
popover-trigger=
"mouseenter"
>
<span
class=
"glyphicon glyphicon-transfer"
aria-hidden
></span>
{{studentData.num_peers}}
</div>
<div
style=
"margin-left: 5px; margin-top: 10px"
class=
"text-left text-danger"
ng-if=
"studentData.num_peers == 0"
popover=
"{{ 'num_peers' | translate }}"
popover-trigger=
"mouseenter"
>
<span
class=
"glyphicon glyphicon-transfer"
aria-hidden=
"true"
></span>
{{studentData.num_peers}}
<div
style=
"margin-left: 5px; margin-top: 10px"
ng-class=
"{ 'text-left':true,
'text-success': studentData.pcb_count > 0,
'text-danger': studentData.pcb_count == 0}"
popover=
"{{ 'num_peers' | translate }}"
popover-trigger=
"mouseenter"
>
<i
class=
"fa fa-tablet"
aria-hidden=
"true"
></i>
{{studentData.pcb_count}}
</div>
</div>
</div>
...
...
sails/src/assets/scripts/modules/supervisor/controllers/supervisor.js
View file @
3916a007
...
...
@@ -17,6 +17,9 @@ dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl(
)
{
// Restore user data from session
if
(
!
$window
.
sessionStorage
.
user
)
return
$scope
.
logout
();
var
user
=
JSON
.
parse
(
$window
.
sessionStorage
.
user
);
// Assign values this way (like an object) to ensure it's the parent scope
...
...
sails/src/config/sockets.js
View file @
3916a007
...
...
@@ -36,14 +36,11 @@ module.exports.sockets = {
***************************************************************************/
afterDisconnect
:
function
(
session
,
socket
,
cb
)
{
var
rooms
=
sails
.
hooks
.
rooms
.
getRoom
(
socket
);
if
(
rooms
)
for
(
var
i
=
0
;
i
<
rooms
.
length
;
i
++
)
{
console
.
log
(
"Unubscribed room in socket afterDisconnect: "
+
rooms
[
i
]);
sails
.
hooks
.
rooms
.
unsubscribeFromRoom
(
rooms
[
i
],
socket
);
}
else
console
.
log
(
"Sockect disconnected without any room"
);
},
// Leave all rooms
var
rooms
=
sails
.
sockets
.
socketRooms
(
socket
);
for
(
var
i
=
0
;
i
<
rooms
.
length
;
i
++
)
sails
.
hooks
.
rooms
.
unsubscribeFromRoom
(
rooms
[
i
],
socket
);
},
/***************************************************************************
...
...
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