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

add more checking for the date

Klaus Zandersd0029deb2039
diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rb
index 9ceaefbd6b3..e81b777133c 100644
--- a/modules/costs/app/controllers/my/time_tracking_controller.rb
+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb
@@ -35,8 +35,12 @@ module My
no_authorization_required!(:day, :week, :month)
current_menu_item do |ctrl|
- if ctrl.params[:action] == "day" && ctrl.current_day == Time.zone.today
+ if ctrl.params[:action] == "day" && ctrl.today?
:my_time_tracking_today
+ elsif ctrl.params[:action] == "week" && ctrl.this_week?
+ :my_time_tracking_this_week
+ elsif ctrl.params[:action] == "month" && ctrl.this_month?
+ :my_time_tracking_this_month
else
:my_time_tracking
end
@@ -44,6 +48,8 @@ module My
layout "global"
+ helper_method :current_day, :today?, :this_week?, :this_month?
+
def day; end
def week; end
@@ -54,16 +60,40 @@ module My
"my time"
end
+ def today?
+ current_day == Time.zone.today
+ end
+
+ def this_week?
+ current_day == Time.zone.today.beginning_of_week
+ end
+
+ def this_month?
+ current_day == Time.zone.today.beginning_of_month
+ end
+
+ private
+
def current_day
- @current_day ||= if params[:date].present?
- begin
- Date.parse(params[:date])
- rescue StandardError
- Time.zone.today
- end
- else
- Time.zone.today
- end
+ return @current_day if defined?(@current_day)
+
+ parsed_date = if params[:date].present?
+ begin
+ Date.iso8601(params[:date])
+ rescue StandardError
+ nil
+ end
+ end
+
+ @current_day = parsed_date || current_date
+ end
+
+ def current_date
+ case params[:action].to_sym
+ when :day then Time.zone.today
+ when :week then Time.zone.today.beginning_of_week
+ when :month then Time.zone.today.beginning_of_month
+ end
end
end
end
diff --git a/modules/costs/app/views/my/time_tracking/day.html.erb b/modules/costs/app/views/my/time_tracking/day.html.erb
index 4f04629f9b9..7f32dd9c59d 100644
--- a/modules/costs/app/views/my/time_tracking/day.html.erb
+++ b/modules/costs/app/views/my/time_tracking/day.html.erb
@@ -1,6 +1,11 @@
<%=
render Primer::OpenProject::PageHeader.new do |header|
header.with_title { "my time: day view" }
- header.with_breadcrumbs(["my time"])
+ header.with_breadcrumbs(
+ [
+ { title: "label_my_time_tracking", href: my_time_tracking_week_path },
+ "day view"
+ ]
+ )
end
%>
diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.yml
index dd77b2529e8..f1750245023 100644
--- a/modules/costs/config/locales/en.yml
+++ b/modules/costs/config/locales/en.yml
@@ -164,6 +164,7 @@ en:
label_cost: "Cost"
label_costs: "Costs"
label_mandatory_fields: "Mandatory fields"
+ label_my_time_tracking: "My time tracking"
placeholder_activity_select_work_package_first: Work package selection is required first