Add Dynamic Task Management to "Manage Tasks" Page
Summary
Implemented functionality to dynamically fetch, render, and manage tasks on the "Manage Tasks" page using real-time interactions with the backend.
Features
1. Fetch and Render Tasks
- Created an
async fetchTasks
function to fetch tasks from the database using a GET request. - Rendered tasks dynamically with a
renderTasks
function, displaying:- Task Priority
- Task Information (ID, Name, Assigned To, Status, Due Date)
- Action Buttons (View Details, Update Status, Remove Task).
2. Button Actions
View Details
- Added a fetch request to retrieve task details by Task ID.
- Placeholder functionality for displaying details in a popup/modal.
Update Status
- Added a PATCH request to update task statuses:
- Status transitions:
Active → Currently Working → Closed
orDue → Currently Working → Closed
.
- Status transitions:
- Dynamically updated status without page reloads.
Remove Task
- Added a DELETE request to remove a task by Task ID.
- Automatically refreshes the page on successful deletion.
3. Dynamic Event Binding
- Created an
attachButtonEvents
function to dynamically bind event listeners to:- "View Details" buttons.
- "Update Status" buttons.
- "Remove Task" buttons.
4. Dynamic Styling
- Added class-based styling for:
- Priority Labels:
low-priority
,medium-priority
,high-priority
. - Status Labels:
active
,currently-working
,closed
.
- Priority Labels:
- Designed visually appealing task cards for better user experience.
Notes
- Improved modularity by isolating reusable functions and separating data fetching from rendering.
- Ensured real-time interaction with backend for all task operations.
- Prepared for future UI enhancements, such as modal-based task details.
Impact
This update enables efficient task management by allowing dynamic interactions, improving the user experience, and ensuring scalability.
Update API for Task Management with Enhanced Features
Summary
Enhanced the task management API to handle fetching, deleting, and updating task statuses efficiently. The updates ensure better error handling, improved performance, and flexibility for frontend integrations.
Updates and Features
1. GET Request: Fetch Tasks
- Endpoint:
/add-get-tasks.php?action=fetch
- Functionality: Retrieves all tasks from the
Tasks
table, ordered by theCreatedAt
field in descending order. - Response:
- Success: Returns all tasks as an array.
- Failure: Returns an error message if no tasks are found or a database error occurs.
2. DELETE Request: Remove Tasks
- Endpoint:
/add-get-tasks.php?action=delete
- Functionality:
- Deletes a specific task identified by its
TID
. - Sanitized
TID
input withhtmlspecialchars
to enhance security.
- Deletes a specific task identified by its
- Response:
- Success: Confirms task deletion with a success message.
- Failure: Returns a descriptive error message for invalid
TID
or database errors.
3. Task Status Update (PATCH/DELETE)
- Endpoint:
/add-get-tasks.php?action=update_status
- Functionality:
- Fetches the current
TaskStatus
for the task identified by itsTID
. - Updates the status to the next logical step:
Active → Currently Working
Currently Working → Closed
Due → Currently Working
Closed
remains unchanged.
- Handles invalid statuses gracefully.
- Fetches the current
- Response:
- Success: Confirms the update and returns the new status.
- Failure: Provides error details if the task is not found or a database error occurs.
4. Error Handling
- Added robust error handling for:
- Database connection issues.
- Missing or invalid
TID
. - Unsupported actions or HTTP methods.
- Returns clear, actionable error messages in JSON format.
5. Code Improvements
- Ensured input sanitization using
htmlspecialchars
to prevent XSS vulnerabilities. - Optimized queries with parameterized bindings to prevent SQL injection.
- Used PHP's
match
expression for concise status updates.
Impact
- Improved security by validating and sanitizing inputs.
- Enhanced the API’s flexibility, making it easier for the frontend to integrate dynamic task management features.
- Ensured scalability by implementing logical status transitions and error-proof task deletions.