Merge remote-tracking branch 'origin/master'
# Conflicts: # templates/index.html
This commit is contained in:
commit
af86caa196
27
app.py
27
app.py
@ -207,6 +207,10 @@ def habit_create():
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
errors['list_query'] = 'Die Anzahl muss eine Zahl sein.'
|
errors['list_query'] = 'Die Anzahl muss eine Zahl sein.'
|
||||||
|
|
||||||
|
# Check if unit is day and times is one
|
||||||
|
if unit == 'Tag' and times != 1:
|
||||||
|
errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.'
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
return render_template(
|
return render_template(
|
||||||
'habit.html',
|
'habit.html',
|
||||||
@ -378,6 +382,9 @@ def edit_habit_change():
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
errors['list_query'] = 'Die Anzahl muss eine Zahl sein.'
|
errors['list_query'] = 'Die Anzahl muss eine Zahl sein.'
|
||||||
|
|
||||||
|
if unit == 'Tag' and times != 1:
|
||||||
|
errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.'
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
return render_template(
|
return render_template(
|
||||||
"edit-habit.html",
|
"edit-habit.html",
|
||||||
@ -561,6 +568,24 @@ def delete_habit():
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/delete-list', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def delete_list():
|
||||||
|
list_id = request.get_json()["listId"]
|
||||||
|
|
||||||
|
habit_list = HabitList.get(list_id)
|
||||||
|
|
||||||
|
if habit_list is None:
|
||||||
|
return {"error": "List not found"}
|
||||||
|
|
||||||
|
# Check if habit belongs to user
|
||||||
|
if current_user not in habit_list.get_users():
|
||||||
|
return {"error": "List does not belong to user"}
|
||||||
|
|
||||||
|
habit_list.delete()
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
@app.route('/reorder', methods=['POST'])
|
@app.route('/reorder', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def reorder_habits():
|
def reorder_habits():
|
||||||
@ -660,4 +685,4 @@ def add_user():
|
|||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(port=5000, debug=True)
|
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||||
|
|||||||
@ -190,7 +190,7 @@ def update_slot(id: int, slot: int):
|
|||||||
|
|
||||||
def update_habit(id: int, name: str, note: str, times: int, unit: int):
|
def update_habit(id: int, name: str, note: str, times: int, unit: int):
|
||||||
now = datetime.now().isoformat()
|
now = datetime.now().isoformat()
|
||||||
query = (f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit}, updated_at = '{now}' "
|
query = (f"UPDATE habits SET name = '{name}', note = '{note}', times = {times}, unit = {unit}, updated_at = '{now}' "
|
||||||
f"WHERE id = {id};")
|
f"WHERE id = {id};")
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|||||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pillow~=10.2.0
|
||||||
|
flask~=3.0.0
|
||||||
|
flask-login~=0.6.3
|
||||||
20
templates/components/delete_list.html
Normal file
20
templates/components/delete_list.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
<div class="modal fade" id="listenModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h1 class="modal-title fs-5" id="exampleModalLabel">Bestätige</h1>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
Möchtest du diese Liste wirklich löschen?
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">abbrechen</button>
|
||||||
|
<button type="button" class="btn btn-primary btn-danger" data-bs-dismiss="modal"
|
||||||
|
onclick="deleteList(selectedListId)">Löschen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@ -15,7 +15,7 @@
|
|||||||
<ul class="nav nav-tabs card-header-tabs" role="tablist">
|
<ul class="nav nav-tabs card-header-tabs" role="tablist">
|
||||||
{% for habit_list in habit_lists %}
|
{% for habit_list in habit_lists %}
|
||||||
|
|
||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation" id="tab-{{ habit_list.id }}">
|
||||||
<a class="nav-link {% if habit_list == habit_lists[0] %} active {% endif %}"
|
<a class="nav-link {% if habit_list == habit_lists[0] %} active {% endif %}"
|
||||||
id="simple-tab-{{habit_list.id}}"
|
id="simple-tab-{{habit_list.id}}"
|
||||||
data-bs-toggle="tab" href="#simple-tabpanel-{{habit_list.id}}" role="tab"
|
data-bs-toggle="tab" href="#simple-tabpanel-{{habit_list.id}}" role="tab"
|
||||||
@ -63,6 +63,22 @@
|
|||||||
{% for habit_list in habit_lists %}
|
{% for habit_list in habit_lists %}
|
||||||
<div class="tab-pane {% if habit_list == habit_lists[0] %} active {% endif %}"
|
<div class="tab-pane {% if habit_list == habit_lists[0] %} active {% endif %}"
|
||||||
id="simple-tabpanel-{{habit_list.id}}" role="tabpanel" aria-labelledby="simple-tab-{{habit_list.id}}">
|
id="simple-tabpanel-{{habit_list.id}}" role="tabpanel" aria-labelledby="simple-tab-{{habit_list.id}}">
|
||||||
|
|
||||||
|
<!-- Beschreibung und Löschen von der Liste -->
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col">
|
||||||
|
{{ habit_list.description }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-2">
|
||||||
|
<button type="button" class="btn btn-xs me-3" data-bs-toggle="modal"
|
||||||
|
data-bs-target="#listenModal" style="width: 40px; height: 40px"
|
||||||
|
onclick="setSelectedListId({{ habit_list.id }})">
|
||||||
|
<i class="bi bi-trash3"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row mb-3 align-items-center">
|
<div class="row mb-3 align-items-center">
|
||||||
|
|
||||||
<!-- Personen die zur Liste gehören -->
|
<!-- Personen die zur Liste gehören -->
|
||||||
@ -103,7 +119,7 @@
|
|||||||
{% for habit in habit_list.habits %}
|
{% for habit in habit_list.habits %}
|
||||||
<li class="row d-flex align-items-center mb-2" id="habit-{{ habit.id }}">
|
<li class="row d-flex align-items-center mb-2" id="habit-{{ habit.id }}">
|
||||||
|
|
||||||
<!-- Handle zum verschieben -->
|
<!-- Handle zum Verschieben -->
|
||||||
<div class="col-auto drag-handle" style="cursor: grab;">
|
<div class="col-auto drag-handle" style="cursor: grab;">
|
||||||
<i class="bi bi-grip-vertical"></i>
|
<i class="bi bi-grip-vertical"></i>
|
||||||
</div>
|
</div>
|
||||||
@ -172,5 +188,9 @@
|
|||||||
selectedHabitId = habitId;
|
selectedHabitId = habitId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selectedListId = null;
|
||||||
|
|
||||||
|
function setSelectedListId(listId) {
|
||||||
|
selectedlistId = listId;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -76,6 +76,28 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
var habitElement = document.getElementById("simple-tabpanel-" + listId);
|
||||||
|
habitElement.remove();
|
||||||
|
var habitElement = document.getElementById("tab-" + listId);
|
||||||
|
habitElement.remove();
|
||||||
|
}).catch(function (error) {
|
||||||
|
// Handle the error if needed
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', (event) => {
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
var elements = document.querySelectorAll('.task-list').values()
|
var elements = document.querySelectorAll('.task-list').values()
|
||||||
|
|||||||
@ -47,6 +47,10 @@
|
|||||||
{% include 'components/delete_button.html' %}
|
{% include 'components/delete_button.html' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if current_user.is_authenticated %}
|
||||||
|
{% include 'components/delete_list.html' %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if not current_user.is_authenticated %}
|
{% if not current_user.is_authenticated %}
|
||||||
<script type="module" src="https://unpkg.com/@splinetool/viewer@1.0.55/build/spline-viewer.js"></script>
|
<script type="module" src="https://unpkg.com/@splinetool/viewer@1.0.55/build/spline-viewer.js"></script>
|
||||||
<spline-viewer loading-anim-type="spinner-small-dark" url="https://prod.spline.design/4mCpd7DzpXgN2X9q/scene.splinecode"></spline-viewer>
|
<spline-viewer loading-anim-type="spinner-small-dark" url="https://prod.spline.design/4mCpd7DzpXgN2X9q/scene.splinecode"></spline-viewer>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user