Skip to content

Tags: BOSS294/Task-Management-WebSoftware

Tags

V3.0

Toggle V3.0's commit message
# Commit: 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` or `Due → Currently Working → Closed`.
- 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`.
- 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.

# Commit: 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 the `CreatedAt` 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 with `htmlspecialchars` to enhance security.
- **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 its `TID`.
  - Updates the status to the next logical step:
    - `Active → Currently Working`
    - `Currently Working → Closed`
    - `Due → Currently Working`
    - `Closed` remains unchanged.
  - Handles invalid statuses gracefully.
- **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.