This commit is contained in:
Yapollon 2024-03-10 21:02:33 +01:00
parent fdc90fe118
commit 03e1f22a87
6 changed files with 55 additions and 40 deletions

20
app.py
View File

@ -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 {}
###########################################################

View File

@ -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);

View File

@ -2,13 +2,8 @@
<!-- Listen erstellen -->
<div class="row mb-3">
<h5 class="col-9">
📋 Gewohnheiten
</h5>
<a class="col-3 btn btn-primary p" role="button" href="/habit-list">
Neue Liste erstellen
</a>
<h5 class="col-9">📋 Gewohnheiten</h5>
<a class="col-3 btn btn-primary p" role="button" href="/habit-list">Neue Liste erstellen</a>
</div>
<!-- Tabs zur Auswahl -->
@ -25,6 +20,7 @@
</li>
{% endfor %}
</ul>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Select all the tab links
@ -207,7 +203,7 @@
</div>
{% endfor %}
</div>
</div>
</div>
<script>
@ -222,5 +218,4 @@
function setSelectedListId(listId) {
selectedlistId = listId;
}
</script>

View File

@ -40,17 +40,16 @@
<option value="Jahr">Jahr</option>
</select>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.addEventListener('DOMContentLoaded', () => {
let selectedElement = document.getElementById('unit');
for (let option of selectedElement.options) {
if (option.value == '{{ unit }}') {
if (option.value === '{{ unit }}') {
option.selected = true;
break;
}
}
});
</script>
<div class="invalid-feedback">
{{ errors.get('unit', '') }}
@ -65,13 +64,13 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
// Extracting the list-query from the URL
var listQuery = new URLSearchParams(window.location.search).get('habit');
let listQuery = new URLSearchParams(window.location.search).get('habit');
if ("{{ habit }}" != "") {
if ("{{ habit }}" !== "") {
listQuery = "{{ habit }}";
// Add the list_id to the URL
var url = new URL(window.location.href);
const url = new URL(window.location.href);
url.searchParams.set('habit', listQuery);
// window.history.pushState({}, '', url);
}

View File

@ -37,11 +37,11 @@
<option value="Jahr">Jahr</option>
</select>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.addEventListener('DOMContentLoaded', () => {
let selectedElement = document.getElementById('unit');
for (let option of selectedElement.options) {
if (option.value == '{{ unit }}') {
if (option.value === '{{ unit }}') {
option.selected = true;
break;
}
@ -61,13 +61,13 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
// Extracting the list-query from the URL
var listQuery = new URLSearchParams(window.location.search).get('list');
let listQuery = new URLSearchParams(window.location.search).get('list');
if ("{{ list_id }}" != "") {
if ("{{ list_id }}" !== "") {
listQuery = "{{ list_id }}";
// Add the list_id to the URL
var url = new URL(window.location.href);
const url = new URL(window.location.href);
url.searchParams.set('list', listQuery);
// window.history.pushState({}, '', url);
}

View File

@ -10,7 +10,7 @@
{% for user in users %}
<form action="/user-delete" class="row" method="POST">
<div class="col">
<img src="{{ user.profile_image }}" class="avatar"/>
<img src="{{ user.profile_image }}" class="avatar" alt=""/>
</div>
<div class="col">
{{ user.name }}