From 76926ff780b32aec1ca1d7f8dbd0322123894734 Mon Sep 17 00:00:00 2001 From: Kaio Magalhaes Date: Thu, 14 Mar 2024 14:16:41 -0300 Subject: [PATCH] make time entries available per sow --- app/controllers/analytics/time_entries_controller.rb | 7 ++++++- app/controllers/statement_of_works_controller.rb | 4 ++-- app/utils/analytics/time_entries_analytics.rb | 12 +++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/analytics/time_entries_controller.rb b/app/controllers/analytics/time_entries_controller.rb index fefeee7..b5199cc 100644 --- a/app/controllers/analytics/time_entries_controller.rb +++ b/app/controllers/analytics/time_entries_controller.rb @@ -3,9 +3,10 @@ module Analytics class TimeEntriesController < ApplicationController before_action :set_project, only: %i[index] + before_action :set_statement_of_work, only: %i[index] def index - @time_entries = Analytics::TimeEntriesAnalytics.new(@project, params[:start_date], + @time_entries = Analytics::TimeEntriesAnalytics.new(@project, @statement_of_work, params[:start_date], params[:end_date]).data render json: @time_entries @@ -16,5 +17,9 @@ def index def set_project @project = Project.where(id: params[:project_id]).first end + + def set_statement_of_work + @statement_of_work = StatementOfWork.where(id: params[:statement_of_work_id]).first + end end end diff --git a/app/controllers/statement_of_works_controller.rb b/app/controllers/statement_of_works_controller.rb index a970b58..1bc65f0 100644 --- a/app/controllers/statement_of_works_controller.rb +++ b/app/controllers/statement_of_works_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StatementOfWorksController < ApplicationController - before_action :set_project + before_action :set_project, only: %i[index create] before_action :set_statement_of_work, only: %i[show update destroy] def index @@ -51,7 +51,7 @@ def set_project end def set_statement_of_work - @statement_of_work = @project.statement_of_works.find(params[:id]) + @statement_of_work = StatementOfWork.find(params[:id]) end def statement_of_work_params diff --git a/app/utils/analytics/time_entries_analytics.rb b/app/utils/analytics/time_entries_analytics.rb index c8e8ff6..aacc8d6 100644 --- a/app/utils/analytics/time_entries_analytics.rb +++ b/app/utils/analytics/time_entries_analytics.rb @@ -2,8 +2,9 @@ module Analytics class TimeEntriesAnalytics - def initialize(project, start_date, end_date) + def initialize(project, statement_of_work, start_date, end_date) @project = project + @statement_of_work = statement_of_work @start_date = start_date.to_datetime.beginning_of_day @end_date = end_date.to_datetime.end_of_day @worked_hours_cache = {} # Cache for memoization @@ -83,12 +84,13 @@ def requirements @requirements = if @project Requirement.where(id: @project.statement_of_works.map(&:requirements) - .flatten.map(&:id)).active_in_period( - @start_date, @end_date - ) + .flatten.map(&:id)) + elsif @statement_of_work + Requirement.where(id: @statement_of_work.requirements.map(&:id)) else - Requirement.all.active_in_period(@start_date, @end_date) + Requirement.all end + @requirements.active_in_period(@start_date, @end_date) end def clean_worked_hours(assignment)