Implement manual and weighted progress features for tasks
- Added SQL migrations to support manual progress and weighted progress calculations in tasks. - Updated the `get_task_complete_ratio` function to consider manual progress and subtask weights. - Enhanced the project model to include flags for manual, weighted, and time-based progress. - Integrated new progress settings in the project drawer and task drawer components. - Implemented socket events for real-time updates on task progress and weight changes. - Updated frontend localization files to include new progress-related terms and tooltips.
This commit is contained in:
@@ -408,6 +408,9 @@ export default class ProjectsController extends WorklenzControllerBase {
|
||||
sps.color_code AS status_color,
|
||||
sps.icon AS status_icon,
|
||||
(SELECT name FROM clients WHERE id = projects.client_id) AS client_name,
|
||||
projects.use_manual_progress,
|
||||
projects.use_weighted_progress,
|
||||
projects.use_time_progress,
|
||||
|
||||
(SELECT COALESCE(ROW_TO_JSON(pm), '{}'::JSON)
|
||||
FROM (SELECT team_member_id AS id,
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Socket } from "socket.io";
|
||||
import db from "../../config/db";
|
||||
import { SocketEvents } from "../events";
|
||||
import { log, log_error, notifyProjectUpdates } from "../util";
|
||||
|
||||
interface UpdateTaskProgressData {
|
||||
task_id: string;
|
||||
progress_value: number;
|
||||
parent_task_id: string | null;
|
||||
}
|
||||
|
||||
export async function on_update_task_progress(io: any, socket: Socket, data: string) {
|
||||
try {
|
||||
log(socket.id, `${SocketEvents.UPDATE_TASK_PROGRESS}: ${data}`);
|
||||
|
||||
const parsedData = JSON.parse(data) as UpdateTaskProgressData;
|
||||
const { task_id, progress_value, parent_task_id } = parsedData;
|
||||
|
||||
if (!task_id || progress_value === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the task progress in the database
|
||||
await db.query(
|
||||
`UPDATE tasks
|
||||
SET progress_value = $1, manual_progress = true, updated_at = NOW()
|
||||
WHERE id = $2`,
|
||||
[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;
|
||||
|
||||
if (projectId) {
|
||||
// Emit the update to all clients in the project room
|
||||
io.to(projectId).emit(
|
||||
SocketEvents.TASK_PROGRESS_UPDATED.toString(),
|
||||
{
|
||||
task_id,
|
||||
progress_value
|
||||
}
|
||||
);
|
||||
|
||||
// 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]
|
||||
);
|
||||
|
||||
// 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
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Notify that project updates are available
|
||||
notifyProjectUpdates(socket, task_id);
|
||||
}
|
||||
} catch (error) {
|
||||
log_error(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Socket } from "socket.io";
|
||||
import db from "../../config/db";
|
||||
import { SocketEvents } from "../events";
|
||||
import { log, log_error, notifyProjectUpdates } from "../util";
|
||||
|
||||
interface UpdateTaskWeightData {
|
||||
task_id: string;
|
||||
weight: number;
|
||||
parent_task_id: string | null;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (!task_id || weight === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the task weight in the database
|
||||
await db.query(
|
||||
`UPDATE tasks
|
||||
SET weight = $1, updated_at = NOW()
|
||||
WHERE id = $2`,
|
||||
[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;
|
||||
|
||||
if (projectId) {
|
||||
// Emit the update to all clients in the project room
|
||||
io.to(projectId).emit(
|
||||
SocketEvents.TASK_PROGRESS_UPDATED.toString(),
|
||||
{
|
||||
task_id,
|
||||
weight
|
||||
}
|
||||
);
|
||||
|
||||
// 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]
|
||||
);
|
||||
|
||||
// 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
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Notify that project updates are available
|
||||
notifyProjectUpdates(socket, task_id);
|
||||
}
|
||||
} catch (error) {
|
||||
log_error(error);
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,10 @@ export enum SocketEvents {
|
||||
TASK_ASSIGNEES_CHANGE,
|
||||
TASK_CUSTOM_COLUMN_UPDATE,
|
||||
CUSTOM_COLUMN_PINNED_CHANGE,
|
||||
TEAM_MEMBER_ROLE_CHANGE,
|
||||
|
||||
// Task progress events
|
||||
UPDATE_TASK_PROGRESS,
|
||||
UPDATE_TASK_WEIGHT,
|
||||
TASK_PROGRESS_UPDATED,
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ import { on_task_recurring_change } from "./commands/on-task-recurring-change";
|
||||
import { on_task_assignees_change } from "./commands/on-task-assignees-change";
|
||||
import { on_task_custom_column_update } from "./commands/on_custom_column_update";
|
||||
import { on_custom_column_pinned_change } from "./commands/on_custom_column_pinned_change";
|
||||
import { on_update_task_progress } from "./commands/on-update-task-progress";
|
||||
import { on_update_task_weight } from "./commands/on-update-task-weight";
|
||||
|
||||
export function register(io: any, socket: Socket) {
|
||||
log(socket.id, "client registered");
|
||||
@@ -106,6 +108,8 @@ export function register(io: any, socket: Socket) {
|
||||
socket.on(SocketEvents.TASK_ASSIGNEES_CHANGE.toString(), data => on_task_assignees_change(io, socket, data));
|
||||
socket.on(SocketEvents.TASK_CUSTOM_COLUMN_UPDATE.toString(), data => on_task_custom_column_update(io, socket, data));
|
||||
socket.on(SocketEvents.CUSTOM_COLUMN_PINNED_CHANGE.toString(), data => on_custom_column_pinned_change(io, socket, data));
|
||||
socket.on(SocketEvents.UPDATE_TASK_PROGRESS.toString(), data => on_update_task_progress(io, socket, data));
|
||||
socket.on(SocketEvents.UPDATE_TASK_WEIGHT.toString(), data => on_update_task_weight(io, socket, data));
|
||||
|
||||
// socket.io built-in event
|
||||
socket.on("disconnect", (reason) => on_disconnect(io, socket, reason));
|
||||
|
||||
Reference in New Issue
Block a user