-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
45 lines (35 loc) · 1.56 KB
/
app.js
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
let i = 0;
let numOpenTables = 0;
firebase.database().ref('Napkn').once("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
let listItem = document.createElement('li');
// show table number
let tableNum = document.createElement('h2');
tableNum.innerHTML = "table " + (i+1);
listItem.appendChild(tableNum);
// show device status (open or occupied)
let deviceStatus = document.createElement('h3');
let status = childSnapshot.child("DeviceStatus").val();
deviceStatus.innerHTML = status.toLowerCase();
listItem.appendChild(deviceStatus);
if(status == "Occupied"){
listItem.classList.add('occupied');
listItem.appendChild(document.createElement('br'));
let remaining = document.createElement('h3');
remaining.innerHTML = "remaining:";
listItem.appendChild(remaining);
// Display minutes remaining
let timeLeft = document.createElement('h2');
timeLeft.innerHTML = childSnapshot.child("TimeRemaining").val() + " mins";
listItem.appendChild(timeLeft);
}
else
numOpenTables++;
let tableList = document.getElementById("TableList");
tableList.appendChild(listItem);
i++;
});
// Display number of open tables
let openTables = document.getElementById("TablesOpen");
openTables.innerHTML = "tables open: " + numOpenTables + "/" + i; // Display num open tables
});