forked from sahat/hackathon-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗿 Added a real-time Dashboard with Socket.io
- Loading branch information
Showing
8 changed files
with
167 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ lib-cov | |
*.pid | ||
*.gz | ||
*.swp | ||
*.css | ||
|
||
pids | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* GET / | ||
* Home page. | ||
*/ | ||
|
||
exports.getDashboard = function(req, res) { | ||
res.render('dashboard', { | ||
title: 'Dashboard' | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
extends layout | ||
|
||
block content | ||
|
||
.row | ||
.well.col-md-2#connections | ||
h3 Right Now | ||
p 0 | ||
h5 active visitors | ||
.col-md-10 | ||
legend Real Time Activity | ||
table#visits.table.table-bordered.table-striped.table-condensed | ||
thead | ||
tr | ||
td URL | ||
td IP | ||
td Timestamp | ||
tbody | ||
legend Page Views | ||
table#pageViews.table.table-bordered.table-striped.table-condensed | ||
thead | ||
tr | ||
td URL | ||
td Page Views | ||
tbody | ||
|
||
script. | ||
var pages = {}; | ||
var lastPageId = 0; | ||
socket.on('connect', function () { | ||
console.log('Socket connected'); | ||
socket.on('pageview', function (msg) { | ||
console.log('Connections: ' + msg.connections); | ||
$('#connections > p').html(msg.connections - 1); // -1 since we don't count our own dashboard connection | ||
if (msg.url) { | ||
if ($('#visits tr').length > 10) { | ||
$('#visits tr:last').remove(); | ||
} | ||
$('#visits tbody').prepend('<tr><td>' + msg.url + '</td><td>' + msg.ip + '</td><td>' + msg.timestamp + '</td></tr>'); | ||
if (pages[msg.url]) { | ||
pages[msg.url].views = pages[msg.url].views + 1; | ||
$('#page' + pages[msg.url].pageId).html(pages[msg.url].views); | ||
} else { | ||
pages[msg.url] = {views: 1, pageId: ++lastPageId}; | ||
$('#pageViews tbody').append('<tr><td>' + msg.url + '</td><td id="page' + lastPageId + '">1</td></tr>'); | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0a632de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can i use socket.io in the controller...?