Compare commits
No commits in common. "119a31302cb6423c80bf29ac24c43fa22c95df60" and "f8ee727705acd6181d796eea2c9d9586d218c263" have entirely different histories.
119a31302c
...
f8ee727705
@ -23,22 +23,25 @@ class Habit:
|
||||
slot: int
|
||||
percentage: int = 0
|
||||
|
||||
|
||||
def __post_init__(self):
|
||||
self.fill_statistics()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1):
|
||||
slot = get_next_slot(user_id)
|
||||
id = create_habit(user_id, name, times, unit, slot, note)
|
||||
return Habit(id, user_id, name, note, times, unit, slot)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get(id: int):
|
||||
habit = get_habit(id)
|
||||
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
|
||||
|
||||
return habit
|
||||
|
||||
|
||||
def update(self, name: str=None, note: str=None, times: int=None, unit: int=None):
|
||||
update_habit(self.id, name, note, times, unit)
|
||||
if name is not None:
|
||||
@ -50,10 +53,12 @@ class Habit:
|
||||
if unit is not None:
|
||||
self.unit = unit
|
||||
|
||||
|
||||
# So sollte die Slots Liste aussehen damit es funktioniert
|
||||
#[(id, 1), (id, 2), (id, 3), (id, 4), (id, 5)]
|
||||
def update_slot(self, new_slot: int):
|
||||
slots = get_slots(self.user_id)
|
||||
print(slots)
|
||||
if new_slot > self.slot:
|
||||
slots = slots[self.slot:new_slot]
|
||||
for slot in slots:
|
||||
@ -62,7 +67,7 @@ class Habit:
|
||||
slots = slots[new_slot-1:self.slot-1]
|
||||
for slot in slots:
|
||||
update_slot(slot[0], slot[1]+1)
|
||||
self.slot = new_slot
|
||||
update_slot(self.id, new_slot)
|
||||
|
||||
|
||||
def delete(self):
|
||||
@ -81,12 +86,12 @@ class Habit:
|
||||
count = 0
|
||||
self.checked = False
|
||||
for tracking in self.get_habitTrackings():
|
||||
if tracking.created_at.day == datetime.today().day:
|
||||
if tracking.created_at == datetime.today():
|
||||
self.checked = True
|
||||
|
||||
# day
|
||||
if self.unit == 0:
|
||||
if tracking.created_at.day == datetime.today().day:
|
||||
if tracking.created_at == datetime.today():
|
||||
# self.checked = True
|
||||
count += 1
|
||||
# week
|
||||
@ -106,7 +111,3 @@ class Habit:
|
||||
count += 1
|
||||
|
||||
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)
|
||||
|
||||
@ -89,12 +89,9 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="task-list row draggable-list" id="draggable-list">
|
||||
<ul class="task-list row">
|
||||
{% for habit in habits %}
|
||||
<li class="row d-flex align-items-center mb-2 draggable" id="habit-{{habit.id}}" draggable="true">
|
||||
<div class="col-auto drag-handle" style="cursor: grab;">
|
||||
<i class="bi bi-grip-vertical"></i>
|
||||
</div>
|
||||
<li class="row d-flex align-items-center mb-2" id="habit-{{habit.id}}">
|
||||
<div class="col-auto">
|
||||
<input {% if habit.checked %} checked {% endif %} type="checkbox" class="task-checkbox" id="{{habit.id}}" onclick="sendPostRequest('{{habit.id}}')">
|
||||
</div>
|
||||
@ -153,7 +150,7 @@
|
||||
var progressBar = document.getElementById("progress-bar-" + habitId);
|
||||
var habitBlock = document.getElementById("habit-" + habitId);
|
||||
|
||||
if (percentage == 100) {
|
||||
if (percentage >= 100) {
|
||||
progressBar.style.backgroundColor = "green";
|
||||
habitBlock.classList.add("animate-bounce");
|
||||
setTimeout(function () {
|
||||
@ -213,112 +210,6 @@
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</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 %}
|
||||
@ -5,11 +5,10 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" >
|
||||
<title>{{ title }} - HabitTracker</title>
|
||||
|
||||
<!-- CSS -->
|
||||
<!-- Bootstrap 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 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-->
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||
@ -54,8 +53,6 @@
|
||||
|
||||
<!-- 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://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>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user