HabitTracker/templates/components/habit_lists.html

177 lines
7.3 KiB
HTML
Raw Normal View History

<div class="flex-fill col-md-8 col-12 card bg-light p-6 mb-6">
2024-02-28 11:18:14 +01:00
<!-- Listen erstellen -->
<div class="row mb-3">
2024-02-28 10:46:26 +01:00
<h5 class="col-9">
📋 Gewohnheiten
</h5>
2024-02-28 10:46:26 +01:00
<a class="col-3 btn btn-primary p" role="button" href="/habit-list">
Neue Liste erstellen
</a>
</div>
2024-02-28 11:18:14 +01:00
<!-- Tabs zur Auswahl -->
<ul class="nav nav-tabs card-header-tabs" role="tablist">
{% for habit_list in habit_lists %}
<li class="nav-item" role="presentation">
<a class="nav-link {% if habit_list == habit_lists[0] %} active {% endif %}"
id="simple-tab-{{habit_list.id}}"
data-bs-toggle="tab" href="#simple-tabpanel-{{habit_list.id}}" role="tab"
aria-controls="simple-tabpanel-{{habit_list.id}}" aria-selected="true">
{{habit_list.name}}
</a>
</li>
{% endfor %}
</ul>
2024-02-28 11:18:14 +01:00
<script>
document.addEventListener('DOMContentLoaded', function () {
// Select all the tab links
const tabLinks = document.querySelectorAll('.nav-link');
tabLinks.forEach(function(link) {
// Add a click event listener to each tab link
link.addEventListener('click', function(e) {
// Prevent the default action
e.preventDefault();
// Get the tab ID
const tabId = this.getAttribute('href').match(/simple-tabpanel-(\d+)/)[1];
// Update the URL with the new query parameter
const newUrl = updateQueryStringParameter(window.location.href, 'list', tabId);
window.history.pushState({path:newUrl}, '', newUrl);
});
});
// Update the URL with the new query parameter
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}
});
</script>
<div class="tab-content pt-5" id="tab-content">
{% for habit_list in habit_lists %}
<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}}">
2024-02-28 10:46:26 +01:00
<div class="row mb-3 align-items-center">
2024-02-28 11:18:14 +01:00
<!-- Personen die zur Liste gehören -->
{% if habit_list.get_users()[0].id == current_user.id %}
{% if habit_list.get_users()|length > 1 %}
2024-03-01 09:17:52 +01:00
<div class="col">
2024-02-28 10:46:26 +01:00
<div class="avatar-stack">
2024-03-01 09:17:52 +01:00
{% for user in habit_list.get_users() %}
{% if current_user.id != user.id %}
<img class="avatar" src="/{{user.profile_image}}" data-toggle="tooltip" data-placement="top" title="{{user.name}}"/>
{% endif %}
{% endfor %}
2024-02-28 10:46:26 +01:00
</div>
</div>
{% endif %}
2024-02-28 10:46:26 +01:00
2024-02-28 11:18:14 +01:00
<!-- Knopf für das Hinzufügen einer Person zur gemeinsamen Liste -->
2024-03-01 09:17:52 +01:00
<div class="col">
<a href="/users?habit_list={{habit_list.id}}" style="width: 40px; height: 40px; min-height: 3em;" data-toggle="tooltip" data-placement="top" title="Benutzer einladen">
2024-02-28 10:46:26 +01:00
2024-03-01 08:50:33 +01:00
<i class="bi bi-plus-circle"></i>
2024-02-28 10:46:26 +01:00
2024-03-01 08:50:33 +01:00
</a>
2024-02-28 10:46:26 +01:00
</div>
{% else %}
<div class="col"></div>
{% endif %}
2024-02-28 10:46:26 +01:00
<div class="col-6"></div>
2024-02-28 11:18:14 +01:00
<!-- neue Gewohnheiten erstellen -->
<a class="col-3 btn btn-primary" role="button" href="/habit?list={{ habit_list.id }}">
Gewohnheit erstellen
</a>
</div>
<ul class="task-list row">
{% for habit in habit_list.habits %}
<li class="row d-flex align-items-center mb-2" id="habit-{{ habit.id }}">
2024-02-28 10:46:26 +01:00
2024-02-28 11:18:14 +01:00
<!-- Handle zum verschieben -->
<div class="col-auto drag-handle" style="cursor: grab;">
<i class="bi bi-grip-vertical"></i>
</div>
2024-02-28 10:46:26 +01:00
2024-02-28 11:18:14 +01:00
<!-- Checkbox -->
<div class="col-auto">
<input {% if habit.checked %} checked {% endif %} type="checkbox" class="task-checkbox"
id="{{ habit.id }}"
onclick="sendPostRequest('{{ habit.id }}')">
</div>
2024-02-28 11:18:14 +01:00
<!-- Name -->
<div class="col" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis">
{{ habit.name }}
</div>
2024-02-28 11:18:14 +01:00
<!-- Beschreibung -->
<div class="col-md-4 d-none d-md-block text-black text-opacity-50"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis">
{{ habit.note }}
</div>
2024-02-28 11:18:14 +01:00
<!-- Streak -->
2024-03-01 07:53:47 +01:00
<div class="col-2" id="streak-{{ habit.id }}" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis">
{% if not habit.streak == 0 %}
2024-03-05 09:45:14 +01:00
{{ habit.streak }} 🔥
{% endif %}
</div>
2024-02-28 11:18:14 +01:00
<!-- Knopf für das Löschen einer Gewohnheit -->
2024-02-28 10:46:26 +01:00
<button type="button" class="btn btn-xs me-3" data-bs-toggle="modal"
data-bs-target="#exampleModal" style="width: 40px; height: 40px"
onclick="setSelectedHabitId({{ habit.id }})">
<i class="bi bi-trash3"></i>
</button>
2024-02-28 10:46:26 +01:00
<!-- Knopf für das Bearbeiten der Gewohnheit -->
2024-03-01 08:19:53 +01:00
<a type="button" class="btn" href="{{ url_for('edit_habit') }}?habit={{ habit.id }}" aria-current="page"
2024-02-28 10:46:26 +01:00
style="width: 40px; height: 40px; min-height: 3em;">
2024-03-01 08:19:53 +01:00
<i class="bi bi-pencil"></i>
</a>
2024-02-28 10:46:26 +01:00
2024-02-28 11:18:14 +01:00
<!-- Progressbar -->
<div class="col-12">
<div class="progress" style="height: 2px; width: 90%">
<div class="progress-bar" id="progress-bar-{{ habit.id }}" role="progressbar"
style="width: {{ habit.percentage }}%; background-color: {% if habit.percentage >= 100 %} green {% else %} primary {% endif %}"
aria-valuenow="{{ habit.percentage }}" aria-valuemin="0"
aria-valuemax="100"></div>
</div>
</div>
</li>
{% endfor %}
</ul>
</div>
{% endfor %}
</div>
</div>
<script>
var selectedHabitId = null;
function setSelectedHabitId(habitId) {
selectedHabitId = habitId;
}
</script>