Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

DRY out controller

Klaus Zanders776d354161d6
diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rb
index 1ceed938efd..c6f5e00ac4b 100644
--- a/modules/costs/app/controllers/my/time_tracking_controller.rb
+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb
@@ -51,9 +51,7 @@ module My
helper_method :current_day, :today?, :this_week?, :this_month?, :time_entries_json
def day
- @time_entries = TimeEntry
- .includes(:project, :activity, :work_package)
- .where(user: User.current, spent_on: current_day)
+ load_time_entries(current_day)
# TODO: At some point the filters will reduce the list, so we need to load them seperately
@project_filters = @time_entries.map(&:project).uniq
@@ -61,9 +59,7 @@ module My
end
def week
- @time_entries = TimeEntry
- .includes(:project, :activity, :work_package)
- .where(user: User.current, spent_on: current_day.all_week)
+ load_time_entries(current_day.all_week)
# TODO: At some point the filters will reduce the list, so we need to load them seperately
@project_filters = @time_entries.map(&:project).uniq
@@ -71,9 +67,7 @@ module My
end
def month
- @time_entries = TimeEntry
- .includes(:project, :activity, :work_package)
- .where(user: User.current, spent_on: current_day.all_month)
+ load_time_entries(current_day.all_month)
# TODO: At some point the filters will reduce the list, so we need to load them seperately
@project_filters = @time_entries.map(&:project).uniq
@@ -127,5 +121,11 @@ module My
when :month then Time.zone.today.beginning_of_month
end
end
+
+ def load_time_entries(time_scope)
+ @time_entries = TimeEntry
+ .includes(:project, :activity, { work_package: :status })
+ .where(user: User.current, spent_on: time_scope)
+ end
end
end