Skip to content

Commit

Permalink
fix(todo): correct function names and enhance task filtering
Browse files Browse the repository at this point in the history
- Corrected the function name from populateTodofunction to populateTodo.
- Added a new listener function addTaskPopupListener to handle task popups.
- Renamed addActionsBtnListener to actionsBtnListener and added a call to searchFunction within it.
- Introduced a new property is_important for tasks and updated the template to conditionally display the important badge.
- Enhanced the search functionality to apply the current filter after searching.
- Added a new function applyCurrentFilter to filter tasks based on their status (Todo, Done, Important).
  • Loading branch information
psyray committed Sep 11, 2024
1 parent 8031c44 commit d3a9f6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
43 changes: 31 additions & 12 deletions web/recon_note/static/note/js/todo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const populateTodofunction = function(project=null){
const populateTodo = function(project=null){
new PerfectScrollbar('.task-text', {
wheelSpeed:.5,
swipeEasing:!0,
Expand All @@ -14,8 +14,9 @@ const populateTodofunction = function(project=null){
suppressScrollX : true
});

addTaskPopupListener(project);
addTaskBtnListener(project);
addActionsBtnListener();
actionsBtnListener();
checkBtnListener();
importantBtnListener();
todoItemListener();
Expand All @@ -30,14 +31,17 @@ const populateTodofunction = function(project=null){
updateBadgeCounts();
}

const addActionsBtnListener = function(){
const actionsBtnListener = function(){
const $btns = $('.list-actions').click((event) => {
const selectedId = event.currentTarget.id;
const $el = $('.' + selectedId);
$('#ct > div').hide();
$el.fadeIn();
$btns.removeClass('active');
$(event.currentTarget).addClass('active');
const selectedId = event.currentTarget.id;
const $el = $('.' + selectedId);
$('#ct > div').hide();
$el.fadeIn();
$btns.removeClass('active');
$(event.currentTarget).addClass('active');

// Apply search and filter when changing menu
searchFunction();
});
}

Expand Down Expand Up @@ -119,7 +123,8 @@ const addTaskPopupListener = function(project) {
description: htmlEncode($_taskDescriptionText),
domain_name: htmlEncode($_targetText),
subdomain_name: htmlEncode($_taskSubdomain),
is_done: false
is_done: false,
is_important: false
};

let todoHTML = $('#todo-template').html();
Expand All @@ -130,7 +135,8 @@ const addTaskPopupListener = function(project) {
.replace(/{target_text}/g, newNote.domain_name ? `Domain: ${newNote.domain_name}` : '')
.replace(/{description}/g, newNote.description)
.replace(/{is_done}/g, newNote.is_done ? 'todo-task-done' : '')
.replace(/{checked}/g, newNote.is_done ? 'checked' : '');
.replace(/{checked}/g, newNote.is_done ? 'checked' : '')
.replace(/{is_important}/g, newNote.is_important ? 'todo-task-important' : '');

const $newTodo = $('<div class="todo-item all-list"></div>').append(todoHTML);

Expand Down Expand Up @@ -367,13 +373,26 @@ const searchFunction = function() {
const rex = new RegExp(searchTerm, 'i'); // Create a regex from the input
$('.todo-box .todo-item').hide(); // Hide all items
$('.todo-box .todo-item').filter(function() {
return rex.test($(this).text()); // Show items that match the regex
return rex.test($(this).text()); // Show items that match the regex
}).show();

// Apply the current filter after search
applyCurrentFilter();

// Update badge counts after filtering
updateBadgeCounts();
};

// Function to apply the current filter (Todo, Done, Important)
const applyCurrentFilter = function() {
const currentFilter = $('.list-actions.active').attr('id');
if (currentFilter === 'todo-task-done') {
$('.todo-box .todo-item:visible').not('.todo-task-done').hide();
} else if (currentFilter === 'todo-task-important') {
$('.todo-box .todo-item:visible').not('.todo-task-important').hide();
}
};

$(document).ready(function() {
// Show or hide the clear button based on input
const updateClearButtonVisibility = function() {
Expand Down
4 changes: 2 additions & 2 deletions web/recon_note/templates/note/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h5 class="todo-heading">{title}</h5>
<p class="target">{target_text}</p>
<p class="todo-text">{description}</p>
</div>
<div class="priority-dropdown custom-dropdown-icon" id="important-badge-{task_id}" style="display: flex; align-items: center;">
<div class="priority-dropdown custom-dropdown-icon" id="important-badge-{task_id}" style="display: flex; align-items: center; {% if not is_important %} display: none; {% endif %}">
<div class="dropdown p-dropdown">
<span class="text-danger bs-tooltip" title="Important Todo">
<i class="fa fa-exclamation-circle"></i>
Expand Down Expand Up @@ -249,7 +249,7 @@ <h5 class="todo-heading">${htmlEncode(note_obj['title'])}</h5>
todo_item.classList.add("todo-task-important");
}
};
populateTodofunction(project='{{current_project.slug}}');
populateTodo(project='{{current_project.slug}}');
$('.bs-tooltip').tooltip();
});
</script>
Expand Down

0 comments on commit d3a9f6b

Please sign in to comment.