2024-03-07 14:28:20 +01:00
|
|
|
|
|
|
|
|
// Funktion zum Erstellen der Heatmap
|
2024-03-07 16:26:56 +01:00
|
|
|
function createHeatmap(data, day, color) {
|
2024-03-07 14:28:20 +01:00
|
|
|
const heatmapContainer = document.getElementById('heatmap');
|
|
|
|
|
|
|
|
|
|
const days = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 7; i++) {
|
|
|
|
|
const dayElement = document.createElement('div');
|
|
|
|
|
dayElement.classList.add('day');
|
|
|
|
|
dayElement.textContent = days[i];
|
|
|
|
|
heatmapContainer.appendChild(dayElement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Aktuelles Datum des Montags in der neuen linken Spalte
|
2024-03-07 15:04:29 +01:00
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
|
for (let j = 0; j < 7; j++) {
|
2024-03-07 14:28:20 +01:00
|
|
|
// console.log(i * 7 + j, data[i * 7 + j], Math.max(...data));
|
|
|
|
|
const opacity = data[i * 7 + j] / (Math.max(...data) <= 0 ? 1 : Math.max(...data)); // Berechne die Opazität basierend auf Aktivitätsanzahl
|
|
|
|
|
|
|
|
|
|
if (data[i * 7 + j]) {
|
|
|
|
|
const dayElement = document.createElement('div');
|
|
|
|
|
dayElement.classList.add('day');
|
2024-03-07 16:26:56 +01:00
|
|
|
dayElement.style.backgroundColor = `rgba(${color}, ${opacity})`;
|
|
|
|
|
if (day === i * 7 + j){
|
2024-03-07 15:56:33 +01:00
|
|
|
dayElement.style.borderColor = `rgba(255, 0, 0)`;
|
|
|
|
|
dayElement.style.borderWidth = "2px";
|
|
|
|
|
}
|
2024-03-07 14:28:20 +01:00
|
|
|
heatmapContainer.appendChild(dayElement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteHeatmap() {
|
|
|
|
|
const heatmapContainer = document.getElementById('heatmap');
|
|
|
|
|
const dayElements = heatmapContainer.getElementsByClassName('day');
|
|
|
|
|
|
|
|
|
|
// Convert HTMLCollection to array and iterate to remove each element
|
|
|
|
|
Array.from(dayElements).forEach(element => {
|
|
|
|
|
element.remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkCompletionAndAnimate(habitId, percentage) {
|
|
|
|
|
const progressBar = document.getElementById("progress-bar-" + habitId);
|
|
|
|
|
const habitBlock = document.getElementById("habit-" + habitId);
|
|
|
|
|
|
|
|
|
|
if (percentage === 100) {
|
|
|
|
|
progressBar.style.backgroundColor = "green";
|
|
|
|
|
habitBlock.classList.add("animate-bounce");
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
habitBlock.classList.remove("animate-bounce");
|
|
|
|
|
}, 2000);
|
|
|
|
|
} else {
|
|
|
|
|
progressBar.style.backgroundColor = "";
|
|
|
|
|
habitBlock.classList.remove("animate-bounce");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sendPostRequest(checkboxId) {
|
|
|
|
|
// Get the habit id from the checkbox id attribute
|
|
|
|
|
const 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);
|
|
|
|
|
|
|
|
|
|
// Set the percentage of the habit. percentage received as integer
|
|
|
|
|
const percentage = response.data.percentage;
|
|
|
|
|
const progressBar = document.getElementById("progress-bar-" + habitId);
|
|
|
|
|
progressBar.style.width = percentage + "%";
|
|
|
|
|
checkCompletionAndAnimate(habitId, percentage);
|
|
|
|
|
|
|
|
|
|
const streak = response.data.streak;
|
|
|
|
|
const streakSymbol = document.getElementById("streak-" + habitId);
|
|
|
|
|
streakSymbol.innerText = streak > 0 ? streak.toString() + " 🔥" : "";
|
|
|
|
|
|
|
|
|
|
const heatmapValues = response.data.heatmap;
|
|
|
|
|
deleteHeatmap()
|
2024-03-07 16:26:56 +01:00
|
|
|
createHeatmap(heatmapValues, day, color)
|
2024-03-07 14:28:20 +01:00
|
|
|
|
|
|
|
|
}).catch(function (error) {
|
|
|
|
|
// Handle the error if needed
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteHabit(habitId) {
|
|
|
|
|
// Make a POST request to /delete with the habit id
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
const habitElement = document.getElementById("habit-" + habitId);
|
|
|
|
|
habitElement.remove();
|
|
|
|
|
}).catch(function (error) {
|
|
|
|
|
// Handle the error if needed
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteList(listId) {
|
|
|
|
|
// Make a POST request to /delete with the habit id
|
|
|
|
|
|
|
|
|
|
axios.post('/delete-list', {listId: listId}, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response) {
|
|
|
|
|
// Handle the success response if needed
|
|
|
|
|
console.log(response.data);
|
|
|
|
|
|
|
|
|
|
// Remove the habit from the DOM
|
2024-03-07 15:04:29 +01:00
|
|
|
let habitElement = document.getElementById("simple-tabpanel-" + listId);
|
2024-03-07 14:28:20 +01:00
|
|
|
habitElement.remove();
|
2024-03-07 15:04:29 +01:00
|
|
|
habitElement = document.getElementById("tab-" + listId);
|
2024-03-07 14:28:20 +01:00
|
|
|
habitElement.remove();
|
|
|
|
|
}).catch(function (error) {
|
|
|
|
|
// Handle the error if needed
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-07 16:26:56 +01:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2024-03-07 15:04:29 +01:00
|
|
|
const elements = document.querySelectorAll('.task-list').values()
|
2024-03-07 14:28:20 +01:00
|
|
|
|
|
|
|
|
// loop through the elements
|
|
|
|
|
for (let el of elements) {
|
|
|
|
|
Sortable.create(el, {
|
|
|
|
|
handle: '.drag-handle',
|
|
|
|
|
animation: 150,
|
|
|
|
|
onEnd: function (evt) {
|
|
|
|
|
var habitId = el.children[evt.newIndex].id.split('-')[1];
|
|
|
|
|
var oldIndex = evt.oldIndex;
|
|
|
|
|
var newIndex = evt.newIndex;
|
|
|
|
|
|
|
|
|
|
axios.post('/reorder', {habitId: habitId, oldIndex: oldIndex, newIndex: newIndex}, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response) {
|
|
|
|
|
// Handle the success response if needed
|
|
|
|
|
}).catch(function (error) {
|
|
|
|
|
// Handle the error if needed
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
|
|
|
|
|
2024-03-07 15:56:33 +01:00
|
|
|
})
|
2024-03-07 14:28:20 +01:00
|
|
|
// Erstelle die Heatmap mit den simulierten Daten
|
2024-03-07 16:26:56 +01:00
|
|
|
createHeatmap(activityData, day, color);
|
2024-03-07 14:28:20 +01:00
|
|
|
|