Create interface.html

pull/3374/head
Elfreda Kwawu 2024-04-03 11:45:34 -04:00 committed by GitHub
parent 2fef0c6378
commit 19fa4a94b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
<html>
<head>
<link rel="stylesheet" href="../../css/spectre.min.css">
</head>
<body>
<div id="data"></div>
<button class="btn btn-default" id="btnSave">Save</button>
<button class="btn btn-default" id="btnDelete">Delete</button>
<script src="../../core/lib/interface.js"></script>
<script>
var dataElement = document.getElementById("data");
var csvData = "";
function getData() {
// Show loading window
Util.showModal("Loading...");
// Get the data
dataElement.innerHTML = "";
Util.readStorageFile(`heart_rate_data.csv`, data => {
csvData = data.trim();
// Remove loading window
Util.hideModal();
// If no data, report it and exit
if (data.length === 0) {
dataElement.innerHTML = "<b>No data found</b>";
return;
}
// Otherwise parse the data and output it as a table
dataElement.innerHTML = `<table>
<tr>
<th>Timestamp</th>
<th>Heart Rate</th>
</tr>` + data.trim().split("\n").map(l => {
l = l.split(",");
return `<tr>
<td>${l[0]}</td>
<td>${l[1]}</td>
</tr>`;
}).join("\n") + "</table>";
});
}
// You can call a utility function to save the data
document.getElementById("btnSave").addEventListener("click", function() {
Util.saveCSV("heart_rate_data", csvData);
});
// Or you can also delete the file
document.getElementById("btnDelete").addEventListener("click", function() {
Util.showModal("Deleting...");
Util.eraseStorageFile("heart_rate_data.csv", function() {
Util.hideModal();
getData();
});
});
// Called when app starts
function onInit() {
getData();
}
</script>
</body>
</html>