-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (40 loc) · 1.95 KB
/
script.js
File metadata and controls
47 lines (40 loc) · 1.95 KB
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
(async () => {
try {
let res = await fetch('http://localhost:5000/database');
let data = await res.json();
let dbContainer = document.getElementById('db-visualization');
data.items.forEach(element => {
let divUsername = document.createElement('div');
divUsername.innerText = element.email;
dbContainer.appendChild(divUsername);
let divEmail = document.createElement('div');
divEmail.innerText = element.name;
dbContainer.appendChild(divEmail);
let divAge = document.createElement('div');
divAge.innerText = element.major;
dbContainer.appendChild(divAge);
let divGpa = document.createElement('div');
divGpa.innerText = element.year;
dbContainer.appendChild(divGpa);
});
let transactionContainer = document.getElementById('transactions');
data.transactions.forEach(element => {
let div = document.createElement('div');
div.innerText = element;
transactionContainer.appendChild(div);
});
} catch {
document.body.innerHTML = '';
let div = document.createElement('div')
div.id = 'container'
let errorText = document.createElement('div');
errorText.id = 'error-text'
errorText.innerText = 'An error has occured or the server is not running!\n \
Check if the server has started and once started refresh the page.\n \
If you are still getting an error please report it to the demo\'s repository.'
div.appendChild(errorText)
document.body.appendChild(div);
}
let button = document.getElementById('refresh-button');
button.addEventListener('click', () => { location.reload() });
})();