2
1
mirror of https://github.com/s00500/nodeMessageBoard.git synced 2024-12-03 17:51:29 +00:00

Added basic database delete page

This commit is contained in:
Lukas Bachschwell 2016-03-15 13:21:33 +01:00
parent 1df24799c5
commit ee2462a40c
5 changed files with 97 additions and 2 deletions

2
app.js
View File

@ -13,4 +13,6 @@ handle["/js/jquery-1.12.1.min"] = requestHandlers.sendJquery;
handle["/js/jquery-ui.js"] = requestHandlers.sendJqueryUI;
handle["/css/bootstrap.min.css"] = requestHandlers.sendBootstrap;
handle["/clear"] = requestHandlers.sendClear;
server.start(router.route,handle,debug);

View File

@ -71,8 +71,14 @@ body {
function initSocketIO()
{
iosocket = io.connect();
iosocket.on('clientrefresh', function() {
location.reload();
});
iosocket.on('onconnection', function() {
initButton();
iosocket.on('debugMessage', function(message) {
alert(message);
@ -81,9 +87,9 @@ body {
iosocket.on('config', function(phonenumber) {
mynumber = phonenumber;
$( "span.number" ).html(mynumber);
console.log(mynumber);
});
iosocket.on('newMessage', function(time,number,message,color) {
var censoredNumber = number.substring(0,3) + "********" +number.substring(number.length - 3, number.length);
var messages = document.getElementById('messagesBody');

62
clear.html Normal file
View File

@ -0,0 +1,62 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<html>
<head>
<title>Clear Board</title>
<link rel='stylesheet' href='sprite/emoji.css' >
<link rel="stylesheet" href="/css/bootstrap.min.css" />
<script src="/js/jquery-1.12.1.min"></script>
<script src="/js/jquery-ui.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var iosocket;
function initSocketIO()
{
iosocket = io.connect();
iosocket.on('onconnection', function() {
iosocket.on('debugMessage', function(message) {
alert(message);
});
});
}
window.onload = function() {
initSocketIO();
};
$(document).ready(function() {
$('#clear').click(function() {
var number = $('#number').val();
iosocket.emit('clear',number);
});
$('#refresh').click(function() {
iosocket.emit('refreshClients');
});
});
</script>
</head>
<body>
<div style="text-align:center;" >
<div id="wrap">
<div id="btnHolder">
<h2>Functions</h2>
<input type="number" id="number" value="1" min="1"/><label for="number">Number</label><br>
<input type="button" id="clear" value="clear"/>
<br>
<input type="button" id="refresh" value="refresh"/>
<div id="debugOut"> </div>
</div>
</div>
</body>
</html>

View File

@ -47,6 +47,16 @@ function sendJqueryUI(response) {
response.end(html);
}
function sendClear(response) {
console.log("Request handler 'clear' was called.");
response.writeHead(200, {"Content-Type": "text/html"});
var html = fs.readFileSync(__dirname + "/clear.html")
response.end(html);
}
exports.sendClear = sendClear;
exports.sendBootstrap = sendBootstrap;
exports.sendJqueryUI = sendJqueryUI;

View File

@ -68,6 +68,16 @@ function initSocketIO(httpServer,debug)
console.log("user connected");
socket.emit('onconnection');
socket.on('clear', function(number) {
var index = db.object.messages.length - 1;
db.object.messages.splice(index,1);
db.write();
console.log('removed entry ' + number)
});
socket.on('getConfig', function(data) {
var number = config('mainConfig').chain().find({ param: 'mynumber' }).value()['value'];
socket.emit('config',number);
@ -78,6 +88,11 @@ function initSocketIO(httpServer,debug)
console.log('sending AT...');
});
socket.on('refreshClients', function() {
console.log('Refreshing all clients');
socketServer.emit('clientrefresh'); // send this to all so use socketServer
});
socket.on('getLastMessages', function(number) {
console.log('retrieving messages');
var times = db('messages').chain().takeRight(number).map('time').value();