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

For the month-list-view, group by week and not date

Klaus Zanders1a9e8ad81b71
diff --git a/modules/costs/app/components/my/time_tracking/daily_entries_table.rb b/modules/costs/app/components/my/time_tracking/daily_entries_table.rb
index 8c4f9d4b1b0..8c6f9d80c56 100644
--- a/modules/costs/app/components/my/time_tracking/daily_entries_table.rb
+++ b/modules/costs/app/components/my/time_tracking/daily_entries_table.rb
@@ -31,7 +31,7 @@
module My
module TimeTracking
class DailyEntriesTable < OpPrimer::BorderBoxTableComponent
- columns :time, :hours, :subject, :project, :activity, :comments
+ columns :spent_on, :time, :hours, :subject, :project, :activity, :comments
main_column :time, :subject, :project
def row_class
@@ -60,6 +60,7 @@ module My
def headers
[
+ options[:mode] == :month ? [:spent_on, { caption: TimeEntry.human_attribute_name(:spent_on) }] : nil,
TimeEntry.can_track_start_and_end_time? ? [:time, { caption: TimeEntry.human_attribute_name(:time) }] : nil,
[:hours, { caption: TimeEntry.human_attribute_name(:hours) }],
[:subject, { caption: TimeEntry.human_attribute_name(:subject) }],
@@ -72,6 +73,8 @@ module My
def skip_column?(column)
if column == :time
!TimeEntry.can_track_start_and_end_time?
+ elsif column == :spent_on
+ options[:mode] != :month
else
false
end
diff --git a/modules/costs/app/components/my/time_tracking/list_component.html.erb b/modules/costs/app/components/my/time_tracking/list_component.html.erb
index 42edbec2327..34ac3c07df1 100644
--- a/modules/costs/app/components/my/time_tracking/list_component.html.erb
+++ b/modules/costs/app/components/my/time_tracking/list_component.html.erb
@@ -30,6 +30,6 @@
<%= render(Primer::OpenProject::Heading.new(tag: :h2, classes: class_names("mt-3" => !i.zero?))) do
date_title(date)
end %>
- <%= render(My::TimeTracking::DailyEntriesTable.new(rows: time_entries_by_day[date], date: date)) %>
+ <%= render(My::TimeTracking::DailyEntriesTable.new(rows: grouped_time_entries[date], date: date, mode: mode)) %>
<%- end %>
<%- end %>
diff --git a/modules/costs/app/components/my/time_tracking/list_component.rb b/modules/costs/app/components/my/time_tracking/list_component.rb
index 02036020861..2ff0450c4d3 100644
--- a/modules/costs/app/components/my/time_tracking/list_component.rb
+++ b/modules/costs/app/components/my/time_tracking/list_component.rb
@@ -51,33 +51,43 @@ module My
case mode
when :day then [date]
when :week then date.all_week
- when :month then date.all_month
+ when :month then date.all_month.map(&:beginning_of_week).uniq
end
end
- def time_entries_by_day
- @time_entries_by_day ||= time_entries.group_by(&:spent_on).tap do |hash|
- hash.default_proc = ->(h, k) { h[k] = [] }
- end
+ def grouped_time_entries
+ @grouped_time_entries ||= time_entries
+ .group_by { |entry| mode == :month ? entry.spent_on.beginning_of_week : entry.spent_on }
+ .tap do |hash|
+ hash.default_proc = ->(h, k) { h[k] = [] }
+ end
end
- def total_hours_per_day(date)
+ def total_hours_for(date)
total_hours = time_entries_by_day[date].sum(&:hours).round(2)
DurationConverter.output(total_hours, format: :hours_and_minutes)
end
def date_title(date)
- result = [
- render(Primer::Beta::Text.new) { date.strftime("%A %d") }
- ]
+ if mode == :month
+ I18n.t(:label_specific_week, week: date.strftime("%W %Y"))
+ else
+ date.strftime("%A %d")
+ end
+ end
- if date.today?
- result << render(Primer::Beta::Text.new(color: :muted)) { t("label_today") }
+ def date_additional_info(date)
+ if mode == :month
+ if Date.current.beginning_of_week == date
+ t(:label_this_week)
+ elsif 1.week.ago.beginning_of_week == date
+ t(:label_last_week)
+ end
+ elsif date.today?
+ t(:label_today)
elsif date.yesterday?
- result << render(Primer::Beta::Text.new(color: :muted)) { t("label_yesterday") }
+ t(:label_yesterday)
end
-
- safe_join(result, " ")
end
end
end
diff --git a/modules/costs/app/components/my/time_tracking/time_entry_row.rb b/modules/costs/app/components/my/time_tracking/time_entry_row.rb
index 0ddcfdfe3a1..a5e604343a5 100644
--- a/modules/costs/app/components/my/time_tracking/time_entry_row.rb
+++ b/modules/costs/app/components/my/time_tracking/time_entry_row.rb
@@ -57,6 +57,10 @@ module My
end
end
+ def spent_on
+ I18n.l(time_entry.spent_on)
+ end
+
def time # rubocop:disable Metrics/AbcSize
return if time_entry.start_time.blank?