Add task progress tracking methods documentation and enhance progress update logic
- Introduced a new markdown file detailing task progress tracking methods: manual, weighted, and time-based. - Updated backend logic to include complete ratio calculations for tasks. - Improved socket command for task progress updates, enabling recursive updates for ancestor tasks. - Enhanced frontend components to reflect progress changes based on the selected tracking method, including updates to task display and progress input handling. - Added support for manual progress flag in task model to facilitate accurate progress representation.
This commit is contained in:
@@ -198,6 +198,7 @@ export default class TasksControllerV2 extends TasksControllerBase {
|
||||
(SELECT use_manual_progress FROM projects WHERE id = t.project_id) AS project_use_manual_progress,
|
||||
(SELECT use_weighted_progress FROM projects WHERE id = t.project_id) AS project_use_weighted_progress,
|
||||
(SELECT use_time_progress FROM projects WHERE id = t.project_id) AS project_use_time_progress,
|
||||
(SELECT (get_task_complete_ratio(t.id)).ratio) AS complete_ratio,
|
||||
|
||||
(SELECT phase_id FROM task_phase WHERE task_id = t.id) AS phase_id,
|
||||
(SELECT name
|
||||
|
||||
@@ -35,7 +35,7 @@ export async function on_update_task_progress(io: any, socket: Socket, data: str
|
||||
|
||||
// Get the current progress value to log the change
|
||||
const currentProgressResult = await db.query(
|
||||
"SELECT progress_value, project_id, FROM tasks WHERE id = $1",
|
||||
"SELECT progress_value, project_id FROM tasks WHERE id = $1",
|
||||
[task_id]
|
||||
);
|
||||
|
||||
@@ -70,24 +70,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(
|
||||
"SELECT get_task_complete_ratio($1) as ratio",
|
||||
[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(),
|
||||
{
|
||||
task_id: parent_task_id,
|
||||
progress_value: progressRatio?.rows[0]?.ratio
|
||||
}
|
||||
);
|
||||
}
|
||||
// Recursively update all ancestors in the task hierarchy
|
||||
await updateTaskAncestors(io, projectId, parent_task_id);
|
||||
|
||||
// Notify that project updates are available
|
||||
notifyProjectUpdates(socket, task_id);
|
||||
@@ -95,4 +79,49 @@ export async function on_update_task_progress(io: any, socket: Socket, data: str
|
||||
} catch (error) {
|
||||
log_error(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively updates all ancestor tasks' progress when a subtask changes
|
||||
* @param io Socket.io instance
|
||||
* @param projectId Project ID for room broadcasting
|
||||
* @param taskId The task ID to update (starts with the parent task)
|
||||
*/
|
||||
async function updateTaskAncestors(io: any, projectId: string, taskId: string | null) {
|
||||
if (!taskId) return;
|
||||
|
||||
try {
|
||||
// Get the current task's progress ratio
|
||||
const progressRatio = await db.query(
|
||||
"SELECT get_task_complete_ratio($1) as ratio",
|
||||
[taskId]
|
||||
);
|
||||
|
||||
const ratio = progressRatio?.rows[0]?.ratio;
|
||||
console.log(`Updated task ${taskId} progress: ${ratio}`);
|
||||
|
||||
// Emit the updated progress
|
||||
io.to(projectId).emit(
|
||||
SocketEvents.TASK_PROGRESS_UPDATED.toString(),
|
||||
{
|
||||
task_id: taskId,
|
||||
progress_value: ratio
|
||||
}
|
||||
);
|
||||
|
||||
// Find this task's parent to continue the recursive update
|
||||
const parentResult = await db.query(
|
||||
"SELECT parent_task_id FROM tasks WHERE id = $1",
|
||||
[taskId]
|
||||
);
|
||||
|
||||
const parentTaskId = parentResult.rows[0]?.parent_task_id;
|
||||
|
||||
// If there's a parent, recursively update it
|
||||
if (parentTaskId) {
|
||||
await updateTaskAncestors(io, projectId, parentTaskId);
|
||||
}
|
||||
} catch (error) {
|
||||
log_error(`Error updating ancestor task ${taskId}: ${error}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user