mirror of
https://github.com/s00500/nodeMessageBoard.git
synced 2024-12-04 04:11:28 +00:00
Added basic database delete page
This commit is contained in:
parent
1df24799c5
commit
ee2462a40c
2
app.js
2
app.js
@ -13,4 +13,6 @@ handle["/js/jquery-1.12.1.min"] = requestHandlers.sendJquery;
|
|||||||
handle["/js/jquery-ui.js"] = requestHandlers.sendJqueryUI;
|
handle["/js/jquery-ui.js"] = requestHandlers.sendJqueryUI;
|
||||||
handle["/css/bootstrap.min.css"] = requestHandlers.sendBootstrap;
|
handle["/css/bootstrap.min.css"] = requestHandlers.sendBootstrap;
|
||||||
|
|
||||||
|
handle["/clear"] = requestHandlers.sendClear;
|
||||||
|
|
||||||
server.start(router.route,handle,debug);
|
server.start(router.route,handle,debug);
|
||||||
|
10
board.html
10
board.html
@ -71,8 +71,14 @@ body {
|
|||||||
function initSocketIO()
|
function initSocketIO()
|
||||||
{
|
{
|
||||||
iosocket = io.connect();
|
iosocket = io.connect();
|
||||||
|
|
||||||
|
iosocket.on('clientrefresh', function() {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
iosocket.on('onconnection', function() {
|
iosocket.on('onconnection', function() {
|
||||||
initButton();
|
|
||||||
|
|
||||||
|
|
||||||
iosocket.on('debugMessage', function(message) {
|
iosocket.on('debugMessage', function(message) {
|
||||||
alert(message);
|
alert(message);
|
||||||
@ -81,9 +87,9 @@ body {
|
|||||||
iosocket.on('config', function(phonenumber) {
|
iosocket.on('config', function(phonenumber) {
|
||||||
mynumber = phonenumber;
|
mynumber = phonenumber;
|
||||||
$( "span.number" ).html(mynumber);
|
$( "span.number" ).html(mynumber);
|
||||||
console.log(mynumber);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
iosocket.on('newMessage', function(time,number,message,color) {
|
iosocket.on('newMessage', function(time,number,message,color) {
|
||||||
var censoredNumber = number.substring(0,3) + "********" +number.substring(number.length - 3, number.length);
|
var censoredNumber = number.substring(0,3) + "********" +number.substring(number.length - 3, number.length);
|
||||||
var messages = document.getElementById('messagesBody');
|
var messages = document.getElementById('messagesBody');
|
||||||
|
62
clear.html
Normal file
62
clear.html
Normal 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>
|
@ -47,6 +47,16 @@ function sendJqueryUI(response) {
|
|||||||
response.end(html);
|
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.sendBootstrap = sendBootstrap;
|
||||||
exports.sendJqueryUI = sendJqueryUI;
|
exports.sendJqueryUI = sendJqueryUI;
|
||||||
|
15
server.js
15
server.js
@ -68,6 +68,16 @@ function initSocketIO(httpServer,debug)
|
|||||||
console.log("user connected");
|
console.log("user connected");
|
||||||
socket.emit('onconnection');
|
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) {
|
socket.on('getConfig', function(data) {
|
||||||
var number = config('mainConfig').chain().find({ param: 'mynumber' }).value()['value'];
|
var number = config('mainConfig').chain().find({ param: 'mynumber' }).value()['value'];
|
||||||
socket.emit('config',number);
|
socket.emit('config',number);
|
||||||
@ -78,6 +88,11 @@ function initSocketIO(httpServer,debug)
|
|||||||
console.log('sending AT...');
|
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) {
|
socket.on('getLastMessages', function(number) {
|
||||||
console.log('retrieving messages');
|
console.log('retrieving messages');
|
||||||
var times = db('messages').chain().takeRight(number).map('time').value();
|
var times = db('messages').chain().takeRight(number).map('time').value();
|
||||||
|
Loading…
Reference in New Issue
Block a user