Files
setra/static/index.html
2025-10-08 18:14:07 +02:00

206 lines
5.0 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="Daniel Svitan">
<title>Setra</title>
<style>
body {
display: flex;
align-items: center;
flex-direction: column;
}
.container {
width: 60vw;
margin-top: 2rem;
}
h1 {
margin: 0;
}
p {
width: min-content;
}
.create-form {
display: flex;
flex-direction: column;
border: 1px black solid;
padding: 0.5rem;
border-radius: 0.5rem;
}
.create-form label {
font-size: 1.15rem;
}
.create-form input {
width: min-content;
border-radius: 0.5rem;
border: 1px gray solid;
padding: 0.4rem 0.4rem 0.15rem 0.4rem;
font-size: 1.05rem;
}
.create-form button[type=submit] {
width: min-content;
margin-top: 0.5rem;
border: none;
font-size: 1.05rem;
color: #eeeeee;
background: #0078e7;
padding: 0.5rem 0.75rem 0.25rem 0.75rem;
border-radius: 0.5rem;
cursor: pointer;
}
.dialog {
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
backdrop-filter: blur(1rem);
}
.dialog form {
border: 1px solid black;
padding: 0.5rem;
border-radius: 0.5rem;
display: flex;
flex-direction: column;
}
.dialog form label {
font-size: 1.15rem;
}
.dialog form input {
width: min-content;
border-radius: 0.5rem;
border: 1px gray solid;
padding: 0.4rem 0.4rem 0.15rem 0.4rem;
font-size: 1.05rem;
}
.dialog form button[type=submit] {
width: min-content;
margin-top: 0.5rem;
border: none;
font-size: 1.05rem;
color: #eeeeee;
background: #0078e7;
padding: 0.5rem 0.75rem 0.25rem 0.75rem;
border-radius: 0.5rem;
align-self: end;
cursor: pointer;
}
#tracker-table {
width: 100%;
margin-top: 2rem;
font-size: 1.10rem;
}
#tracker-table th:nth-child(1) {
width: 20rem;
}
#tracker-table td:nth-child(3) {
width: 15rem;
}
#tracker-table td, #tracker-table th {
margin: 0;
padding: 0;
border-bottom: 1px solid black;
}
</style>
</head>
<body>
<div class="container">
<h1>Setra</h1>
<form class="create-form">
<label for="name-input">Name:</label>
<input id="name-input" type="text">
<button type="submit">Create</button>
</form>
<table id="tracker-table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Created at</th>
<th>Hits</th>
</tr>
</table>
<div class="dialog" id="dialog">
<form onsubmit="saveAPIKey(Event)">
<label for="api-key-input">API key:</label>
<input id="api-key-input" type="password">
<button type="submit">Save</button>
</form>
</div>
</div>
<script>
function saveAPIKey(event) {
event.preventDefault();
const input = document.getElementById("api-key-input");
localStorage.setItem("api-key", input.value);
document.getElementById("dialog").style.display = "none";
loadTriggers();
}
function init() {
if (localStorage.getItem("api-key")) {
document.getElementById("dialog").style.display = "none";
loadTriggers();
}
}
function loadTriggers() {
const apiKey = localStorage.getItem("api-key");
if (!apiKey) {
return;
}
fetch("http://localhost:8000/tracker", {
method: "GET",
headers: {
Authorization: apiKey,
}
}).then((res) => {
res.json().then((trackers) => {
console.log(trackers);
trackers.forEach((tracker) => {
document.getElementById("tracker-table").innerHTML += `
<tr>
<td>${tracker.id}</td>
<td>${tracker.name}</td>
<td>${tracker.created_at}</td>
<td>${tracker.hits}</td>
</tr>
`;
})
}).catch((err) => alert(`Couldn't unwrap json: ${err}`))
}).catch((err) => alert(`Couldn't fetch trackers: ${err}`));
}
init();
</script>
</body>
</html>