Add task progress tracking methods and enhance UI components

- Introduced a comprehensive guide for users on task progress tracking methods, including manual, weighted, and time-based progress.
- Implemented backend support for progress calculations, including SQL functions and migrations to accommodate new progress features.
- Enhanced frontend components to support progress input and display, including updates to task and project drawers.
- Added localization for new progress-related terms and validation messages.
- Integrated real-time updates for task progress and weight changes through socket events.
This commit is contained in:
chamiakJ
2025-04-30 15:24:07 +05:30
parent a2bfdb682b
commit 6128c64c31
24 changed files with 1466 additions and 150 deletions

View File

@@ -5,6 +5,8 @@ import TasksControllerV2 from "../../controllers/tasks-controller-v2";
export async function on_get_task_progress(_io: Server, socket: Socket, taskId?: string) {
try {
console.log(`GET_TASK_PROGRESS requested for task: ${taskId}`);
const task: any = {};
task.id = taskId;
@@ -13,6 +15,8 @@ export async function on_get_task_progress(_io: Server, socket: Socket, taskId?:
task.complete_ratio = info.ratio;
task.completed_count = info.total_completed;
task.total_tasks_count = info.total_tasks;
console.log(`Sending task progress for task ${taskId}: complete_ratio=${task.complete_ratio}`);
}
return socket.emit(SocketEvents.GET_TASK_PROGRESS.toString(), task);

View File

@@ -2,6 +2,7 @@ import { Socket } from "socket.io";
import db from "../../config/db";
import { SocketEvents } from "../events";
import { log, log_error, notifyProjectUpdates } from "../util";
import { logProgressChange } from "../../services/activity-logs/activity-logs.service";
interface UpdateTaskProgressData {
task_id: string;
@@ -16,10 +17,38 @@ export async function on_update_task_progress(io: any, socket: Socket, data: str
const parsedData = JSON.parse(data) as UpdateTaskProgressData;
const { task_id, progress_value, parent_task_id } = parsedData;
console.log(`Updating progress for task ${task_id}: new value = ${progress_value}`);
if (!task_id || progress_value === undefined) {
return;
}
// Check if this is a parent task (has subtasks)
const subTasksResult = await db.query(
"SELECT COUNT(*) as subtask_count FROM tasks WHERE parent_task_id = $1",
[task_id]
);
const subtaskCount = parseInt(subTasksResult.rows[0]?.subtask_count || '0');
// If this is a parent task, we shouldn't set manual progress
if (subtaskCount > 0) {
console.log(`Cannot set manual progress on parent task ${task_id} with ${subtaskCount} subtasks`);
return;
}
// Get the current progress value to log the change
const currentProgressResult = await db.query(
"SELECT progress_value, project_id, team_id FROM tasks WHERE id = $1",
[task_id]
);
const currentProgress = currentProgressResult.rows[0]?.progress_value;
const projectId = currentProgressResult.rows[0]?.project_id;
const teamId = currentProgressResult.rows[0]?.team_id;
console.log(`Previous progress for task ${task_id}: ${currentProgress}; New: ${progress_value}`);
// Update the task progress in the database
await db.query(
`UPDATE tasks
@@ -28,9 +57,13 @@ export async function on_update_task_progress(io: any, socket: Socket, data: str
[progress_value, task_id]
);
// Get the project ID for the task
const projectResult = await db.query("SELECT project_id FROM tasks WHERE id = $1", [task_id]);
const projectId = projectResult.rows[0]?.project_id;
// Log the progress change using the activity logs service
await logProgressChange({
task_id,
old_value: currentProgress !== null ? currentProgress.toString() : '0',
new_value: progress_value.toString(),
socket
});
if (projectId) {
// Emit the update to all clients in the project room
@@ -42,6 +75,8 @@ export async function on_update_task_progress(io: any, socket: Socket, data: str
}
);
console.log(`Emitted progress update for task ${task_id} to project room ${projectId}`);
// If this is a subtask, update the parent task's progress
if (parent_task_id) {
const progressRatio = await db.query(
@@ -49,6 +84,8 @@ export async function on_update_task_progress(io: any, socket: Socket, data: str
[parent_task_id]
);
console.log(`Updated parent task ${parent_task_id} progress: ${progressRatio?.rows[0]?.ratio}`);
// Emit the parent task's updated progress
io.to(projectId).emit(
SocketEvents.TASK_PROGRESS_UPDATED.toString(),

View File

@@ -2,6 +2,7 @@ import { Socket } from "socket.io";
import db from "../../config/db";
import { SocketEvents } from "../events";
import { log, log_error, notifyProjectUpdates } from "../util";
import { logWeightChange } from "../../services/activity-logs/activity-logs.service";
interface UpdateTaskWeightData {
task_id: string;
@@ -11,7 +12,6 @@ interface UpdateTaskWeightData {
export async function on_update_task_weight(io: any, socket: Socket, data: string) {
try {
log(socket.id, `${SocketEvents.UPDATE_TASK_WEIGHT}: ${data}`);
const parsedData = JSON.parse(data) as UpdateTaskWeightData;
const { task_id, weight, parent_task_id } = parsedData;
@@ -20,6 +20,15 @@ export async function on_update_task_weight(io: any, socket: Socket, data: strin
return;
}
// Get the current weight value to log the change
const currentWeightResult = await db.query(
"SELECT weight, project_id FROM tasks WHERE id = $1",
[task_id]
);
const currentWeight = currentWeightResult.rows[0]?.weight;
const projectId = currentWeightResult.rows[0]?.project_id;
// Update the task weight in the database
await db.query(
`UPDATE tasks
@@ -28,9 +37,13 @@ export async function on_update_task_weight(io: any, socket: Socket, data: strin
[weight, task_id]
);
// Get the project ID for the task
const projectResult = await db.query("SELECT project_id FROM tasks WHERE id = $1", [task_id]);
const projectId = projectResult.rows[0]?.project_id;
// Log the weight change using the activity logs service
await logWeightChange({
task_id,
old_value: currentWeight !== null ? currentWeight.toString() : '100',
new_value: weight.toString(),
socket
});
if (projectId) {
// Emit the update to all clients in the project room