2024-01-12 10:57:58 +01:00
|
|
|
{% extends 'layouts/main.html' %}
|
|
|
|
|
|
|
|
|
|
{% block content %}
|
2024-01-19 11:13:01 +01:00
|
|
|
<h1>{{ title }}</h1>
|
2024-01-12 10:57:58 +01:00
|
|
|
<h3>{{ utc_dt }}</h3>
|
|
|
|
|
|
|
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
<style>
|
|
|
|
|
#heatmap {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(7, 0fr); /* 7 Tage in einer Woche */
|
|
|
|
|
gap: 5px;
|
2024-01-16 11:16:21 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
.day {
|
2024-01-30 10:49:08 +01:00
|
|
|
width: 50px;
|
|
|
|
|
height: 50px;
|
2024-01-23 11:17:24 +01:00
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
2024-01-19 10:27:08 +01:00
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
<div class="row">
|
2024-01-19 11:13:01 +01:00
|
|
|
|
2024-01-30 10:49:08 +01:00
|
|
|
<div class="col-md-5 col-12">
|
|
|
|
|
<div id="heatmap"></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
<script>
|
|
|
|
|
// Funktion zur Rückgabe des Montagsdatums
|
|
|
|
|
function getMonday(date) {
|
|
|
|
|
const day = date.getDay();
|
|
|
|
|
const diff = date.getDate() - day + (day === 0 ? -6 : 1); // Anpassung für Sonntag
|
|
|
|
|
return new Date(date.setDate(diff));
|
|
|
|
|
}
|
2024-01-19 11:13:01 +01:00
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
// Simulierte Aktivitätsdaten (ersetze dies durch deine echten Daten)
|
2024-01-30 10:46:16 +01:00
|
|
|
const activityData = [5, 3, 10, 5, 24, 2, 10, 47, 32, 45, 9, 5, 11, 39, 24, 2, 10, 47, 32, 45];
|
2024-01-23 11:17:24 +01:00
|
|
|
|
|
|
|
|
// Funktion zum Erstellen der Heatmap
|
|
|
|
|
function createHeatmap(data) {
|
|
|
|
|
const heatmapContainer = document.getElementById('heatmap');
|
|
|
|
|
|
|
|
|
|
// Aktuelles Datum des Montags
|
2024-01-26 09:13:33 +01:00
|
|
|
const days = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
|
2024-01-23 11:17:24 +01:00
|
|
|
|
|
|
|
|
for (let i = 0; i < 7; i++) {
|
|
|
|
|
const dayElement = document.createElement('div');
|
|
|
|
|
dayElement.classList.add('day');
|
2024-01-26 09:13:33 +01:00
|
|
|
dayElement.textContent = days[i];
|
2024-01-23 11:17:24 +01:00
|
|
|
heatmapContainer.appendChild(dayElement);
|
2024-01-26 09:13:33 +01:00
|
|
|
// currentDate.setDate(currentDate.getDate() + 1);
|
2024-01-23 11:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Aktuelles Datum des Montags in der neuen linken Spalte
|
|
|
|
|
for (let i = 0; i < 7; i++) {
|
2024-01-26 09:13:33 +01:00
|
|
|
for (let j = 0; j < 7; j++) {
|
2024-01-26 10:25:38 +01:00
|
|
|
// console.log(i * 7 + j, data[i * 7 + j], Math.max(...data));
|
2024-01-23 11:17:24 +01:00
|
|
|
const opacity = data[i * 7 + j] / Math.max(...data); // Berechne die Opazität basierend auf Aktivitätsanzahl
|
2024-01-26 09:13:33 +01:00
|
|
|
|
|
|
|
|
if (data[i * 7 + j]) {
|
|
|
|
|
const dayElement = document.createElement('div');
|
|
|
|
|
dayElement.classList.add('day');
|
|
|
|
|
dayElement.style.backgroundColor = `rgba(0, 255, 0, ${opacity})`;
|
|
|
|
|
heatmapContainer.appendChild(dayElement);
|
|
|
|
|
} else {
|
|
|
|
|
const dayElement = document.createElement('div');
|
|
|
|
|
// dayElement.classList.add('day');
|
|
|
|
|
// dayElement.style.backgroundColor = `rgba(0, 255, 0, ${opacity})`;
|
|
|
|
|
heatmapContainer.appendChild(dayElement);
|
|
|
|
|
}
|
2024-01-23 11:17:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-19 11:13:01 +01:00
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
// Erstelle die Heatmap mit den simulierten Daten
|
|
|
|
|
createHeatmap(activityData);
|
2024-01-30 10:46:16 +01:00
|
|
|
|
|
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
</script>
|
2024-01-16 11:16:21 +01:00
|
|
|
|
2024-01-30 10:49:08 +01:00
|
|
|
<div class="col-md-7 col-12">
|
2024-01-26 11:07:41 +01:00
|
|
|
<div class="row mb-3">
|
2024-01-23 11:17:24 +01:00
|
|
|
<h2 class="col-10">Task List</h2>
|
|
|
|
|
<a class="col-2 btn btn-primary" role="button" href="/habit">
|
|
|
|
|
Task erstellen
|
|
|
|
|
</a>
|
2024-01-19 10:27:08 +01:00
|
|
|
</div>
|
|
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
<ul class="task-list row">
|
|
|
|
|
{% for habit in habits %}
|
2024-01-26 11:07:41 +01:00
|
|
|
<li class="row d-flex align-items-center mb-2" id="habit-{{habit.id}}">
|
2024-01-23 11:17:24 +01:00
|
|
|
<div class="col-auto">
|
2024-01-26 10:01:02 +01:00
|
|
|
<input {% if habit.checked %} checked {% endif %} type="checkbox" class="task-checkbox" id="{{habit.id}}" onclick="sendPostRequest('{{habit.id}}')">
|
2024-01-23 11:17:24 +01:00
|
|
|
</div>
|
2024-01-19 10:27:08 +01:00
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
<div class="col" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis">
|
|
|
|
|
{{ habit.name }}
|
|
|
|
|
</div>
|
2024-01-19 10:27:08 +01:00
|
|
|
|
2024-01-26 11:07:41 +01:00
|
|
|
<div class="col-8" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis">
|
|
|
|
|
{{ habit.note }}
|
|
|
|
|
</div>
|
2024-01-19 10:27:08 +01:00
|
|
|
|
2024-01-31 10:40:46 +01:00
|
|
|
<button type="button" class="btn btn-xs btn-danger rounded-circle" data-bs-toggle="modal" data-bs-target="#exampleModal" style="width: 40px; height: 40px" onclick="setSelectedHabitId({{habit.id}})">
|
2024-01-26 11:07:41 +01:00
|
|
|
<i class="bi bi-trash3"></i>
|
|
|
|
|
</button>
|
2024-01-30 10:46:16 +01:00
|
|
|
<div class="col-12">
|
|
|
|
|
<div class="progress" style="height: 2px; width: 90%">
|
2024-01-31 10:43:44 +01:00
|
|
|
<div class="progress-bar" id="progress-bar-{{habit.id}}" role="progressbar" style="width: {{ habit.percentage }}%;"></div>
|
2024-01-30 10:46:16 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-01-26 11:07:41 +01:00
|
|
|
</li>
|
2024-01-17 11:17:35 +01:00
|
|
|
|
2024-01-23 11:17:24 +01:00
|
|
|
{% endfor %}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
2024-01-30 10:46:16 +01:00
|
|
|
|
2024-01-31 10:40:46 +01:00
|
|
|
<script>
|
|
|
|
|
var selectedHabitId = null;
|
|
|
|
|
|
|
|
|
|
function setSelectedHabitId(habitId) {
|
|
|
|
|
selectedHabitId = habitId;
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2024-01-30 11:15:22 +01:00
|
|
|
|
|
|
|
|
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
|
|
|
|
<div class="modal-dialog">
|
|
|
|
|
<div class="modal-content">
|
|
|
|
|
<div class="modal-header">
|
2024-01-31 10:40:46 +01:00
|
|
|
<h1 class="modal-title fs-5" id="exampleModalLabel">Bestätige</h1>
|
2024-01-30 11:15:22 +01:00
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="modal-body">
|
2024-01-31 10:40:46 +01:00
|
|
|
Möchtest du dieses Habit wirklich löschen?
|
2024-01-30 11:15:22 +01:00
|
|
|
</div>
|
|
|
|
|
<div class="modal-footer">
|
|
|
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
2024-01-31 10:40:46 +01:00
|
|
|
<button type="button" class="btn btn-primary btn-danger" data-bs-dismiss="modal" onclick="deleteHabit(selectedHabitId)">Löschen</button>
|
2024-01-30 11:15:22 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
2024-01-26 08:27:44 +01:00
|
|
|
<script>
|
|
|
|
|
function sendPostRequest(checkboxId) {
|
|
|
|
|
// Get the checkbox element using the provided ID
|
|
|
|
|
var checkbox = document.getElementById(checkboxId);
|
2024-01-26 10:01:02 +01:00
|
|
|
// console.log(checkbox);
|
|
|
|
|
|
|
|
|
|
// Get the habit id from the checkbox id attribute
|
|
|
|
|
var habitId = checkboxId;
|
|
|
|
|
|
|
|
|
|
// Make a POST request to /check with the habit id
|
|
|
|
|
axios.post('/check', { habitId: habitId }, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response) {
|
|
|
|
|
// Handle the success response if needed
|
|
|
|
|
console.log(response.data);
|
2024-01-30 10:53:21 +01:00
|
|
|
|
|
|
|
|
// Set the percentage of the habit. percentage received as integer
|
|
|
|
|
var percentage = response.data.percentage;
|
|
|
|
|
var progressBar = document.getElementById("progress-bar-" + habitId);
|
|
|
|
|
progressBar.style.width = percentage + "%";
|
2024-01-26 10:01:02 +01:00
|
|
|
}).catch(function (error) {
|
|
|
|
|
// Handle the error if needed
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
2024-01-26 08:27:44 +01:00
|
|
|
}
|
2024-01-26 11:07:41 +01:00
|
|
|
|
|
|
|
|
function deleteHabit(habitId) {
|
|
|
|
|
// Make a POST request to /delete with the habit id
|
2024-01-30 11:15:22 +01:00
|
|
|
|
2024-01-26 11:07:41 +01:00
|
|
|
axios.post('/delete', { habitId: habitId }, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response) {
|
|
|
|
|
// Handle the success response if needed
|
|
|
|
|
console.log(response.data);
|
|
|
|
|
|
|
|
|
|
// Remove the habit from the DOM
|
|
|
|
|
var habitElement = document.getElementById("habit-" + habitId);
|
|
|
|
|
habitElement.remove();
|
|
|
|
|
}).catch(function (error) {
|
|
|
|
|
// Handle the error if needed
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-01-26 08:27:44 +01:00
|
|
|
</script>
|
2024-01-23 11:17:24 +01:00
|
|
|
</div>
|
2024-01-16 11:16:21 +01:00
|
|
|
|
2024-01-12 10:57:58 +01:00
|
|
|
{% endblock %}
|