Compare commits

..

No commits in common. "119a31302cb6423c80bf29ac24c43fa22c95df60" and "f8ee727705acd6181d796eea2c9d9586d218c263" have entirely different histories.

3 changed files with 13 additions and 124 deletions

View File

@ -23,22 +23,25 @@ class Habit:
slot: int slot: int
percentage: int = 0 percentage: int = 0
def __post_init__(self): def __post_init__(self):
self.fill_statistics() self.fill_statistics()
@staticmethod @staticmethod
def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1): def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1):
slot = get_next_slot(user_id) slot = get_next_slot(user_id)
id = create_habit(user_id, name, times, unit, slot, note) id = create_habit(user_id, name, times, unit, slot, note)
return Habit(id, user_id, name, note, times, unit, slot) return Habit(id, user_id, name, note, times, unit, slot)
@staticmethod @staticmethod
def get(id: int): def get(id: int):
habit = get_habit(id) habit = get_habit(id)
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
return habit return habit
def update(self, name: str=None, note: str=None, times: int=None, unit: int=None): def update(self, name: str=None, note: str=None, times: int=None, unit: int=None):
update_habit(self.id, name, note, times, unit) update_habit(self.id, name, note, times, unit)
if name is not None: if name is not None:
@ -50,10 +53,12 @@ class Habit:
if unit is not None: if unit is not None:
self.unit = unit self.unit = unit
# So sollte die Slots Liste aussehen damit es funktioniert # So sollte die Slots Liste aussehen damit es funktioniert
#[(id, 1), (id, 2), (id, 3), (id, 4), (id, 5)] #[(id, 1), (id, 2), (id, 3), (id, 4), (id, 5)]
def update_slot(self, new_slot: int): def update_slot(self, new_slot: int):
slots = get_slots(self.user_id) slots = get_slots(self.user_id)
print(slots)
if new_slot > self.slot: if new_slot > self.slot:
slots = slots[self.slot:new_slot] slots = slots[self.slot:new_slot]
for slot in slots: for slot in slots:
@ -62,7 +67,7 @@ class Habit:
slots = slots[new_slot-1:self.slot-1] slots = slots[new_slot-1:self.slot-1]
for slot in slots: for slot in slots:
update_slot(slot[0], slot[1]+1) update_slot(slot[0], slot[1]+1)
self.slot = new_slot update_slot(self.id, new_slot)
def delete(self): def delete(self):
@ -81,12 +86,12 @@ class Habit:
count = 0 count = 0
self.checked = False self.checked = False
for tracking in self.get_habitTrackings(): for tracking in self.get_habitTrackings():
if tracking.created_at.day == datetime.today().day: if tracking.created_at == datetime.today():
self.checked = True self.checked = True
# day # day
if self.unit == 0: if self.unit == 0:
if tracking.created_at.day == datetime.today().day: if tracking.created_at == datetime.today():
# self.checked = True # self.checked = True
count += 1 count += 1
# week # week
@ -106,7 +111,3 @@ class Habit:
count += 1 count += 1
self.percentage = int(count / self.times * 100) self.percentage = int(count / self.times * 100)
def to_json(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)

View File

