diff --git a/docs/recurring-tasks-user-guide.md b/docs/recurring-tasks-user-guide.md new file mode 100644 index 00000000..3d91572a --- /dev/null +++ b/docs/recurring-tasks-user-guide.md @@ -0,0 +1,60 @@ +# Recurring Tasks: User Guide + +## What Are Recurring Tasks? +Recurring tasks are tasks that repeat automatically on a schedule you choose. This helps you save time and ensures important work is never forgotten. For example, you can set up a recurring task for weekly team meetings, monthly reports, or daily check-ins. + +## Why Use Recurring Tasks? +- **Save time:** No need to create the same task over and over. +- **Stay organized:** Tasks appear automatically when needed. +- **Never miss a deadline:** Tasks are created on time, every time. + +## How to Set Up a Recurring Task +1. Go to the tasks section in your workspace. +2. Choose to create a new task and look for the option to make it recurring. +3. Fill in the task details (name, description, assignees, etc.). +4. Select your preferred schedule (see options below). +5. Save the task. It will now be created automatically based on your chosen schedule. + +## Schedule Options +You can choose how often your task repeats. Here are the available options: + +- **Daily:** The task is created every day. +- **Weekly:** The task is created once a week. You can pick one or more days (e.g., every Monday and Thursday). +- **Monthly:** The task is created once a month. You have two options: + - **On a specific date:** Choose a date from 1 to 28 (limited to 28 to ensure consistency across all months) + - **On a specific day:** Choose a week (first, second, third, fourth, or last) and a day of the week +- **Every X Days:** The task is created every specified number of days (e.g., every 3 days) +- **Every X Weeks:** The task is created every specified number of weeks (e.g., every 2 weeks) +- **Every X Months:** The task is created every specified number of months (e.g., every 3 months) + +### Examples +- "Send team update" every Friday (weekly) +- "Submit expense report" on the 15th of each month (monthly, specific date) +- "Monthly team meeting" on the first Monday of each month (monthly, specific day) +- "Check backups" every day (daily) +- "Review project status" every Monday and Thursday (weekly, multiple days) +- "Quarterly report" every 3 months (every X months) + +## Future Task Creation +The system automatically creates tasks up to a certain point in the future to ensure timely scheduling: + +- **Daily Tasks:** Created up to 7 days in advance +- **Weekly Tasks:** Created up to 2 weeks in advance +- **Monthly Tasks:** Created up to 2 months in advance +- **Every X Days/Weeks/Months:** Created up to 2 intervals in advance + +This ensures that: +- You always have upcoming tasks visible in your schedule +- Tasks are created at appropriate intervals +- The system maintains a reasonable number of future tasks + +## Tips +- You can edit or stop a recurring task at any time. +- Assign team members and labels to recurring tasks for better organization. +- Check your task list regularly to see newly created recurring tasks. +- For monthly tasks, dates are limited to 1-28 to ensure the task occurs on the same date every month. +- Tasks are created automatically within the future limit window - you don't need to manually create them. +- If you need to see tasks further in the future, they will be created automatically as the current tasks are completed. + +## Need Help? +If you have questions or need help setting up recurring tasks, contact your workspace admin or support team. \ No newline at end of file diff --git a/docs/recurring-tasks.md b/docs/recurring-tasks.md new file mode 100644 index 00000000..71448719 --- /dev/null +++ b/docs/recurring-tasks.md @@ -0,0 +1,104 @@ +# Recurring Tasks Cron Job Documentation + +## Overview +The recurring tasks cron job automates the creation of tasks based on predefined templates and schedules. It ensures that tasks are generated at the correct intervals without manual intervention, supporting efficient project management and timely task assignment. + +## Purpose +- Automatically create tasks according to recurring schedules defined in the database. +- Prevent duplicate task creation for the same schedule and date. +- Assign team members and labels to newly created tasks as specified in the template. + +## Scheduling Logic +- The cron job is scheduled using the [cron](https://www.npmjs.com/package/cron) package. +- The schedule is defined by a cron expression (e.g., `*/2 * * * *` for every 2 minutes, or `0 11 */1 * 1-5` for 11:00 UTC on weekdays). +- On each tick, the job: + 1. Fetches all recurring task templates and their schedules. + 2. Determines the next occurrence for each template using `calculateNextEndDate`. + 3. Checks if a task for the next occurrence already exists. + 4. Creates a new task if it does not exist and the next occurrence is within the allowed future window. + +## Future Limit Logic +The system implements different future limits based on the schedule type to maintain an appropriate number of future tasks: + +```typescript +const FUTURE_LIMITS = { + daily: moment.duration(7, 'days'), + weekly: moment.duration(2, 'weeks'), + monthly: moment.duration(2, 'months'), + every_x_days: (interval: number) => moment.duration(interval * 2, 'days'), + every_x_weeks: (interval: number) => moment.duration(interval * 2, 'weeks'), + every_x_months: (interval: number) => moment.duration(interval * 2, 'months') +}; +``` + +### Implementation Details +- **Base Calculation:** + ```typescript + const futureLimit = moment(template.last_checked_at || template.created_at) + .add(getFutureLimit(schedule.schedule_type, schedule.interval), 'days'); + ``` + +- **Task Creation Rules:** + 1. Only create tasks if the next occurrence is before the future limit + 2. Skip creation if a task already exists for that date + 3. Update `last_checked_at` after processing + +- **Benefits:** + - Prevents excessive task creation + - Maintains system performance + - Ensures timely task visibility + - Allows for schedule modifications + +## Date Handling +- **Monthly Tasks:** + - Dates are limited to 1-28 to ensure consistency across all months + - This prevents issues with months having different numbers of days + - No special handling needed for February or months with 30/31 days +- **Weekly Tasks:** + - Supports multiple days of the week (0-6, where 0 is Sunday) + - Tasks are created for each selected day +- **Interval-based Tasks:** + - Every X days/weeks/months from the last task's end date + - Minimum interval is 1 day/week/month + - No maximum limit, but tasks are only created up to the future limit + +## Database Interactions +- **Templates and Schedules:** + - Templates are stored in `task_recurring_templates`. + - Schedules are stored in `task_recurring_schedules`. + - The job joins these tables to get all necessary data for task creation. +- **Task Creation:** + - Uses a stored procedure `create_quick_task` to insert new tasks. + - Assigns team members and labels by calling appropriate functions/controllers. +- **State Tracking:** + - Updates `last_checked_at` and `last_created_task_end_date` in the schedule after processing. + - Maintains future limits based on schedule type. + +## Task Creation Process +1. **Fetch Templates:** Retrieve all templates and their associated schedules. +2. **Determine Next Occurrence:** Use the last task's end date or the schedule's creation date to calculate the next due date. +3. **Check for Existing Task:** Ensure no duplicate task is created for the same schedule and date. +4. **Create Task:** + - Insert the new task using the template's data. + - Assign team members and labels as specified. +5. **Update Schedule:** Record the last checked and created dates for accurate future runs. + +## Configuration & Extension Points +- **Cron Expression:** Modify the `TIME` constant in the code to change the schedule. +- **Task Template Structure:** Extend the template or schedule interfaces to support additional fields. +- **Task Creation Logic:** Customize the task creation process or add new assignment/labeling logic as needed. +- **Future Window:** Adjust the future limits by modifying the `FUTURE_LIMITS` configuration. + +## Error Handling +- Errors are logged using the `log_error` utility. +- The job continues processing other templates even if one fails. +- Failed task creations are not retried automatically. + +## References +- Source: `src/cron_jobs/recurring-tasks.ts` +- Utilities: `src/shared/utils.ts` +- Database: `src/config/db.ts` +- Controllers: `src/controllers/tasks-controller.ts` + +--- +For further customization or troubleshooting, refer to the source code and update the documentation as needed. \ No newline at end of file diff --git a/worklenz-backend/.env.template b/worklenz-backend/.env.template index e0bea264..fdd8fe44 100644 --- a/worklenz-backend/.env.template +++ b/worklenz-backend/.env.template @@ -78,4 +78,8 @@ GOOGLE_CAPTCHA_SECRET_KEY=your_captcha_secret_key GOOGLE_CAPTCHA_PASS_SCORE=0.8 # Email Cronjobs -ENABLE_EMAIL_CRONJOBS=true \ No newline at end of file +ENABLE_EMAIL_CRONJOBS=true + +# RECURRING_JOBS +ENABLE_RECURRING_JOBS=true +RECURRING_JOBS_INTERVAL="0 11 */1 * 1-5" \ No newline at end of file diff --git a/worklenz-backend/database/migrations/20250427000000-fix-progress-mode-type.sql b/worklenz-backend/database/migrations/20250427000000-fix-progress-mode-type.sql new file mode 100644 index 00000000..557b1bc5 --- /dev/null +++ b/worklenz-backend/database/migrations/20250427000000-fix-progress-mode-type.sql @@ -0,0 +1,160 @@ +-- Migration: Fix progress_mode_type ENUM and casting issues +-- Date: 2025-04-27 +-- Version: 1.0.0 + +BEGIN; + +-- First, let's ensure the ENUM type exists with the correct values +DO $$ +BEGIN + -- Check if the type exists + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'progress_mode_type') THEN + CREATE TYPE progress_mode_type AS ENUM ('manual', 'weighted', 'time', 'default'); + ELSE + -- Add any missing values to the existing ENUM + BEGIN + ALTER TYPE progress_mode_type ADD VALUE IF NOT EXISTS 'manual'; + ALTER TYPE progress_mode_type ADD VALUE IF NOT EXISTS 'weighted'; + ALTER TYPE progress_mode_type ADD VALUE IF NOT EXISTS 'time'; + ALTER TYPE progress_mode_type ADD VALUE IF NOT EXISTS 'default'; + EXCEPTION + WHEN duplicate_object THEN + -- Ignore if values already exist + NULL; + END; + END IF; +END $$; + +-- Update functions to use proper type casting +CREATE OR REPLACE FUNCTION on_update_task_progress(_body json) RETURNS json + LANGUAGE plpgsql +AS +$$ +DECLARE + _task_id UUID; + _progress_value INTEGER; + _parent_task_id UUID; + _project_id UUID; + _current_mode progress_mode_type; +BEGIN + _task_id = (_body ->> 'task_id')::UUID; + _progress_value = (_body ->> 'progress_value')::INTEGER; + _parent_task_id = (_body ->> 'parent_task_id')::UUID; + + -- Get the project ID and determine the current progress mode + SELECT project_id INTO _project_id FROM tasks WHERE id = _task_id; + + IF _project_id IS NOT NULL THEN + SELECT + CASE + WHEN use_manual_progress IS TRUE THEN 'manual'::progress_mode_type + WHEN use_weighted_progress IS TRUE THEN 'weighted'::progress_mode_type + WHEN use_time_progress IS TRUE THEN 'time'::progress_mode_type + ELSE 'default'::progress_mode_type + END + INTO _current_mode + FROM projects + WHERE id = _project_id; + ELSE + _current_mode := 'default'::progress_mode_type; + END IF; + + -- Update the task with progress value and set the progress mode + UPDATE tasks + SET progress_value = _progress_value, + manual_progress = TRUE, + progress_mode = _current_mode, + updated_at = CURRENT_TIMESTAMP + WHERE id = _task_id; + + -- Return the updated task info + RETURN JSON_BUILD_OBJECT( + 'task_id', _task_id, + 'progress_value', _progress_value, + 'progress_mode', _current_mode + ); +END; +$$; + +-- Update the on_update_task_weight function to use proper type casting +CREATE OR REPLACE FUNCTION on_update_task_weight(_body json) RETURNS json + LANGUAGE plpgsql +AS +$$ +DECLARE + _task_id UUID; + _weight INTEGER; + _parent_task_id UUID; + _project_id UUID; +BEGIN + _task_id = (_body ->> 'task_id')::UUID; + _weight = (_body ->> 'weight')::INTEGER; + _parent_task_id = (_body ->> 'parent_task_id')::UUID; + + -- Get the project ID + SELECT project_id INTO _project_id FROM tasks WHERE id = _task_id; + + -- Update the task with weight value and set progress_mode to 'weighted' + UPDATE tasks + SET weight = _weight, + progress_mode = 'weighted'::progress_mode_type, + updated_at = CURRENT_TIMESTAMP + WHERE id = _task_id; + + -- Return the updated task info + RETURN JSON_BUILD_OBJECT( + 'task_id', _task_id, + 'weight', _weight + ); +END; +$$; + +-- Update the reset_project_progress_values function to use proper type casting +CREATE OR REPLACE FUNCTION reset_project_progress_values() RETURNS TRIGGER + LANGUAGE plpgsql +AS +$$ +DECLARE + _old_mode progress_mode_type; + _new_mode progress_mode_type; + _project_id UUID; +BEGIN + _project_id := NEW.id; + + -- Determine old and new modes with proper type casting + _old_mode := + CASE + WHEN OLD.use_manual_progress IS TRUE THEN 'manual'::progress_mode_type + WHEN OLD.use_weighted_progress IS TRUE THEN 'weighted'::progress_mode_type + WHEN OLD.use_time_progress IS TRUE THEN 'time'::progress_mode_type + ELSE 'default'::progress_mode_type + END; + + _new_mode := + CASE + WHEN NEW.use_manual_progress IS TRUE THEN 'manual'::progress_mode_type + WHEN NEW.use_weighted_progress IS TRUE THEN 'weighted'::progress_mode_type + WHEN NEW.use_time_progress IS TRUE THEN 'time'::progress_mode_type + ELSE 'default'::progress_mode_type + END; + + -- If mode has changed, reset progress values for tasks with the old mode + IF _old_mode <> _new_mode THEN + -- Reset progress values for tasks that were set in the old mode + UPDATE tasks + SET progress_value = NULL, + progress_mode = NULL + WHERE project_id = _project_id + AND progress_mode = _old_mode; + END IF; + + RETURN NEW; +END; +$$; + +-- Update the tasks table to ensure proper type casting for existing values +UPDATE tasks +SET progress_mode = progress_mode::text::progress_mode_type +WHERE progress_mode IS NOT NULL; + +COMMIT; \ No newline at end of file diff --git a/worklenz-backend/database/migrations/consolidated-progress-migrations.sql b/worklenz-backend/database/migrations/consolidated-progress-migrations.sql index c1007d24..ef89a923 100644 --- a/worklenz-backend/database/migrations/consolidated-progress-migrations.sql +++ b/worklenz-backend/database/migrations/consolidated-progress-migrations.sql @@ -23,33 +23,40 @@ ALTER TABLE projects ADD COLUMN IF NOT EXISTS use_time_progress BOOLEAN DEFAULT FALSE; -- Update function to consider manual progress -CREATE OR REPLACE FUNCTION get_task_complete_ratio(_task_id UUID) RETURNS JSON +CREATE OR REPLACE FUNCTION get_task_complete_ratio(_task_id uuid) RETURNS json LANGUAGE plpgsql AS $$ DECLARE - _parent_task_done FLOAT = 0; - _sub_tasks_done FLOAT = 0; - _sub_tasks_count FLOAT = 0; - _total_completed FLOAT = 0; - _total_tasks FLOAT = 0; - _ratio FLOAT = 0; - _is_manual BOOLEAN = FALSE; - _manual_value INTEGER = NULL; - _project_id UUID; - _use_manual_progress BOOLEAN = FALSE; + _parent_task_done FLOAT = 0; + _sub_tasks_done FLOAT = 0; + _sub_tasks_count FLOAT = 0; + _total_completed FLOAT = 0; + _total_tasks FLOAT = 0; + _ratio FLOAT = 0; + _is_manual BOOLEAN = FALSE; + _manual_value INTEGER = NULL; + _project_id UUID; + _use_manual_progress BOOLEAN = FALSE; _use_weighted_progress BOOLEAN = FALSE; - _use_time_progress BOOLEAN = FALSE; + _use_time_progress BOOLEAN = FALSE; + _task_complete BOOLEAN = FALSE; + _progress_mode VARCHAR(20) = NULL; BEGIN - -- Check if manual progress is set - SELECT manual_progress, progress_value, project_id + -- Check if manual progress is set for this task + SELECT manual_progress, progress_value, project_id, progress_mode, + EXISTS( + SELECT 1 + FROM tasks_with_status_view + WHERE tasks_with_status_view.task_id = tasks.id + AND is_done IS TRUE + ) AS is_complete FROM tasks WHERE id = _task_id - INTO _is_manual, _manual_value, _project_id; + INTO _is_manual, _manual_value, _project_id, _progress_mode, _task_complete; -- Check if the project uses manual progress - IF _project_id IS NOT NULL - THEN + IF _project_id IS NOT NULL THEN SELECT COALESCE(use_manual_progress, FALSE), COALESCE(use_weighted_progress, FALSE), COALESCE(use_time_progress, FALSE) @@ -58,49 +65,212 @@ BEGIN INTO _use_manual_progress, _use_weighted_progress, _use_time_progress; END IF; - -- If manual progress is enabled and has a value, use it directly - IF _is_manual IS TRUE AND _manual_value IS NOT NULL - THEN + -- Get all subtasks + SELECT COUNT(*) + FROM tasks + WHERE parent_task_id = _task_id AND archived IS FALSE + INTO _sub_tasks_count; + + -- If task is complete, always return 100% + IF _task_complete IS TRUE THEN RETURN JSON_BUILD_OBJECT( + 'ratio', 100, + 'total_completed', 1, + 'total_tasks', 1, + 'is_manual', FALSE + ); + END IF; + + -- Determine current active mode + DECLARE + _current_mode VARCHAR(20) = CASE + WHEN _use_manual_progress IS TRUE THEN 'manual' + WHEN _use_weighted_progress IS TRUE THEN 'weighted' + WHEN _use_time_progress IS TRUE THEN 'time' + ELSE 'default' + END; + BEGIN + -- Only use manual progress value if it was set in the current active mode + -- and time progress is not enabled + IF _use_time_progress IS FALSE AND + ((_is_manual IS TRUE AND _manual_value IS NOT NULL AND + (_progress_mode IS NULL OR _progress_mode = _current_mode)) OR + (_use_manual_progress IS TRUE AND _manual_value IS NOT NULL AND + (_progress_mode IS NULL OR _progress_mode = 'manual'))) THEN + RETURN JSON_BUILD_OBJECT( 'ratio', _manual_value, 'total_completed', 0, 'total_tasks', 0, 'is_manual', TRUE - ); + ); + END IF; + END; + + -- If there are no subtasks, calculate based on the task itself + IF _sub_tasks_count = 0 THEN + -- Use time-based estimation if enabled + IF _use_time_progress IS TRUE THEN + -- Calculate progress based on logged time vs estimated time + WITH task_time_info AS ( + SELECT + COALESCE(t.total_minutes, 0) as estimated_minutes, + COALESCE(( + SELECT SUM(time_spent) + FROM task_work_log + WHERE task_id = t.id + ), 0) as logged_minutes + FROM tasks t + WHERE t.id = _task_id + ) + SELECT + CASE + WHEN _task_complete IS TRUE THEN 100 + WHEN estimated_minutes > 0 THEN + LEAST((logged_minutes / estimated_minutes) * 100, 100) + ELSE 0 + END + INTO _ratio + FROM task_time_info; + ELSE + -- Traditional calculation for non-time-based tasks + SELECT (CASE WHEN _task_complete IS TRUE THEN 1 ELSE 0 END) + INTO _parent_task_done; + + _ratio = _parent_task_done * 100; + END IF; + ELSE + -- If project uses manual progress, calculate based on subtask manual progress values + IF _use_manual_progress IS TRUE AND _use_time_progress IS FALSE THEN + WITH subtask_progress AS ( + SELECT + t.id, + t.manual_progress, + t.progress_value, + t.progress_mode, + EXISTS( + SELECT 1 + FROM tasks_with_status_view + WHERE tasks_with_status_view.task_id = t.id + AND is_done IS TRUE + ) AS is_complete + FROM tasks t + WHERE t.parent_task_id = _task_id + AND t.archived IS FALSE + ), + subtask_with_values AS ( + SELECT + CASE + WHEN is_complete IS TRUE THEN 100 + WHEN progress_value IS NOT NULL AND (progress_mode = 'manual' OR progress_mode IS NULL) THEN progress_value + ELSE 0 + END AS progress_value + FROM subtask_progress + ) + SELECT COALESCE(AVG(progress_value), 0) + FROM subtask_with_values + INTO _ratio; + -- If project uses weighted progress, calculate based on subtask weights + ELSIF _use_weighted_progress IS TRUE AND _use_time_progress IS FALSE THEN + WITH subtask_progress AS ( + SELECT + t.id, + t.manual_progress, + t.progress_value, + t.progress_mode, + EXISTS( + SELECT 1 + FROM tasks_with_status_view + WHERE tasks_with_status_view.task_id = t.id + AND is_done IS TRUE + ) AS is_complete, + COALESCE(t.weight, 100) AS weight + FROM tasks t + WHERE t.parent_task_id = _task_id + AND t.archived IS FALSE + ), + subtask_with_values AS ( + SELECT + CASE + WHEN is_complete IS TRUE THEN 100 + WHEN progress_value IS NOT NULL AND (progress_mode = 'weighted' OR progress_mode IS NULL) THEN progress_value + ELSE 0 + END AS progress_value, + weight + FROM subtask_progress + ) + SELECT COALESCE( + SUM(progress_value * weight) / NULLIF(SUM(weight), 0), + 0 + ) + FROM subtask_with_values + INTO _ratio; + -- If project uses time-based progress, calculate based on actual logged time + ELSIF _use_time_progress IS TRUE THEN + WITH task_time_info AS ( + SELECT + t.id, + COALESCE(t.total_minutes, 0) as estimated_minutes, + COALESCE(( + SELECT SUM(time_spent) + FROM task_work_log + WHERE task_id = t.id + ), 0) as logged_minutes, + EXISTS( + SELECT 1 + FROM tasks_with_status_view + WHERE tasks_with_status_view.task_id = t.id + AND is_done IS TRUE + ) AS is_complete + FROM tasks t + WHERE t.parent_task_id = _task_id + AND t.archived IS FALSE + ) + SELECT COALESCE( + SUM( + CASE + WHEN is_complete IS TRUE THEN estimated_minutes + ELSE LEAST(logged_minutes, estimated_minutes) + END + ) / NULLIF(SUM(estimated_minutes), 0) * 100, + 0 + ) + FROM task_time_info + INTO _ratio; + ELSE + -- Traditional calculation based on completion status + SELECT (CASE WHEN _task_complete IS TRUE THEN 1 ELSE 0 END) + INTO _parent_task_done; + + SELECT COUNT(*) + FROM tasks_with_status_view + WHERE parent_task_id = _task_id + AND is_done IS TRUE + INTO _sub_tasks_done; + + _total_completed = _parent_task_done + _sub_tasks_done; + _total_tasks = _sub_tasks_count + 1; -- +1 for the parent task + + IF _total_tasks = 0 THEN + _ratio = 0; + ELSE + _ratio = (_total_completed / _total_tasks) * 100; + END IF; + END IF; END IF; - -- Otherwise calculate automatically as before - SELECT (CASE - WHEN EXISTS(SELECT 1 - FROM tasks_with_status_view - WHERE tasks_with_status_view.task_id = _task_id - AND is_done IS TRUE) THEN 1 - ELSE 0 END) - INTO _parent_task_done; - SELECT COUNT(*) FROM tasks WHERE parent_task_id = _task_id AND archived IS FALSE INTO _sub_tasks_count; - - SELECT COUNT(*) - FROM tasks_with_status_view - WHERE parent_task_id = _task_id - AND is_done IS TRUE - INTO _sub_tasks_done; - - _total_completed = _parent_task_done + _sub_tasks_done; - _total_tasks = _sub_tasks_count; -- +1 for the parent task - - IF _total_tasks > 0 - THEN - _ratio = (_total_completed / _total_tasks) * 100; - ELSE - _ratio = _parent_task_done * 100; + -- Ensure ratio is between 0 and 100 + IF _ratio < 0 THEN + _ratio = 0; + ELSIF _ratio > 100 THEN + _ratio = 100; END IF; RETURN JSON_BUILD_OBJECT( - 'ratio', _ratio, - 'total_completed', _total_completed, - 'total_tasks', _total_tasks, - 'is_manual', FALSE - ); + 'ratio', _ratio, + 'total_completed', _total_completed, + 'total_tasks', _total_tasks, + 'is_manual', _is_manual + ); END $$; @@ -615,38 +785,38 @@ BEGIN ) FROM subtask_with_values INTO _ratio; - -- If project uses time-based progress, calculate based on estimated time + -- If project uses time-based progress, calculate based on actual logged time ELSIF _use_time_progress IS TRUE THEN - WITH subtask_progress AS (SELECT t.id, - t.manual_progress, - t.progress_value, - t.progress_mode, - EXISTS(SELECT 1 - FROM tasks_with_status_view - WHERE tasks_with_status_view.task_id = t.id - AND is_done IS TRUE) AS is_complete, - COALESCE(t.total_minutes, 0) AS estimated_minutes - FROM tasks t - WHERE t.parent_task_id = _task_id - AND t.archived IS FALSE), - subtask_with_values AS (SELECT CASE - -- For completed tasks, always use 100% - WHEN is_complete IS TRUE THEN 100 - -- For tasks with progress value set in the correct mode, use it - WHEN progress_value IS NOT NULL AND - (progress_mode = 'time' OR progress_mode IS NULL) - THEN progress_value - -- Default to 0 for incomplete tasks with no progress value or wrong mode - ELSE 0 - END AS progress_value, - estimated_minutes - FROM subtask_progress) + WITH task_time_info AS ( + SELECT + t.id, + COALESCE(t.total_minutes, 0) as estimated_minutes, + COALESCE(( + SELECT SUM(time_spent) + FROM task_work_log + WHERE task_id = t.id + ), 0) as logged_minutes, + EXISTS( + SELECT 1 + FROM tasks_with_status_view + WHERE tasks_with_status_view.task_id = t.id + AND is_done IS TRUE + ) AS is_complete + FROM tasks t + WHERE t.parent_task_id = _task_id + AND t.archived IS FALSE + ) SELECT COALESCE( - SUM(progress_value * estimated_minutes) / NULLIF(SUM(estimated_minutes), 0), - 0 - ) - FROM subtask_with_values + SUM( + CASE + WHEN is_complete IS TRUE THEN estimated_minutes + ELSE LEAST(logged_minutes, estimated_minutes) + END + ) / NULLIF(SUM(estimated_minutes), 0) * 100, + 0 + ) + FROM task_time_info INTO _ratio; ELSE -- Traditional calculation based on completion status diff --git a/worklenz-backend/database/sql/4_functions.sql b/worklenz-backend/database/sql/4_functions.sql index 189f8ac7..9c9cc820 100644 --- a/worklenz-backend/database/sql/4_functions.sql +++ b/worklenz-backend/database/sql/4_functions.sql @@ -3351,15 +3351,15 @@ BEGIN SELECT COALESCE(ARRAY_TO_JSON(ARRAY_AGG(ROW_TO_JSON(rec))), '[]'::JSON) FROM (SELECT team_member_id, project_member_id, - (SELECT name FROM team_member_info_view WHERE team_member_info_view.team_member_id = tm.id), - (SELECT email_notifications_enabled + COALESCE((SELECT name FROM team_member_info_view WHERE team_member_info_view.team_member_id = tm.id), '') as name, + COALESCE((SELECT email_notifications_enabled FROM notification_settings WHERE team_id = tm.team_id - AND notification_settings.user_id = u.id) AS email_notifications_enabled, - u.avatar_url, + AND notification_settings.user_id = u.id), false) AS email_notifications_enabled, + COALESCE(u.avatar_url, '') as avatar_url, u.id AS user_id, - u.email, - u.socket_id AS socket_id, + COALESCE(u.email, '') as email, + COALESCE(u.socket_id, '') as socket_id, tm.team_id AS team_id FROM tasks_assignees INNER JOIN team_members tm ON tm.id = tasks_assignees.team_member_id @@ -4066,14 +4066,14 @@ DECLARE _schedule_id JSON; _task_completed_at TIMESTAMPTZ; BEGIN - SELECT name FROM tasks WHERE id = _task_id INTO _task_name; + SELECT COALESCE(name, '') FROM tasks WHERE id = _task_id INTO _task_name; - SELECT name + SELECT COALESCE(name, '') FROM task_statuses WHERE id = (SELECT status_id FROM tasks WHERE id = _task_id) INTO _previous_status_name; - SELECT name FROM task_statuses WHERE id = _status_id INTO _new_status_name; + SELECT COALESCE(name, '') FROM task_statuses WHERE id = _status_id INTO _new_status_name; IF (_previous_status_name != _new_status_name) THEN @@ -4081,14 +4081,22 @@ BEGIN SELECT get_task_complete_info(_task_id, _status_id) INTO _task_info; - SELECT name FROM users WHERE id = _user_id INTO _updater_name; + SELECT COALESCE(name, '') FROM users WHERE id = _user_id INTO _updater_name; _message = CONCAT(_updater_name, ' transitioned "', _task_name, '" from ', _previous_status_name, ' ⟶ ', _new_status_name); END IF; SELECT completed_at FROM tasks WHERE id = _task_id INTO _task_completed_at; - SELECT schedule_id FROM tasks WHERE id = _task_id INTO _schedule_id; + + -- Handle schedule_id properly for recurring tasks + SELECT CASE + WHEN schedule_id IS NULL THEN 'null'::json + ELSE json_build_object('id', schedule_id) + END + FROM tasks + WHERE id = _task_id + INTO _schedule_id; SELECT COALESCE(ROW_TO_JSON(r), '{}'::JSON) FROM (SELECT is_done, is_doing, is_todo @@ -4097,7 +4105,7 @@ BEGIN INTO _status_category; RETURN JSON_BUILD_OBJECT( - 'message', _message, + 'message', COALESCE(_message, ''), 'project_id', (SELECT project_id FROM tasks WHERE id = _task_id), 'parent_done', (CASE WHEN EXISTS(SELECT 1 @@ -4105,14 +4113,14 @@ BEGIN WHERE tasks_with_status_view.task_id = _task_id AND is_done IS TRUE) THEN 1 ELSE 0 END), - 'color_code', (_task_info ->> 'color_code')::TEXT, - 'color_code_dark', (_task_info ->> 'color_code_dark')::TEXT, - 'total_tasks', (_task_info ->> 'total_tasks')::INT, - 'total_completed', (_task_info ->> 'total_completed')::INT, - 'members', (_task_info ->> 'members')::JSON, + 'color_code', COALESCE((_task_info ->> 'color_code')::TEXT, ''), + 'color_code_dark', COALESCE((_task_info ->> 'color_code_dark')::TEXT, ''), + 'total_tasks', COALESCE((_task_info ->> 'total_tasks')::INT, 0), + 'total_completed', COALESCE((_task_info ->> 'total_completed')::INT, 0), + 'members', COALESCE((_task_info ->> 'members')::JSON, '[]'::JSON), 'completed_at', _task_completed_at, - 'status_category', _status_category, - 'schedule_id', _schedule_id + 'status_category', COALESCE(_status_category, '{}'::JSON), + 'schedule_id', COALESCE(_schedule_id, 'null'::JSON) ); END $$; @@ -6148,3 +6156,219 @@ BEGIN RETURN v_new_id; END; $$; + +CREATE OR REPLACE FUNCTION transfer_team_ownership(_team_id UUID, _new_owner_id UUID) RETURNS json + LANGUAGE plpgsql +AS +$$ +DECLARE + _old_owner_id UUID; + _owner_role_id UUID; + _admin_role_id UUID; + _old_org_id UUID; + _new_org_id UUID; + _has_license BOOLEAN; + _old_owner_role_id UUID; + _new_owner_role_id UUID; + _has_active_coupon BOOLEAN; + _other_teams_count INTEGER; + _new_owner_org_id UUID; + _license_type_id UUID; + _has_valid_license BOOLEAN; +BEGIN + -- Get the current owner's ID and organization + SELECT t.user_id, t.organization_id + INTO _old_owner_id, _old_org_id + FROM teams t + WHERE t.id = _team_id; + + IF _old_owner_id IS NULL THEN + RAISE EXCEPTION 'Team not found'; + END IF; + + -- Get the new owner's organization + SELECT organization_id INTO _new_owner_org_id + FROM organizations + WHERE user_id = _new_owner_id; + + -- Get the old organization + SELECT id INTO _old_org_id + FROM organizations + WHERE id = _old_org_id; + + IF _old_org_id IS NULL THEN + RAISE EXCEPTION 'Organization not found'; + END IF; + + -- Check if new owner has any valid license type + SELECT EXISTS ( + SELECT 1 + FROM ( + -- Check regular subscriptions + SELECT lus.user_id, lus.status, lus.active + FROM licensing_user_subscriptions lus + WHERE lus.user_id = _new_owner_id + AND lus.active = TRUE + AND lus.status IN ('active', 'trialing') + + UNION ALL + + -- Check custom subscriptions + SELECT lcs.user_id, lcs.subscription_status as status, TRUE as active + FROM licensing_custom_subs lcs + WHERE lcs.user_id = _new_owner_id + AND lcs.end_date > CURRENT_DATE + + UNION ALL + + -- Check trial status in organizations + SELECT o.user_id, o.subscription_status as status, TRUE as active + FROM organizations o + WHERE o.user_id = _new_owner_id + AND o.trial_in_progress = TRUE + AND o.trial_expire_date > CURRENT_DATE + ) valid_licenses + ) INTO _has_valid_license; + + IF NOT _has_valid_license THEN + RAISE EXCEPTION 'New owner does not have a valid license (subscription, custom subscription, or trial)'; + END IF; + + -- Check if new owner has any active coupon codes + SELECT EXISTS ( + SELECT 1 + FROM licensing_coupon_codes lcc + WHERE lcc.redeemed_by = _new_owner_id + AND lcc.is_redeemed = TRUE + AND lcc.is_refunded = FALSE + ) INTO _has_active_coupon; + + IF _has_active_coupon THEN + RAISE EXCEPTION 'New owner has active coupon codes that need to be handled before transfer'; + END IF; + + -- Count other teams in the organization for information purposes + SELECT COUNT(*) INTO _other_teams_count + FROM teams + WHERE organization_id = _old_org_id + AND id != _team_id; + + -- If new owner has their own organization, move the team to their organization + IF _new_owner_org_id IS NOT NULL THEN + -- Update the team to use the new owner's organization + UPDATE teams + SET user_id = _new_owner_id, + organization_id = _new_owner_org_id + WHERE id = _team_id; + + -- Create notification about organization change + PERFORM create_notification( + _old_owner_id, + _team_id, + NULL, + NULL, + CONCAT('Team ', (SELECT name FROM teams WHERE id = _team_id), ' has been moved to a different organization') + ); + + PERFORM create_notification( + _new_owner_id, + _team_id, + NULL, + NULL, + CONCAT('Team ', (SELECT name FROM teams WHERE id = _team_id), ' has been moved to your organization') + ); + ELSE + -- If new owner doesn't have an organization, transfer the old organization to them + UPDATE organizations + SET user_id = _new_owner_id + WHERE id = _old_org_id; + + -- Update the team to use the same organization + UPDATE teams + SET user_id = _new_owner_id, + organization_id = _old_org_id + WHERE id = _team_id; + + -- Notify both users about organization ownership transfer + PERFORM create_notification( + _old_owner_id, + NULL, + NULL, + NULL, + CONCAT('You are no longer the owner of organization ', (SELECT organization_name FROM organizations WHERE id = _old_org_id), '') + ); + + PERFORM create_notification( + _new_owner_id, + NULL, + NULL, + NULL, + CONCAT('You are now the owner of organization ', (SELECT organization_name FROM organizations WHERE id = _old_org_id), '') + ); + END IF; + + -- Get the owner and admin role IDs + SELECT id INTO _owner_role_id FROM roles WHERE team_id = _team_id AND owner = TRUE; + SELECT id INTO _admin_role_id FROM roles WHERE team_id = _team_id AND admin_role = TRUE; + + -- Get current role IDs for both users + SELECT role_id INTO _old_owner_role_id + FROM team_members + WHERE team_id = _team_id AND user_id = _old_owner_id; + + SELECT role_id INTO _new_owner_role_id + FROM team_members + WHERE team_id = _team_id AND user_id = _new_owner_id; + + -- Update the old owner's role to admin if they want to stay in the team + IF _old_owner_role_id IS NOT NULL THEN + UPDATE team_members + SET role_id = _admin_role_id + WHERE team_id = _team_id AND user_id = _old_owner_id; + END IF; + + -- Update the new owner's role to owner + IF _new_owner_role_id IS NOT NULL THEN + UPDATE team_members + SET role_id = _owner_role_id + WHERE team_id = _team_id AND user_id = _new_owner_id; + ELSE + -- If new owner is not a team member yet, add them + INSERT INTO team_members (user_id, team_id, role_id) + VALUES (_new_owner_id, _team_id, _owner_role_id); + END IF; + + -- Create notification for both users about team ownership + PERFORM create_notification( + _old_owner_id, + _team_id, + NULL, + NULL, + CONCAT('You are no longer the owner of team ', (SELECT name FROM teams WHERE id = _team_id), '') + ); + + PERFORM create_notification( + _new_owner_id, + _team_id, + NULL, + NULL, + CONCAT('You are now the owner of team ', (SELECT name FROM teams WHERE id = _team_id), '') + ); + + RETURN json_build_object( + 'success', TRUE, + 'old_owner_id', _old_owner_id, + 'new_owner_id', _new_owner_id, + 'team_id', _team_id, + 'old_org_id', _old_org_id, + 'new_org_id', COALESCE(_new_owner_org_id, _old_org_id), + 'old_role_id', _old_owner_role_id, + 'new_role_id', _new_owner_role_id, + 'has_valid_license', _has_valid_license, + 'has_active_coupon', _has_active_coupon, + 'other_teams_count', _other_teams_count, + 'org_ownership_transferred', _new_owner_org_id IS NULL, + 'team_moved_to_new_org', _new_owner_org_id IS NOT NULL + ); +END; +$$; diff --git a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts index be79c4b8..4db8e3d5 100644 --- a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts +++ b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts @@ -408,6 +408,65 @@ export default class ReportingAllocationController extends ReportingControllerBa const { duration, date_range } = req.body; + // Calculate the date range (start and end) + let startDate: moment.Moment; + let endDate: moment.Moment; + if (date_range && date_range.length === 2) { + startDate = moment(date_range[0]); + endDate = moment(date_range[1]); + } else if (duration === DATE_RANGES.ALL_TIME) { + // Fetch the earliest start_date (or created_at if null) from selected projects + const minDateQuery = `SELECT MIN(COALESCE(start_date, created_at)) as min_date FROM projects WHERE id IN (${projectIds})`; + const minDateResult = await db.query(minDateQuery, []); + const minDate = minDateResult.rows[0]?.min_date; + startDate = minDate ? moment(minDate) : moment('2000-01-01'); + endDate = moment(); + } else { + switch (duration) { + case DATE_RANGES.YESTERDAY: + startDate = moment().subtract(1, "day"); + endDate = moment().subtract(1, "day"); + break; + case DATE_RANGES.LAST_WEEK: + startDate = moment().subtract(1, "week").startOf("isoWeek"); + endDate = moment().subtract(1, "week").endOf("isoWeek"); + break; + case DATE_RANGES.LAST_MONTH: + startDate = moment().subtract(1, "month").startOf("month"); + endDate = moment().subtract(1, "month").endOf("month"); + break; + case DATE_RANGES.LAST_QUARTER: + startDate = moment().subtract(3, "months").startOf("quarter"); + endDate = moment().subtract(1, "quarter").endOf("quarter"); + break; + default: + startDate = moment().startOf("day"); + endDate = moment().endOf("day"); + } + } + + // Count only weekdays (Mon-Fri) in the period + let workingDays = 0; + let current = startDate.clone(); + while (current.isSameOrBefore(endDate, 'day')) { + const day = current.isoWeekday(); + if (day >= 1 && day <= 5) workingDays++; + current.add(1, 'day'); + } + + // Get hours_per_day for all selected projects + const projectHoursQuery = `SELECT id, hours_per_day FROM projects WHERE id IN (${projectIds})`; + const projectHoursResult = await db.query(projectHoursQuery, []); + const projectHoursMap: Record = {}; + for (const row of projectHoursResult.rows) { + projectHoursMap[row.id] = row.hours_per_day || 8; + } + // Sum total working hours for all selected projects + let totalWorkingHours = 0; + for (const pid of Object.keys(projectHoursMap)) { + totalWorkingHours += workingDays * projectHoursMap[pid]; + } + const durationClause = this.getDateRangeClause(duration || DATE_RANGES.LAST_WEEK, date_range); const archivedClause = archived ? "" @@ -430,6 +489,12 @@ export default class ReportingAllocationController extends ReportingControllerBa for (const member of result.rows) { member.value = member.logged_time ? parseFloat(moment.duration(member.logged_time, "seconds").asHours().toFixed(2)) : 0; member.color_code = getColor(member.name); + member.total_working_hours = totalWorkingHours; + member.utilization_percent = (totalWorkingHours > 0 && member.logged_time) ? ((parseFloat(member.logged_time) / (totalWorkingHours * 3600)) * 100).toFixed(2) : '0.00'; + member.utilized_hours = member.logged_time ? (parseFloat(member.logged_time) / 3600).toFixed(2) : '0.00'; + // Over/under utilized hours: utilized_hours - total_working_hours + const overUnder = member.utilized_hours && member.total_working_hours ? (parseFloat(member.utilized_hours) - member.total_working_hours) : 0; + member.over_under_utilized_hours = overUnder.toFixed(2); } return res.status(200).send(new ServerResponse(true, result.rows)); diff --git a/worklenz-backend/src/controllers/tasks-controller-base.ts b/worklenz-backend/src/controllers/tasks-controller-base.ts index 1fe89210..d2524bad 100644 --- a/worklenz-backend/src/controllers/tasks-controller-base.ts +++ b/worklenz-backend/src/controllers/tasks-controller-base.ts @@ -1,6 +1,6 @@ import WorklenzControllerBase from "./worklenz-controller-base"; -import {getColor} from "../shared/utils"; -import {PriorityColorCodes, TASK_PRIORITY_COLOR_ALPHA, TASK_STATUS_COLOR_ALPHA} from "../shared/constants"; +import { getColor } from "../shared/utils"; +import { PriorityColorCodes, TASK_PRIORITY_COLOR_ALPHA, TASK_STATUS_COLOR_ALPHA } from "../shared/constants"; import moment from "moment/moment"; export const GroupBy = { @@ -32,23 +32,14 @@ export default class TasksControllerBase extends WorklenzControllerBase { } public static updateTaskViewModel(task: any) { - console.log(`Processing task ${task.id} (${task.name})`); - console.log(` manual_progress: ${task.manual_progress}, progress_value: ${task.progress_value}`); - console.log(` project_use_manual_progress: ${task.project_use_manual_progress}, project_use_weighted_progress: ${task.project_use_weighted_progress}`); - console.log(` has subtasks: ${task.sub_tasks_count > 0}`); - // For parent tasks (with subtasks), always use calculated progress from subtasks if (task.sub_tasks_count > 0) { - // For parent tasks without manual progress, calculate from subtasks (already done via db function) - console.log(` Parent task with subtasks: complete_ratio=${task.complete_ratio}`); - // Ensure progress matches complete_ratio for consistency task.progress = task.complete_ratio || 0; - + // Important: Parent tasks should not have manual progress // If they somehow do, reset it if (task.manual_progress) { - console.log(` WARNING: Parent task ${task.id} had manual_progress set to true, resetting`); task.manual_progress = false; task.progress_value = null; } @@ -58,28 +49,24 @@ export default class TasksControllerBase extends WorklenzControllerBase { // For manually set progress, use that value directly task.progress = parseInt(task.progress_value); task.complete_ratio = parseInt(task.progress_value); - - console.log(` Using manual progress: progress=${task.progress}, complete_ratio=${task.complete_ratio}`); - } + } // For tasks with no subtasks and no manual progress, calculate based on time else { - task.progress = task.total_minutes_spent && task.total_minutes - ? ~~(task.total_minutes_spent / task.total_minutes * 100) + task.progress = task.total_minutes_spent && task.total_minutes + ? ~~(task.total_minutes_spent / task.total_minutes * 100) : 0; - + // Set complete_ratio to match progress task.complete_ratio = task.progress; - - console.log(` Calculated time-based progress: progress=${task.progress}, complete_ratio=${task.complete_ratio}`); } - + // Ensure numeric values task.progress = parseInt(task.progress) || 0; task.complete_ratio = parseInt(task.complete_ratio) || 0; - + task.overdue = task.total_minutes < task.total_minutes_spent; - task.time_spent = {hours: ~~(task.total_minutes_spent / 60), minutes: task.total_minutes_spent % 60}; + task.time_spent = { hours: ~~(task.total_minutes_spent / 60), minutes: task.total_minutes_spent % 60 }; task.comments_count = Number(task.comments_count) ? +task.comments_count : 0; task.attachments_count = Number(task.attachments_count) ? +task.attachments_count : 0; diff --git a/worklenz-backend/src/controllers/tasks-controller-v2.ts b/worklenz-backend/src/controllers/tasks-controller-v2.ts index c3231825..6e01c686 100644 --- a/worklenz-backend/src/controllers/tasks-controller-v2.ts +++ b/worklenz-backend/src/controllers/tasks-controller-v2.ts @@ -97,7 +97,6 @@ export default class TasksControllerV2 extends TasksControllerBase { try { const result = await db.query("SELECT get_task_complete_ratio($1) AS info;", [taskId]); const [data] = result.rows; - console.log("data", data); if (data && data.info && data.info.ratio !== undefined) { data.info.ratio = +((data.info.ratio || 0).toFixed()); return data.info; @@ -833,9 +832,7 @@ export default class TasksControllerV2 extends TasksControllerBase { } public static async refreshProjectTaskProgressValues(projectId: string): Promise { - try { - console.log(`Refreshing progress values for project ${projectId}`); - + try { // Run the recalculate_all_task_progress function only for tasks in this project const query = ` DO $$ @@ -893,10 +890,10 @@ export default class TasksControllerV2 extends TasksControllerBase { END $$; `; - const result = await db.query(query); + await db.query(query); console.log(`Finished refreshing progress values for project ${projectId}`); } catch (error) { - log_error('Error refreshing project task progress values', error); + log_error("Error refreshing project task progress values", error); } } diff --git a/worklenz-backend/src/cron_jobs/index.ts b/worklenz-backend/src/cron_jobs/index.ts index 20bd4f62..108a76f2 100644 --- a/worklenz-backend/src/cron_jobs/index.ts +++ b/worklenz-backend/src/cron_jobs/index.ts @@ -7,5 +7,5 @@ export function startCronJobs() { startNotificationsJob(); startDailyDigestJob(); startProjectDigestJob(); - startRecurringTasksJob(); + if (process.env.ENABLE_RECURRING_JOBS === "true") startRecurringTasksJob(); } diff --git a/worklenz-backend/src/cron_jobs/recurring-tasks.ts b/worklenz-backend/src/cron_jobs/recurring-tasks.ts index 16854c7e..2780edd5 100644 --- a/worklenz-backend/src/cron_jobs/recurring-tasks.ts +++ b/worklenz-backend/src/cron_jobs/recurring-tasks.ts @@ -7,12 +7,90 @@ import TasksController from "../controllers/tasks-controller"; // At 11:00+00 (4.30pm+530) on every day-of-month if it's on every day-of-week from Monday through Friday. // const TIME = "0 11 */1 * 1-5"; -const TIME = "*/2 * * * *"; // runs every 2 minutes - for testing purposes +const TIME = process.env.RECURRING_JOBS_INTERVAL || "0 11 */1 * 1-5"; const TIME_FORMAT = "YYYY-MM-DD"; // const TIME = "0 0 * * *"; // Runs at midnight every day const log = (value: any) => console.log("recurring-task-cron-job:", value); +// Define future limits for different schedule types +// More conservative limits to prevent task list clutter +const FUTURE_LIMITS = { + daily: moment.duration(3, "days"), + weekly: moment.duration(1, "week"), + monthly: moment.duration(1, "month"), + every_x_days: (interval: number) => moment.duration(interval, "days"), + every_x_weeks: (interval: number) => moment.duration(interval, "weeks"), + every_x_months: (interval: number) => moment.duration(interval, "months") +}; + +// Helper function to get the future limit based on schedule type +function getFutureLimit(scheduleType: string, interval?: number): moment.Duration { + switch (scheduleType) { + case "daily": + return FUTURE_LIMITS.daily; + case "weekly": + return FUTURE_LIMITS.weekly; + case "monthly": + return FUTURE_LIMITS.monthly; + case "every_x_days": + return FUTURE_LIMITS.every_x_days(interval || 1); + case "every_x_weeks": + return FUTURE_LIMITS.every_x_weeks(interval || 1); + case "every_x_months": + return FUTURE_LIMITS.every_x_months(interval || 1); + default: + return moment.duration(3, "days"); // Default to 3 days + } +} + +// Helper function to batch create tasks +async function createBatchTasks(template: ITaskTemplate & IRecurringSchedule, endDates: moment.Moment[]) { + const createdTasks = []; + + for (const nextEndDate of endDates) { + const existingTaskQuery = ` + SELECT id FROM tasks + WHERE schedule_id = $1 AND end_date::DATE = $2::DATE; + `; + const existingTaskResult = await db.query(existingTaskQuery, [template.schedule_id, nextEndDate.format(TIME_FORMAT)]); + + if (existingTaskResult.rows.length === 0) { + const createTaskQuery = `SELECT create_quick_task($1::json) as task;`; + const taskData = { + name: template.name, + priority_id: template.priority_id, + project_id: template.project_id, + reporter_id: template.reporter_id, + status_id: template.status_id || null, + end_date: nextEndDate.format(TIME_FORMAT), + schedule_id: template.schedule_id + }; + const createTaskResult = await db.query(createTaskQuery, [JSON.stringify(taskData)]); + const createdTask = createTaskResult.rows[0].task; + + if (createdTask) { + createdTasks.push(createdTask); + + for (const assignee of template.assignees) { + await TasksController.createTaskBulkAssignees(assignee.team_member_id, template.project_id, createdTask.id, assignee.assigned_by); + } + + for (const label of template.labels) { + const q = `SELECT add_or_remove_task_label($1, $2) AS labels;`; + await db.query(q, [createdTask.id, label.label_id]); + } + + console.log(`Created task for template ${template.name} with end date ${nextEndDate.format(TIME_FORMAT)}`); + } + } else { + console.log(`Skipped creating task for template ${template.name} with end date ${nextEndDate.format(TIME_FORMAT)} - task already exists`); + } + } + + return createdTasks; +} + async function onRecurringTaskJobTick() { try { log("(cron) Recurring tasks job started."); @@ -33,65 +111,44 @@ async function onRecurringTaskJobTick() { ? moment(template.last_task_end_date) : moment(template.created_at); - const futureLimit = moment(template.last_checked_at || template.created_at).add(1, "week"); + // Calculate future limit based on schedule type + const futureLimit = moment(template.last_checked_at || template.created_at) + .add(getFutureLimit( + template.schedule_type, + template.interval_days || template.interval_weeks || template.interval_months || 1 + )); let nextEndDate = calculateNextEndDate(template, lastTaskEndDate); + const endDatesToCreate: moment.Moment[] = []; - // Find the next future occurrence - while (nextEndDate.isSameOrBefore(now)) { + // Find all future occurrences within the limit + while (nextEndDate.isSameOrBefore(futureLimit)) { + if (nextEndDate.isAfter(now)) { + endDatesToCreate.push(moment(nextEndDate)); + } nextEndDate = calculateNextEndDate(template, nextEndDate); } - // Only create a task if it's within the future limit - if (nextEndDate.isSameOrBefore(futureLimit)) { - const existingTaskQuery = ` - SELECT id FROM tasks - WHERE schedule_id = $1 AND end_date::DATE = $2::DATE; + // Batch create tasks for all future dates + if (endDatesToCreate.length > 0) { + const createdTasks = await createBatchTasks(template, endDatesToCreate); + createdTaskCount += createdTasks.length; + + // Update the last_checked_at in the schedule + const updateScheduleQuery = ` + UPDATE task_recurring_schedules + SET last_checked_at = $1::DATE, + last_created_task_end_date = $2 + WHERE id = $3; `; - const existingTaskResult = await db.query(existingTaskQuery, [template.schedule_id, nextEndDate.format(TIME_FORMAT)]); - - if (existingTaskResult.rows.length === 0) { - const createTaskQuery = `SELECT create_quick_task($1::json) as task;`; - const taskData = { - name: template.name, - priority_id: template.priority_id, - project_id: template.project_id, - reporter_id: template.reporter_id, - status_id: template.status_id || null, - end_date: nextEndDate.format(TIME_FORMAT), - schedule_id: template.schedule_id - }; - const createTaskResult = await db.query(createTaskQuery, [JSON.stringify(taskData)]); - const createdTask = createTaskResult.rows[0].task; - - if (createdTask) { - createdTaskCount++; - - for (const assignee of template.assignees) { - await TasksController.createTaskBulkAssignees(assignee.team_member_id, template.project_id, createdTask.id, assignee.assigned_by); - } - - for (const label of template.labels) { - const q = `SELECT add_or_remove_task_label($1, $2) AS labels;`; - await db.query(q, [createdTask.id, label.label_id]); - } - - console.log(`Created task for template ${template.name} with end date ${nextEndDate.format(TIME_FORMAT)}`); - } - } else { - console.log(`Skipped creating task for template ${template.name} with end date ${nextEndDate.format(TIME_FORMAT)} - task already exists`); - } + await db.query(updateScheduleQuery, [ + moment().format(TIME_FORMAT), + endDatesToCreate[endDatesToCreate.length - 1].format(TIME_FORMAT), + template.schedule_id + ]); } else { - console.log(`No task created for template ${template.name} - next occurrence is beyond the future limit`); + console.log(`No tasks created for template ${template.name} - next occurrence is beyond the future limit`); } - - // Update the last_checked_at in the schedule - const updateScheduleQuery = ` - UPDATE task_recurring_schedules - SET last_checked_at = $1::DATE, last_created_task_end_date = $2 - WHERE id = $3; - `; - await db.query(updateScheduleQuery, [moment(template.last_checked_at || template.created_at).add(1, "day").format(TIME_FORMAT), nextEndDate.format(TIME_FORMAT), template.schedule_id]); } log(`(cron) Recurring tasks job ended with ${createdTaskCount} new tasks created.`); diff --git a/worklenz-backend/worklenz-email-templates/password-changed-notification.html b/worklenz-backend/worklenz-email-templates/password-changed-notification.html index f734d8a8..2c8e2d3a 100644 --- a/worklenz-backend/worklenz-email-templates/password-changed-notification.html +++ b/worklenz-backend/worklenz-email-templates/password-changed-notification.html @@ -2,31 +2,30 @@ - + Password Changed | Worklenz + - - - - + + + + + + + + + diff --git a/worklenz-backend/worklenz-email-templates/reset-password.html b/worklenz-backend/worklenz-email-templates/reset-password.html index d6f7e4d7..9c5f2c24 100644 --- a/worklenz-backend/worklenz-email-templates/reset-password.html +++ b/worklenz-backend/worklenz-email-templates/reset-password.html @@ -2,31 +2,30 @@ - + Reset Your Password | Worklenz + - - - - - - - - + + + + diff --git a/worklenz-backend/worklenz-email-templates/team-invitation.html b/worklenz-backend/worklenz-email-templates/team-invitation.html index 921e845d..f0d17e33 100644 --- a/worklenz-backend/worklenz-email-templates/team-invitation.html +++ b/worklenz-backend/worklenz-email-templates/team-invitation.html @@ -2,31 +2,30 @@ - + Join Your Team on Worklenz + - - - - - - - - + + + + diff --git a/worklenz-backend/worklenz-email-templates/unregistered-team-invitation-notification.html b/worklenz-backend/worklenz-email-templates/unregistered-team-invitation-notification.html index a231f9ad..2db5cfc2 100644 --- a/worklenz-backend/worklenz-email-templates/unregistered-team-invitation-notification.html +++ b/worklenz-backend/worklenz-email-templates/unregistered-team-invitation-notification.html @@ -2,31 +2,30 @@ - + Join Your Team on Worklenz + - - - - - + + + + + + + + + + + + + + + + diff --git a/worklenz-backend/worklenz-email-templates/welcome.html b/worklenz-backend/worklenz-email-templates/welcome.html index bc258a6d..7bb62821 100644 --- a/worklenz-backend/worklenz-email-templates/welcome.html +++ b/worklenz-backend/worklenz-email-templates/welcome.html @@ -2,31 +2,30 @@ - + Welcome to Worklenz + - - - - - + + + + + + + + + + + + + + + + diff --git a/worklenz-frontend/index.html b/worklenz-frontend/index.html index 57a2a1b0..ba93ca2c 100644 --- a/worklenz-frontend/index.html +++ b/worklenz-frontend/index.html @@ -48,6 +48,17 @@
+ \ No newline at end of file diff --git a/worklenz-frontend/public/locales/en/task-drawer/task-drawer-recurring-config.json b/worklenz-frontend/public/locales/en/task-drawer/task-drawer-recurring-config.json index f1d0301d..10a9db71 100644 --- a/worklenz-frontend/public/locales/en/task-drawer/task-drawer-recurring-config.json +++ b/worklenz-frontend/public/locales/en/task-drawer/task-drawer-recurring-config.json @@ -2,6 +2,7 @@ "recurring": "Recurring", "recurringTaskConfiguration": "Recurring task configuration", "repeats": "Repeats", + "daily": "Daily", "weekly": "Weekly", "everyXDays": "Every X Days", "everyXWeeks": "Every X Weeks", diff --git a/worklenz-frontend/public/locales/es/task-drawer/task-drawer-recurring-config.json b/worklenz-frontend/public/locales/es/task-drawer/task-drawer-recurring-config.json index d9c711a5..ecc48c5f 100644 --- a/worklenz-frontend/public/locales/es/task-drawer/task-drawer-recurring-config.json +++ b/worklenz-frontend/public/locales/es/task-drawer/task-drawer-recurring-config.json @@ -2,6 +2,7 @@ "recurring": "Recurrente", "recurringTaskConfiguration": "Configuración de tarea recurrente", "repeats": "Repeticiones", + "daily": "Diario", "weekly": "Semanal", "everyXDays": "Cada X días", "everyXWeeks": "Cada X semanas", diff --git a/worklenz-frontend/public/locales/pt/task-drawer/task-drawer-recurring-config.json b/worklenz-frontend/public/locales/pt/task-drawer/task-drawer-recurring-config.json index 5619884b..d693f277 100644 --- a/worklenz-frontend/public/locales/pt/task-drawer/task-drawer-recurring-config.json +++ b/worklenz-frontend/public/locales/pt/task-drawer/task-drawer-recurring-config.json @@ -2,6 +2,7 @@ "recurring": "Recorrente", "recurringTaskConfiguration": "Configuração de tarefa recorrente", "repeats": "Repete", + "daily": "Diário", "weekly": "Semanal", "everyXDays": "A cada X dias", "everyXWeeks": "A cada X semanas", diff --git a/worklenz-frontend/src/components/EmptyListPlaceholder.tsx b/worklenz-frontend/src/components/EmptyListPlaceholder.tsx index 372cd845..dfe1aa76 100644 --- a/worklenz-frontend/src/components/EmptyListPlaceholder.tsx +++ b/worklenz-frontend/src/components/EmptyListPlaceholder.tsx @@ -8,7 +8,7 @@ type EmptyListPlaceholderProps = { }; const EmptyListPlaceholder = ({ - imageSrc = '/src/assets/images/empty-box.webp', + imageSrc = 'https://s3.us-west-2.amazonaws.com/worklenz.com/assets/empty-box.webp', imageHeight = 60, text, }: EmptyListPlaceholderProps) => { diff --git a/worklenz-frontend/src/components/HubSpot.tsx b/worklenz-frontend/src/components/HubSpot.tsx new file mode 100644 index 00000000..072ca433 --- /dev/null +++ b/worklenz-frontend/src/components/HubSpot.tsx @@ -0,0 +1,24 @@ +import { useEffect } from 'react'; + +const HubSpot = () => { + useEffect(() => { + const script = document.createElement('script'); + script.type = 'text/javascript'; + script.id = 'hs-script-loader'; + script.async = true; + script.defer = true; + script.src = '//js.hs-scripts.com/22348300.js'; + document.body.appendChild(script); + + return () => { + const existingScript = document.getElementById('hs-script-loader'); + if (existingScript) { + existingScript.remove(); + } + }; + }, []); + + return null; +}; + +export default HubSpot; \ No newline at end of file diff --git a/worklenz-frontend/src/components/task-drawer/shared/info-tab/details/task-drawer-recurring-config/task-drawer-recurring-config.tsx b/worklenz-frontend/src/components/task-drawer/shared/info-tab/details/task-drawer-recurring-config/task-drawer-recurring-config.tsx index 608fc321..1ff8b315 100644 --- a/worklenz-frontend/src/components/task-drawer/shared/info-tab/details/task-drawer-recurring-config/task-drawer-recurring-config.tsx +++ b/worklenz-frontend/src/components/task-drawer/shared/info-tab/details/task-drawer-recurring-config/task-drawer-recurring-config.tsx @@ -24,44 +24,46 @@ import { taskRecurringApiService } from '@/api/tasks/task-recurring.api.service' import logger from '@/utils/errorLogger'; import { setTaskRecurringSchedule } from '@/features/task-drawer/task-drawer.slice'; -const repeatOptions: IRepeatOption[] = [ - { label: 'Daily', value: ITaskRecurring.Daily }, - { label: 'Weekly', value: ITaskRecurring.Weekly }, - { label: 'Every X Days', value: ITaskRecurring.EveryXDays }, - { label: 'Every X Weeks', value: ITaskRecurring.EveryXWeeks }, - { label: 'Every X Months', value: ITaskRecurring.EveryXMonths }, - { label: 'Monthly', value: ITaskRecurring.Monthly }, -]; - -const daysOfWeek = [ - { label: 'Sunday', value: 0, checked: false }, - { label: 'Monday', value: 1, checked: false }, - { label: 'Tuesday', value: 2, checked: false }, - { label: 'Wednesday', value: 3, checked: false }, - { label: 'Thursday', value: 4, checked: false }, - { label: 'Friday', value: 5, checked: false }, - { label: 'Saturday', value: 6, checked: false } -]; - const monthlyDateOptions = Array.from({ length: 28 }, (_, i) => i + 1); -const weekOptions = [ - { label: 'First', value: 1 }, - { label: 'Second', value: 2 }, - { label: 'Third', value: 3 }, - { label: 'Fourth', value: 4 }, - { label: 'Last', value: 5 } -]; -const dayOptions = daysOfWeek.map(d => ({ label: d.label, value: d.value })); const TaskDrawerRecurringConfig = ({ task }: { task: ITaskViewModel }) => { const { socket, connected } = useSocket(); const dispatch = useAppDispatch(); const { t } = useTranslation('task-drawer/task-drawer-recurring-config'); + const repeatOptions: IRepeatOption[] = [ + { label: t('daily'), value: ITaskRecurring.Daily }, + { label: t('weekly'), value: ITaskRecurring.Weekly }, + { label: t('everyXDays'), value: ITaskRecurring.EveryXDays }, + { label: t('everyXWeeks'), value: ITaskRecurring.EveryXWeeks }, + { label: t('everyXMonths'), value: ITaskRecurring.EveryXMonths }, + { label: t('monthly'), value: ITaskRecurring.Monthly }, + ]; + + const daysOfWeek = [ + { label: t('sun'), value: 0, checked: false }, + { label: t('mon'), value: 1, checked: false }, + { label: t('tue'), value: 2, checked: false }, + { label: t('wed'), value: 3, checked: false }, + { label: t('thu'), value: 4, checked: false }, + { label: t('fri'), value: 5, checked: false }, + { label: t('sat'), value: 6, checked: false } + ]; + + const weekOptions = [ + { label: t('first'), value: 1 }, + { label: t('second'), value: 2 }, + { label: t('third'), value: 3 }, + { label: t('fourth'), value: 4 }, + { label: t('last'), value: 5 } + ]; + + const dayOptions = daysOfWeek.map(d => ({ label: d.label, value: d.value })); + const [recurring, setRecurring] = useState(false); const [showConfig, setShowConfig] = useState(false); const [repeatOption, setRepeatOption] = useState({}); - const [selectedDays, setSelectedDays] = useState([]); + const [selectedDays, setSelectedDays] = useState([]); const [monthlyOption, setMonthlyOption] = useState('date'); const [selectedMonthlyDate, setSelectedMonthlyDate] = useState(1); const [selectedMonthlyWeek, setSelectedMonthlyWeek] = useState(weekOptions[0].value); @@ -106,8 +108,8 @@ const TaskDrawerRecurringConfig = ({ task }: { task: ITaskViewModel }) => { [repeatOption] ); - const handleDayCheckboxChange = (checkedValues: string[]) => { - setSelectedDays(checkedValues as unknown as string[]); + const handleDayCheckboxChange = (checkedValues: number[]) => { + setSelectedDays(checkedValues); }; const getSelectedDays = () => { @@ -165,7 +167,9 @@ const TaskDrawerRecurringConfig = ({ task }: { task: ITaskViewModel }) => { const res = await taskRecurringApiService.updateTaskRecurringData(task.schedule_id, body); if (res.done) { + setRecurring(true); setShowConfig(false); + configVisibleChange(false); } } catch (e) { logger.error("handleSave", e); @@ -220,9 +224,9 @@ const TaskDrawerRecurringConfig = ({ task }: { task: ITaskViewModel }) => { if (!task) return; if (task) setRecurring(!!task.schedule_id); - if (recurring) void getScheduleData(); + if (task.schedule_id) void getScheduleData(); socket?.on(SocketEvents.TASK_RECURRING_CHANGE.toString(), handleResponse); - }, [task]); + }, [task?.schedule_id]); return (
@@ -232,11 +236,11 @@ const TaskDrawerRecurringConfig = ({ task }: { task: ITaskViewModel }) => {   {recurring && (
- + { )} {monthlyOption === 'day' && ( <> - + { )} {repeatOption.value === ITaskRecurring.EveryXDays && ( - + { )} {repeatOption.value === ITaskRecurring.EveryXWeeks && ( - + { )} {repeatOption.value === ITaskRecurring.EveryXMonths && ( - + { loading={updatingData} onClick={handleSave} > - Save Changes + {t('saveChanges')} diff --git a/worklenz-frontend/src/components/task-drawer/task-drawer-header/task-drawer-header.tsx b/worklenz-frontend/src/components/task-drawer/task-drawer-header/task-drawer-header.tsx index 6a20f0b9..0bc322f3 100644 --- a/worklenz-frontend/src/components/task-drawer/task-drawer-header/task-drawer-header.tsx +++ b/worklenz-frontend/src/components/task-drawer/task-drawer-header/task-drawer-header.tsx @@ -27,6 +27,7 @@ const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => { const { socket, connected } = useSocket(); const { clearTaskFromUrl } = useTaskDrawerUrlSync(); const isDeleting = useRef(false); + const [isEditing, setIsEditing] = useState(false); const { taskFormViewModel, selectedTaskId } = useAppSelector(state => state.taskDrawerReducer); const [taskName, setTaskName] = useState(taskFormViewModel?.task?.name ?? ''); @@ -88,6 +89,7 @@ const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => { }; const handleInputBlur = () => { + setIsEditing(false); if ( !selectedTaskId || !connected || @@ -113,21 +115,39 @@ const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => { return ( - onTaskNameChange(e)} - onBlur={handleInputBlur} - placeholder={t('taskHeader.taskNamePlaceholder')} - className="task-name-input" - style={{ - width: '100%', - border: 'none', - }} - showCount={false} - maxLength={250} - /> + {isEditing ? ( + onTaskNameChange(e)} + onBlur={handleInputBlur} + placeholder={t('taskHeader.taskNamePlaceholder')} + className="task-name-input" + style={{ + width: '100%', + border: 'none', + }} + showCount={true} + maxLength={250} + autoFocus + /> + ) : ( +

setIsEditing(true)} + style={{ + margin: 0, + padding: '4px 11px', + fontSize: '16px', + cursor: 'pointer', + wordWrap: 'break-word', + overflowWrap: 'break-word', + width: '100%' + }} + > + {taskName || t('taskHeader.taskNamePlaceholder')} +

+ )}
{ - const { socket, connected } = useSocket(); + const { socket } = useSocket(); const dispatch = useAppDispatch(); const themeMode = useAppSelector(state => state.themeReducer.mode); const { tab } = useTabSearchParam(); diff --git a/worklenz-frontend/src/index.css b/worklenz-frontend/src/index.css index bb0a0781..3c1af53d 100644 --- a/worklenz-frontend/src/index.css +++ b/worklenz-frontend/src/index.css @@ -58,9 +58,9 @@ html.light body { margin: 0; padding: 0; box-sizing: border-box; - font-family: -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, - "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", - "Noto Color Emoji" !important; + font-family: + -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, "Noto Sans", + sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji" !important; } /* helper classes */ @@ -145,3 +145,4 @@ Not supports in Firefox and IE */ tr:hover .action-buttons { opacity: 1; } + diff --git a/worklenz-frontend/src/layouts/MainLayout.tsx b/worklenz-frontend/src/layouts/MainLayout.tsx index bbfd302b..83a4f4c4 100644 --- a/worklenz-frontend/src/layouts/MainLayout.tsx +++ b/worklenz-frontend/src/layouts/MainLayout.tsx @@ -7,7 +7,7 @@ import { colors } from '../styles/colors'; import { verifyAuthentication } from '@/features/auth/authSlice'; import { useEffect } from 'react'; import { useAppDispatch } from '@/hooks/useAppDispatch'; -import TawkTo from '@/components/TawkTo'; +import HubSpot from '@/components/HubSpot'; const MainLayout = () => { const themeMode = useAppSelector(state => state.themeReducer.mode); @@ -68,9 +68,6 @@ const MainLayout = () => { - {import.meta.env.VITE_APP_ENV === 'production' && ( - - )} ); diff --git a/worklenz-frontend/src/lib/settings/settings-constants.ts b/worklenz-frontend/src/lib/settings/settings-constants.ts index 9855b008..7f9beb2a 100644 --- a/worklenz-frontend/src/lib/settings/settings-constants.ts +++ b/worklenz-frontend/src/lib/settings/settings-constants.ts @@ -108,14 +108,14 @@ export const settingsItems: SettingMenuItems[] = [ element: React.createElement(CategoriesSettings), adminOnly: true, }, - // { - // key: 'project-templates', - // name: 'project-templates', - // endpoint: 'project-templates', - // icon: React.createElement(FileZipOutlined), - // element: React.createElement(ProjectTemplatesSettings), - // adminOnly: true, - // }, + { + key: 'project-templates', + name: 'project-templates', + endpoint: 'project-templates', + icon: React.createElement(FileZipOutlined), + element: React.createElement(ProjectTemplatesSettings), + adminOnly: true, + }, { key: 'task-templates', name: 'task-templates', diff --git a/worklenz-frontend/src/pages/home/recent-and-favourite-project-list/recent-and-favourite-project-list.tsx b/worklenz-frontend/src/pages/home/recent-and-favourite-project-list/recent-and-favourite-project-list.tsx index 27822e12..2102da02 100644 --- a/worklenz-frontend/src/pages/home/recent-and-favourite-project-list/recent-and-favourite-project-list.tsx +++ b/worklenz-frontend/src/pages/home/recent-and-favourite-project-list/recent-and-favourite-project-list.tsx @@ -132,7 +132,7 @@ const RecentAndFavouriteProjectList = () => {
{projectsData?.body?.length === 0 ? ( { ) : data?.body.total === 0 ? ( ) : ( diff --git a/worklenz-frontend/src/pages/home/todo-list/todo-list.tsx b/worklenz-frontend/src/pages/home/todo-list/todo-list.tsx index a27d2ac0..f8715808 100644 --- a/worklenz-frontend/src/pages/home/todo-list/todo-list.tsx +++ b/worklenz-frontend/src/pages/home/todo-list/todo-list.tsx @@ -147,7 +147,7 @@ const TodoList = () => {
{data?.body.length === 0 ? ( ) : ( diff --git a/worklenz-frontend/src/pages/projects/projectView/members/project-view-members.tsx b/worklenz-frontend/src/pages/projects/projectView/members/project-view-members.tsx index 8b1b862f..2d669f73 100644 --- a/worklenz-frontend/src/pages/projects/projectView/members/project-view-members.tsx +++ b/worklenz-frontend/src/pages/projects/projectView/members/project-view-members.tsx @@ -263,7 +263,7 @@ const ProjectViewMembers = () => { > {members?.total === 0 ? ( diff --git a/worklenz-frontend/src/pages/reporting/time-reports/members-time-sheet/members-time-sheet.tsx b/worklenz-frontend/src/pages/reporting/time-reports/members-time-sheet/members-time-sheet.tsx index f4c1bf89..7283a40a 100644 --- a/worklenz-frontend/src/pages/reporting/time-reports/members-time-sheet/members-time-sheet.tsx +++ b/worklenz-frontend/src/pages/reporting/time-reports/members-time-sheet/members-time-sheet.tsx @@ -81,6 +81,22 @@ const MembersTimeSheet = forwardRef((_, ref) => { display: false, position: 'top' as const, }, + tooltip: { + callbacks: { + label: function(context: any) { + const idx = context.dataIndex; + const member = jsonData[idx]; + const hours = member?.utilized_hours || '0.00'; + const percent = member?.utilization_percent || '0.00'; + const overUnder = member?.over_under_utilized_hours || '0.00'; + return [ + `${context.dataset.label}: ${hours} h`, + `Utilization: ${percent}%`, + `Over/Under Utilized: ${overUnder} h` + ]; + } + } + } }, backgroundColor: 'black', indexAxis: 'y' as const, diff --git a/worklenz-frontend/src/pages/settings/project-templates/project-templates-settings.tsx b/worklenz-frontend/src/pages/settings/project-templates/project-templates-settings.tsx index 714947fc..7da55d59 100644 --- a/worklenz-frontend/src/pages/settings/project-templates/project-templates-settings.tsx +++ b/worklenz-frontend/src/pages/settings/project-templates/project-templates-settings.tsx @@ -51,7 +51,7 @@ const ProjectTemplatesSettings = () => { style={{ display: 'flex', gap: '10px', justifyContent: 'right' }} className="button-visibilty" > - + {/* - + */}