forked from vegardga/lunsj-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.html
101 lines (91 loc) · 3.35 KB
/
history.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!doctype html>
<html>
<head>
<title>Tine-lunsj!</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
body {
max-width: 650px;
margin-left: 10px;
}
#content {
display: none;
}
#content h2 {
text-align: center;
margin-bottom: 30px;
}
.glyphicon.spinning {
animation: spin 1s infinite linear;
-webkit-animation: spin2 1s infinite linear;
}
@keyframes spin {
from { transform: scale(1) rotate(0deg); }
to { transform: scale(1) rotate(360deg); }
}
@-webkit-keyframes spin2 {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
</style>
</head>
<body>
<div id="loader">
<span class="glyphicon glyphicon-refresh spinning"></span>
</div>
<div id="content">
<h2>Fredagslønsj historikk!</h2>
<table class="table table-striped table-bordered">
<col width="25%">
<col width="55%">
<col width="20%">
<thead>
<tr class="info">
<th>Når</th>
<th>Hva</th>
<th>Hvem</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>
</div>
<ul id="status-messages"></ul>
<a href="/tine-lunsj" class="btn btn-default hidden-print">Tilbake</a>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
function getAllOrders() {
$.get("/tine-lunsj/allOrders", function( data ) {
$("#tableBody").empty();
data.sort(function(a, b){
var x = new Date(a.timestamp);
var y = new Date(b.timestamp);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
for(var i = 0; i < data.length; i++) {
var item = data[i];
$("#tableBody").append("<tr><td>" + new Date(item.timestamp).toLocaleString() + "</td><td>" + item.order + "</td><td>" + item.name + "</td></tr>");
}
$("#loader").hide();
$("#content").show();
});
}
function showStatusMessage(msg) {
$("#status-messages").prepend($("<li>" + new Date().toTimeString().substr(0,8) + ": " + msg + "</li>"))
}
$(document).ready(getAllOrders);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.js"></script>
<script>
var socket = io();
socket.on('bestilling', function (msg) {
$("#loader").show();
getAllOrders();
var messageObj = JSON.parse(msg);
var messageText = messageObj.customer + " bestilte " + messageObj.orderItem;
showStatusMessage(messageText);
});
</script>
</html>