Andrew Tomaka
f5b4a55071
Implement a simple HTTP server to remove the dependancy on also running your own Apache or NGINX instance to host static content. The built-in HTTP server currently hosts four static files and will return a 404 error if a request does not match one of those four files.
66 lines
No EOL
2 KiB
HTML
66 lines
No EOL
2 KiB
HTML
<!doctype html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
<title>DBMonitor</title>
|
|
|
|
<link rel="stylesheet" href="css/style.css">
|
|
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.10/socket.io.min.js"></script>
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/coffee-script/1.3.3/coffee-script.min.js"></script>
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.5.0-dev/mustache.min.js"></script>
|
|
<script src="/js/jquery.mustache.js"></script>
|
|
|
|
<script type="text/coffeescript">
|
|
$.Mustache.load('./templates/views.html')
|
|
|
|
socket = io.connect '/', {
|
|
'reconnect': true,
|
|
'reconnection_delay': 500,
|
|
'max reconnection attempts': 25
|
|
}
|
|
|
|
socket.on 'connect', () ->
|
|
$('#disconnected').hide()
|
|
if $('#container tbody').children().length == 0
|
|
$('#empty').show()
|
|
|
|
socket.on 'disconnect', () ->
|
|
$('#disconnected').show()
|
|
$('#empty').hide()
|
|
|
|
socket.on 'error', (reason) ->
|
|
console.log 'Socket.io error', reason
|
|
|
|
socket.on 'update', (data) ->
|
|
if $('#container thead').children().length == 0
|
|
$('#container thead').html($.Mustache.render('header', getKeys(data)))
|
|
$('#empty').hide()
|
|
|
|
$('#container tbody').html($.Mustache.render('row', getValues(data)) + $('#container tbody').html())
|
|
|
|
while $('#container tbody').children().length > 20
|
|
$('#container tbody tr:last').remove()
|
|
|
|
getKeys = (data) ->
|
|
keys = []
|
|
keys.push key for key, value of data
|
|
{ 'labels': keys }
|
|
|
|
getValues = (data) ->
|
|
values = []
|
|
values.push value for key, value of data
|
|
{ 'values': values }
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="disconnected" class="down text-center">Not connected to the server. Retrying...</div>
|
|
<div id="empty" class="down text-center">Waiting to receive data from the server.</div>
|
|
<table id="container">
|
|
<thead></thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</body>
|
|
</html> |