@ -89,12 +89,9 @@
</a> </a>
</div> </div>
<ul class="task-list row draggable-list" id="draggable-list"> <ul class="task-list row">
{% for habit in habits %} {% for habit in habits %}
<li class="row d-flex align-items-center mb-2 draggable" id="habit-{{habit.id}}" draggable="true"> <li class="row d-flex align-items-center mb-2" id="habit-{{habit.id}}">
<div class="col-auto drag-handle" style="cursor: grab;">
<i class="bi bi-grip-vertical"></i>
</div>
<div class="col-auto"> <div class="col-auto">
<input {% if habit.checked %} checked {% endif %} type="checkbox" class="task-checkbox" id="{{habit.id}}" onclick="sendPostRequest('{{habit.id}}')"> <input {% if habit.checked %} checked {% endif %} type="checkbox" class="task-checkbox" id="{{habit.id}}" onclick="sendPostRequest('{{habit.id}}')">
</div> </div>
@ -153,7 +150,7 @@
var progressBar = document.getElementById("progress-bar-" + habitId); var progressBar = document.getElementById("progress-bar-" + habitId);
var habitBlock = document.getElementById("habit-" + habitId); var habitBlock = document.getElementById("habit-" + habitId);
if (percentage == 100) { if (percentage >= 100) {
progressBar.style.backgroundColor = "green"; progressBar.style.backgroundColor = "green";
habitBlock.classList.add("animate-bounce"); habitBlock.classList.add("animate-bounce");
setTimeout(function () { setTimeout(function () {
@ -213,112 +210,6 @@
}); });
} }
</script> </script>
</div> </div>
<script>
const draggable_list = document.getElementById('draggable-list');
const check = document.getElementById('check');
const richestPeople = [
'Jeff Bezos',
'Bill Gates',
'Warren Buffett',
'Bernard Arnault',
'Carlos Slim Helu',
'Amancio Ortega',
'Larry Ellison',
'Mark Zuckerberg',
'Michael Bloomberg',
'Larry Page'
];
// Store listitems
const listItems =
let dragStartIndex;
createList();
// Insert list items into DOM
function createList() {
[...richestPeople]
.map(a => ({ value: a, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(a => a.value)
.forEach((person, index) => {
const listItem = document.createElement('li');
listItem.setAttribute('data-index', index);
listItem.innerHTML = `
<span class="number">${index + 1}</span>
<div class="draggable" draggable="true">
<p class="person-name">${person}</p>
<i class="fas fa-grip-lines"></i>
</div>
`;
listItems.push(listItem);
draggable_list.appendChild(listItem);
});
addEventListeners();
}
function dragStart() {
// console.log('Event: ', 'dragstart');
dragStartIndex = +this.closest('li').getAttribute('data-index');
}
function dragEnter() {
// console.log('Event: ', 'dragenter');
this.classList.add('over');
}
function dragLeave() {
// console.log('Event: ', 'dragleave');
this.classList.remove('over');
}
function dragOver(e) {
// console.log('Event: ', 'dragover');
e.preventDefault();
}
function dragDrop() {
// console.log('Event: ', 'drop');
const dragEndIndex = +this.getAttribute('data-index');
swapItems(dragStartIndex, dragEndIndex);
this.classList.remove('over');
}
// Swap list items that are drag and drop
function swapItems(fromIndex, toIndex) {
const itemOne = listItems[fromIndex].querySelector('.draggable');
const itemTwo = listItems[toIndex].querySelector('.draggable');
listItems[fromIndex].appendChild(itemTwo);
listItems[toIndex].appendChild(itemOne);
}
function addEventListeners() {
const draggables = document.querySelectorAll('.draggable');
const dragListItems = document.querySelectorAll('.draggable-list li');
draggables.forEach(draggable => {
draggable.addEventListener('dragstart', dragStart);
});
dragListItems.forEach(item => {
item.addEventListener('dragover', dragOver);
item.addEventListener('drop', dragDrop);
item.addEventListener('dragenter', dragEnter);
item.addEventListener('dragleave', dragLeave);
});
}
check.addEventListener('click', checkOrder);
</script>
{% endblock %} {% endblock %}

View File

@ -5,11 +5,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1" > <meta name="viewport" content="width=device-width, initial-scale=1" >
<title>{{ title }} - HabitTracker</title> <title>{{ title }} - HabitTracker</title>
<!-- CSS --> <!-- Bootstrap CSS -->
<link rel="stylesheet" href="/static/main.css"> <link rel="stylesheet" href="/static/main.css">
<link href="https://cdn.jsdelivr.net/npm/fastbootstrap@2.2.0/dist/css/fastbootstrap.min.css" rel="stylesheet" integrity="sha256-V6lu+OdYNKTKTsVFBuQsyIlDiRWiOmtC8VQ8Lzdm2i4=" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/fastbootstrap@2.2.0/dist/css/fastbootstrap.min.css" rel="stylesheet" integrity="sha256-V6lu+OdYNKTKTsVFBuQsyIlDiRWiOmtC8VQ8Lzdm2i4=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css" integrity="sha512-ELV+xyi8IhEApPS/pSj66+Jiw+sOT1Mqkzlh8ExXihe4zfqbWkxPRi8wptXIO9g73FSlhmquFlUOuMSoXz5IRw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Axios Library--> <!-- Axios Library-->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
@ -54,8 +53,6 @@
<!-- Bootstrap JS --> <!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js" integrity="sha512-57oZ/vW8ANMjR/KQ6Be9v/+/h6bq9/l3f0Oc7vn6qMqyhvPd1cvKBRWWpzu0QoneImqr2SkmO4MSqU+RpHom3Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</div> </div>
</body> </body>
</html> </html>