Skip to content

Commit

Permalink
refactor(todo): simplify badge update logic and remove unused checkbo…
Browse files Browse the repository at this point in the history
…x elements

- Simplified the logic for updating badge notifications in the todo list by consolidating repeated code into a single function.
- Removed unused checkbox elements from the todo item template and related HTML.
  • Loading branch information
psyray committed Sep 16, 2024
1 parent 9056061 commit 9b9a42e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 63 deletions.
80 changes: 30 additions & 50 deletions web/recon_note/static/note/js/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,68 +159,48 @@ const addTaskPopupListener = function(project) {
const dynamicBadgeNotification = function(setTodoCategoryCount) {
const todoCategoryCount = setTodoCategoryCount;

// Get Parents Div(s)
const get_TodoAllListParentsDiv = $('.todo-item.all-list').not('.todo-item-template').filter(':visible');
const get_TodoCompletedListParentsDiv = $('.todo-item.todo-task-done').not('.todo-item-template').filter(':visible');
const get_TodoImportantListParentsDiv = $('.todo-item.todo-task-important').not('.todo-item-template').filter(':visible');
// Compter les éléments en se basant uniquement sur les classes CSS
const get_TodoAllListParentsDiv = $('.todo-item').not('.todo-item-template');
const get_TodoCompletedListParentsDiv = $('.todo-item.todo-task-done').not('.todo-item-template');
const get_TodoImportantListParentsDiv = $('.todo-item.todo-task-important').not('.todo-item-template');

// Get Parents Div(s) Counts
// Obtenir les comptes
const get_TodoListElementsCount = get_TodoAllListParentsDiv.length;
const get_CompletedTaskElementsCount = get_TodoCompletedListParentsDiv.length;
const get_ImportantTaskElementsCount = get_TodoImportantListParentsDiv.length;

// Get Badge Div(s)
// Obtenir les éléments de badge
const getBadgeTodoAllListDiv = $('#all-list .todo-badge');
const getBadgeCompletedTaskListDiv = $('#todo-task-done .todo-badge');
const getBadgeImportantTaskListDiv = $('#todo-task-important .todo-badge');

if (todoCategoryCount === 'allList') {
if (get_TodoListElementsCount === 0) {
getBadgeTodoAllListDiv.text('');
return;
}
if (get_TodoListElementsCount > 9) {
getBadgeTodoAllListDiv.css({
padding: '2px 0px',
height: '25px',
width: '25px'
});
} else if (get_TodoListElementsCount <= 9) {
getBadgeTodoAllListDiv.removeAttr('style');
// Fonction pour mettre à jour un badge
const updateBadge = function(badgeElement, count) {
if (count === 0) {
badgeElement.text('');
} else {
badgeElement.text(count);
if (count > 9) {
badgeElement.css({
padding: '2px 0px',
height: '25px',
width: '25px'
});
} else {
badgeElement.removeAttr('style');
}
}
getBadgeTodoAllListDiv.text(get_TodoListElementsCount);
};

// Mettre à jour les badges en fonction de la catégorie
if (todoCategoryCount === 'allList' || todoCategoryCount === undefined) {
updateBadge(getBadgeTodoAllListDiv, get_TodoListElementsCount);
}
else if (todoCategoryCount === 'completedList') {
if (get_CompletedTaskElementsCount === 0) {
getBadgeCompletedTaskListDiv.text('');
return;
}
if (get_CompletedTaskElementsCount > 9) {
getBadgeCompletedTaskListDiv.css({
padding: '2px 0px',
height: '25px',
width: '25px'
});
} else if (get_CompletedTaskElementsCount <= 9) {
getBadgeCompletedTaskListDiv.removeAttr('style');
}
getBadgeCompletedTaskListDiv.text(get_CompletedTaskElementsCount);
if (todoCategoryCount === 'completedList' || todoCategoryCount === undefined) {
updateBadge(getBadgeCompletedTaskListDiv, get_CompletedTaskElementsCount);
}
else if (todoCategoryCount === 'importantList') {
if (get_ImportantTaskElementsCount === 0) {
getBadgeImportantTaskListDiv.text('');
return;
}
if (get_ImportantTaskElementsCount > 9) {
getBadgeImportantTaskListDiv.css({
padding: '2px 0px',
height: '25px',
width: '25px'
});
} else if (get_ImportantTaskElementsCount <= 9) {
getBadgeImportantTaskListDiv.removeAttr('style');
}
getBadgeImportantTaskListDiv.text(get_ImportantTaskElementsCount);
if (todoCategoryCount === 'importantList' || todoCategoryCount === undefined) {
updateBadge(getBadgeImportantTaskListDiv, get_ImportantTaskElementsCount);
}
}

Expand Down
13 changes: 0 additions & 13 deletions web/recon_note/templates/note/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ <h5 class="">Add to-do</h5>
<div class="todo-item-template">
<div class="todo-item-content {is_done}">
<div class="todo-item-inner">
<div class="n-chk text-center">
<label class="new-control new-checkbox checkbox-primary">
<input type="checkbox" class="form-check-input inbox-chkbox" id="checkbox_{task_id}" {checked}>
<span class="new-control-indicator"></span>
</label>
</div>
<div class="todo-content">
<h5 class="todo-heading">{title}</h5>
<p class="target">{target_text}</p>
Expand Down Expand Up @@ -215,12 +209,6 @@ <h5 class="todo-heading">{title}</h5>
}
var badges = is_important_badge;
var html = `<div class="todo-item-inner">
<div class="n-chk text-center">
<label class="new-control new-checkbox checkbox-primary">
<input type="checkbox" class="new-control-input inbox-chkbox" id="checkbox_${note_obj['id']}">
<span class="new-control-indicator"></span>
</label>
</div>
<div class="todo-content">
<h5 class="todo-heading">${htmlEncode(note_obj['title'])}</h5>
<p class="target">${target_text}</p>
Expand All @@ -243,7 +231,6 @@ <h5 class="todo-heading">${htmlEncode(note_obj['title'])}</h5>
document.getElementById('ct').appendChild(todo_item);
if (note_obj['is_done']) {
todo_item.classList.add("todo-task-done");
document.getElementById('checkbox_'+note_obj['id']).checked = true;
}
if (note_obj['is_important']) {
todo_item.classList.add("todo-task-important");
Expand Down

0 comments on commit 9b9a42e

Please sign in to comment.