Add result page
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Datefinder</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.calendar {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
/* 7 columns for 7 days */
|
||||
gap: 10px;
|
||||
margin: 20px auto;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.day-column {
|
||||
border: 1px solid #ccc;
|
||||
background-color: #f9f9f9;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.day-header {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.hour-block {
|
||||
border: 1px solid #ddd;
|
||||
padding: 10px;
|
||||
margin: 2px 0;
|
||||
cursor: pointer;
|
||||
background-color: #fff;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.hour-block.clicked {
|
||||
background-color: #87CEEB;
|
||||
/* Change color when clicked */
|
||||
}
|
||||
|
||||
// TODO(jona) This should be specific for the sumbit-name-lable id!
|
||||
label {
|
||||
color: red;
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Datefinder</h1>
|
||||
<h2>{{ .PollName }}</h2>
|
||||
<div class="calendar" id="calendar"></div>
|
||||
<script>
|
||||
|
||||
function createResultView(result) {
|
||||
const daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
||||
const calendar = document.getElementById("calendar");
|
||||
|
||||
for (let day = 0; day < 7; day++) {
|
||||
const dayColumn = document.createElement("div");
|
||||
dayColumn.classList.add("day-column");
|
||||
|
||||
const dayHeader = document.createElement("div");
|
||||
dayHeader.classList.add("day-header");
|
||||
dayHeader.textContent = daysOfWeek[day];
|
||||
dayColumn.appendChild(dayHeader);
|
||||
|
||||
for (let hour = 0; hour < 24; hour++) {
|
||||
const hourBlock = document.createElement("div");
|
||||
hourBlock.classList.add("hour-block");
|
||||
hourBlock.textContent = `${hour}:00\n${result.votes[day][hour].votes}\n${result.votes[day][hour].usernames}`;
|
||||
|
||||
dayColumn.appendChild(hourBlock);
|
||||
}
|
||||
|
||||
calendar.appendChild(dayColumn);
|
||||
}
|
||||
}
|
||||
|
||||
const url = "http://localhost:8080/api/result/{{ .PollId }}"
|
||||
|
||||
fetch(url, {method: "GET"})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
console.log(response)
|
||||
}
|
||||
return response.json()
|
||||
})
|
||||
.then(data => {
|
||||
createResultView(data)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Fetch error:", error);
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user