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

Start implementing table view

Klaus Zanders5acefc9e9279
diff --git a/modules/costs/app/components/my/time_tracking/table_component.html.erb b/modules/costs/app/components/my/time_tracking/table_component.html.erb
new file mode 100644
index 00000000000..1a5757b9205
--- /dev/null
+++ b/modules/costs/app/components/my/time_tracking/table_component.html.erb
@@ -0,0 +1,8 @@
+<h1> We are a table component </h1>
+<h2><%= title %></h2>
+
+<ul>
+ <%- time_entries.each do |te| %>
+ <li><%= te.spent_on %> <%= te.hours %>h - <%= te.work_package.subject %></li>
+ <%- end %>
+</ul>
diff --git a/modules/costs/app/components/my/time_tracking/table_component.rb b/modules/costs/app/components/my/time_tracking/table_component.rb
new file mode 100644
index 00000000000..adf3f3e80a3
--- /dev/null
+++ b/modules/costs/app/components/my/time_tracking/table_component.rb
@@ -0,0 +1,96 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+module My
+ module TimeTracking
+ class TableComponent < ApplicationComponent
+ include OpTurbo::Streamable
+
+ options time_entries: [],
+ mode: :week,
+ date: Date.current
+
+ private
+
+ def today_href
+ case mode
+ when :day
+ my_time_tracking_day_path(date: Date.current)
+ when :week
+ my_time_tracking_week_path(date: Date.current)
+ when :month
+ my_time_tracking_month_path(date: Date.current)
+ end
+ end
+
+ def title # rubocop:disable Metrics/AbcSize
+ case mode
+ when :day
+ I18n.l(date, format: :long)
+ when :week
+ bow = date.beginning_of_week
+ eow = date.end_of_week
+
+ if bow.year == eow.year && bow.month == eow.month
+ "#{bow.strftime('%d.')} - #{eow.strftime('%d. %B %Y')}"
+ elsif bow.year == eow.year
+ "#{bow.strftime('%d. %B')} - #{eow.strftime('%d. %B %Y')}"
+ else
+ "#{bow.strftime('%d. %B %Y')} - #{eow.strftime('%d. %B %Y')}"
+ end
+ when :month
+ date.strftime("%B %Y")
+ end
+ end
+
+ def previous_attrs
+ case mode
+ when :day
+ { href: my_time_tracking_day_path(date: date - 1.day), aria: { label: I18n.t(:label_previous_day) } }
+ when :week
+ { href: my_time_tracking_week_path(date: date - 1.week), aria: { label: I18n.t(:label_previous_week) } }
+ when :month
+ { href: my_time_tracking_month_path(date: date - 1.month), aria: { label: I18n.t(:label_previous_month) } }
+ end
+ end
+
+ def next_attrs
+ case mode
+ when :day
+ { href: my_time_tracking_day_path(date: date + 1.day), aria: { label: I18n.t(:label_next_day) } }
+ when :week
+ { href: my_time_tracking_week_path(date: date + 1.week), aria: { label: I18n.t(:label_next_week) } }
+ when :month
+ { href: my_time_tracking_month_path(date: date + 1.month), aria: { label: I18n.t(:label_next_month) } }
+ end
+ end
+ end
+ end
+end
diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rb
index b736f134092..7c2f1594d9a 100644
--- a/modules/costs/app/controllers/my/time_tracking_controller.rb
+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb
@@ -48,7 +48,7 @@ module My
layout "global"
- helper_method :current_day, :today?, :this_week?, :this_month?, :time_entries_json
+ helper_method :current_day, :today?, :this_week?, :this_month?, :list_view_component
def calendar
if browser.device.mobile?
@@ -122,6 +122,15 @@ module My
@time_entries = TimeEntry
.includes(:project, :activity, { work_package: :status })
.where(user: User.current, spent_on: time_scope)
+ .order(:spent_on, :start_time, :hours)
+ end
+
+ def list_view_component
+ if params[:view_mode] == "list"
+ My::TimeTracking::TableComponent.new(time_entries: @time_entries, mode: params[:action].to_sym, date: current_day)
+ else
+ My::TimeTracking::CalendarComponent.new(time_entries: @time_entries, mode: params[:action].to_sym, date: current_day)
+ 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 5a12f3e2a20..141f7b39ece 100644
--- a/modules/costs/app/views/my/time_tracking/day.html.erb
+++ b/modules/costs/app/views/my/time_tracking/day.html.erb
@@ -10,4 +10,4 @@
end
%>
-<%= render(My::TimeTracking::CalendarComponent.new(time_entries: @time_entries, mode: :day, date: current_day)) %>
+<%= render(list_view_component) %>
diff --git a/modules/costs/app/views/my/time_tracking/month.html.erb b/modules/costs/app/views/my/time_tracking/month.html.erb
index cc81cb00474..6f55ca5bce5 100644
--- a/modules/costs/app/views/my/time_tracking/month.html.erb
+++ b/modules/costs/app/views/my/time_tracking/month.html.erb
@@ -10,4 +10,4 @@
end
%>
-<%= render(My::TimeTracking::CalendarComponent.new(time_entries: @time_entries, mode: :month, date: current_day)) %>
+<%= render(list_view_component) %>
diff --git a/modules/costs/app/views/my/time_tracking/week.html.erb b/modules/costs/app/views/my/time_tracking/week.html.erb
index 06b96d87ea0..4aea1d1b5fa 100644
--- a/modules/costs/app/views/my/time_tracking/week.html.erb
+++ b/modules/costs/app/views/my/time_tracking/week.html.erb
@@ -8,24 +8,29 @@
]
)
- btn = lambda do |button|
+ cal_button = lambda do |button|
button.with_leading_visual_icon(icon: :calendar)
button.with_trailing_action_icon(icon: :"triangle-down")
"Calendar"
end
- header.with_action_menu(menu_arguments: { anchor_align: :end }, button_arguments: { button_block: btn }) do |menu|
- menu.with_item(label: "Calendar") do |item|
+ list_button = lambda do |button|
+ button.with_leading_visual_icon(icon: "list-unordered")
+ button.with_trailing_action_icon(icon: :"triangle-down")
+ "List"
+ end
+
+ header.with_action_menu(menu_arguments: { anchor_align: :end }, button_arguments: { button_block: params[:view_mode] == "list" ? list_button : cal_button }) do |menu|
+ menu.with_item(label: "Calendar", tag: :a, href: url_for(params.permit(:controller, :action, :date).merge(view_mode: "calendar"))) do |item|
item.with_leading_visual_icon(icon: :calendar)
end
- menu.with_item(label: "List") do |item|
+ menu.with_item(label: "List", tag: :a, href: url_for(params.permit(:controller, :action, :date).merge(view_mode: "list"))) do |item|
item.with_leading_visual_icon(icon: "list-unordered")
end
end
header.with_action_zen_mode_button
- header.with_action_icon_button(icon: "ellipsis", mobile_icon: "ellipsis", label: "more")
end
%>
-<%= render(My::TimeTracking::CalendarComponent.new(time_entries: @time_entries, mode: :week, date: current_day)) %>
+<%= render(list_view_component) %>
diff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rb
index 92d16421f7f..7a9e24d2ecb 100644
--- a/modules/costs/config/routes.rb
+++ b/modules/costs/config/routes.rb
@@ -51,9 +51,15 @@ Rails.application.routes.draw do
get "/timer" => "timer#show", as: "timers"
get "/time-tracking" => "time_tracking#calendar"
- get "/time-tracking/day" => "time_tracking#day"
- get "/time-tracking/week" => "time_tracking#week"
- get "/time-tracking/month" => "time_tracking#month"
+ get "/time-tracking/day(-:view_mode)" => "time_tracking#day",
+ defaults: { view_mode: "calendar" },
+ as: :time_tracking_day
+ get "/time-tracking/week(-:view_mode)" => "time_tracking#week",
+ defaults: { view_mode: "calendar" },
+ as: :time_tracking_week
+ get "/time-tracking/month(-view_mode)" => "time_tracking#month",
+ defaults: { view_mode: "calendar" },
+ as: :time_tracking_month
end
scope "projects/:project_id", as: "project", module: "projects" do