-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdashboard.js
More file actions
69 lines (61 loc) · 2.48 KB
/
Copy pathdashboard.js
File metadata and controls
69 lines (61 loc) · 2.48 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
document.addEventListener('DOMContentLoaded', function() {
fetchSites();
});
//document.getElementById('create-site-form').addEventListener('submit', function(e) {
// e.preventDefault();
// createSite();
//});
function fetchSites() {
fetch('backend/get_sites.php')
.then(response => response.json())
.then(sites => {
const sitesList = document.getElementById('sites-list');
if (sites.length === 0 ) {
}
else {
console.log(JSON.parse(sites[2].site_data)["timespans"]);
sitesList.innerHTML = ''; // Clear current sites
sites.forEach(site => {
var siteType = "";
if (JSON.parse(site.site_data)["type"] == "1") {
siteType = "Wäscherei";
}
if (JSON.parse(site.site_data)["type"] == "2") {
siteType = "Reinigung";
}
if (JSON.parse(site.site_data)["type"] == "3") {
siteType = "Mischbetrieb";
}
var timespan_cnt = 0;
if (JSON.parse(site.site_data)["timespans"] != null) {
timespan_cnt = JSON.parse(site.site_data)["timespans"].length;
}
//TODO: somehow better present timespans
const div = document.createElement('div');
div.className = 'site';
div.innerHTML = `<strong>${site.site_name}</strong>, ` + siteType + `<p>` + timespan_cnt + ` Datenpunkte</p>`;
div.addEventListener('click', () => {
window.location.href = `datenerfassung.php?site_id=${site.id}`;
});
sitesList.appendChild(div);
});
}
})
.catch(error => console.error('Error fetching sites:', error));
}
function createSite() {
const siteName = document.getElementById('site-name').value;
const siteData = document.getElementById('site-data').value;
// Example fetch request; adjust the URL and method as needed.
fetch('backend/create_site.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded', },
body: `site_name=${encodeURIComponent(siteName)}&site_data=${encodeURIComponent(siteData)}`
})
.then(response => response.text())
.then(result => {
console.log(result);
fetchSites(); // Refresh the list of sites
})
.catch(error => console.error('Error creating site:', error));
}