From 03e1f22a87eaca7e07f0eaff4cede2a58dc93a3e Mon Sep 17 00:00:00 2001 From: Yapollon <75550334+Yapollon@users.noreply.github.com> Date: Sun, 10 Mar 2024 21:02:33 +0100 Subject: [PATCH] Cleanup --- app.py | 20 +++++++++++++++++- static/script/script-index.js | 23 ++++++++++++--------- templates/components/habit_lists.html | 29 +++++++++++---------------- templates/edit-habit.html | 11 +++++----- templates/habit.html | 10 ++++----- templates/users-edit.html | 2 +- 6 files changed, 55 insertions(+), 40 deletions(-) diff --git a/app.py b/app.py index ae28e74..fa41487 100644 --- a/app.py +++ b/app.py @@ -432,7 +432,7 @@ def delete_habit(): habit.delete() return {} -@app.route('/reorder', methods=['POST']) +@app.route('/reorder-habit', methods=['POST']) @login_required def reorder_habits(): new_index = request.get_json()["newIndex"] + 1 @@ -699,6 +699,24 @@ def deny_list(): habit_list.remove_user(current_user.id) return {} + +@app.route('/reorder-list', methods=['POST']) +@login_required +def reorder_habit_list(): + new_index = request.get_json()["newIndex"] + 1 + habitList = HabitList.get(request.get_json()["habitListId"]) + + if habitList is None: + return {"error": "HabitList not found"} + + # Check if habit belongs to user + users = habitList.get_users() + if current_user not in users: + return {"error": "HabitList does not belong to user"} + + habitList.update_slot(new_index) + + return {} ########################################################### diff --git a/static/script/script-index.js b/static/script/script-index.js index f9acf6a..c08b353 100644 --- a/static/script/script-index.js +++ b/static/script/script-index.js @@ -1,5 +1,5 @@ -// Funktion zum Erstellen der Heatmap +// Erstellen der Heatmap function createHeatmap(data, day) { const heatmapContainer = document.getElementById('heatmap'); @@ -29,6 +29,7 @@ function createHeatmap(data, day) { } } +// Löschen der Heatmap function deleteHeatmap() { const heatmapContainer = document.getElementById('heatmap'); const dayElements = heatmapContainer.getElementsByClassName('day'); @@ -39,6 +40,7 @@ function deleteHeatmap() { }); } +// Animation der Progressbar function checkCompletionAndAnimate(habitId, percentage) { const progressBar = document.getElementById("progress-bar-" + habitId); const habitBlock = document.getElementById("habit-" + habitId); @@ -55,6 +57,7 @@ function checkCompletionAndAnimate(habitId, percentage) { } } +// Senden einer Post-Request, sobald ein Habit abgehackt wird function sendPostRequest(checkboxId) { // Get the habit id from the checkbox id attribute const habitId = checkboxId; @@ -88,6 +91,7 @@ function sendPostRequest(checkboxId) { }); } +// Senden einer Post-Request, sobald ein Habit gelöscht wird function deleteHabit(habitId) { // Make a POST request to /delete with the habit id @@ -108,6 +112,7 @@ function deleteHabit(habitId) { }); } +// Senden einer Post-Request, sobald eine HabitList gelöscht wird function deleteList(listId) { // Make a POST request to /delete with the habit id @@ -130,6 +135,7 @@ function deleteList(listId) { }); } + document.addEventListener('DOMContentLoaded', () => { const elements = document.querySelectorAll('.task-list').values() @@ -139,11 +145,11 @@ document.addEventListener('DOMContentLoaded', () => { 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; + const habitId = el.children[evt.newIndex].id.split('-')[1]; + const oldIndex = evt.oldIndex; + const newIndex = evt.newIndex; - axios.post('/reorder', {habitId: habitId, oldIndex: oldIndex, newIndex: newIndex}, { + axios.post('/reorder-habit', {habitId: habitId, oldIndex: oldIndex, newIndex: newIndex}, { headers: { 'Content-Type': 'application/json' } @@ -162,7 +168,7 @@ $(function () { $('[data-toggle="tooltip"]').tooltip() }) -// Function to update the current time +// Aktualisieren der Uhrzeit function updateCurrentTime() { const currentTimeElement = document.getElementById('current-time'); const currentDate = new Date(); @@ -171,11 +177,8 @@ function updateCurrentTime() { currentTimeElement.innerText = currentDateTime.replace(',', ',') + ' ' + currentDate.toLocaleString('de-DE', { weekday: 'long' }); } -// Erstelle die Heatmap mit den simulierten Daten +// Erstellt die Heatmap mit den simulierten Daten createHeatmap(activityData, day, color); -// Update the time immediately updateCurrentTime(); - -// Update the time every second setInterval(updateCurrentTime, 1000); diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index 1643dbd..5c70175 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -2,13 +2,8 @@
@@ -25,6 +20,7 @@ {% endfor %} + diff --git a/templates/edit-habit.html b/templates/edit-habit.html index d258e75..d208ae2 100644 --- a/templates/edit-habit.html +++ b/templates/edit-habit.html @@ -40,17 +40,16 @@