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

Introduce a ModeSwitcherComponent and add it to the list component

Klaus Zanders9d3348a6fa48
diff --git a/modules/costs/app/components/my/time_tracking/calendar_component.html.erb b/modules/costs/app/components/my/time_tracking/calendar_component.html.erb
index 73843a75584..ddbeadf9292 100644
--- a/modules/costs/app/components/my/time_tracking/calendar_component.html.erb
+++ b/modules/costs/app/components/my/time_tracking/calendar_component.html.erb
@@ -3,18 +3,7 @@
<% calendar_page.with_row do %>
<%= render(Primer::OpenProject::SubHeader.new) do |component|
component.with_filter_component do
- render(Primer::Alpha::SegmentedControl.new("aria-label": I18n.t(:label_meeting_date_time))) do |control|
- %i[day week month].each do |action|
- control.with_item(
- tag: :a,
- href: url_for(params.permit(:controller, :date).merge(action:, view_mode: "calendar")),
- icon: "calendar", # TODO: Replace with proper icon
- label: t("label_#{action}"),
- title: t("label_#{action}"),
- selected: (mode == action)
- )
- end
- end
+ render(My::TimeTracking::ModeSwitcherComponent.new(current_mode: mode, view_mode: :calendar))
end
component.with_text { title }
diff --git a/modules/costs/app/components/my/time_tracking/header_component.html.erb b/modules/costs/app/components/my/time_tracking/header_component.html.erb
index 0c620795ded..27bcf1636f2 100644
--- a/modules/costs/app/components/my/time_tracking/header_component.html.erb
+++ b/modules/costs/app/components/my/time_tracking/header_component.html.erb
@@ -21,7 +21,7 @@
menu.with_item(
label: t(:label_list),
tag: :a,
- href: url_for(params.permit(:controller, :date).merge(view_mode: "list", action: "week"))
+ href: url_for(params.permit(:controller, :date, :action).merge(view_mode: "list"))
) do |item|
item.with_leading_visual_icon(icon: "list-unordered")
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 cdc2790dd98..42edbec2327 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
@@ -1,6 +1,10 @@
<%= component_wrapper(tag: "div", data: wrapper_data) do %>
<%= render(My::TimeTracking::HeaderComponent.new(mode:, date:, view_mode: :list)) %>
<%= render(Primer::OpenProject::SubHeader.new) do |component|
+ component.with_filter_component do
+ render(My::TimeTracking::ModeSwitcherComponent.new(current_mode: mode, view_mode: :calendar))
+ end
+
component.with_text { title }
component.with_action_component do
diff --git a/modules/costs/app/components/my/time_tracking/mode_switcher_component.rb b/modules/costs/app/components/my/time_tracking/mode_switcher_component.rb
new file mode 100644
index 00000000000..81e1170cd4f
--- /dev/null
+++ b/modules/costs/app/components/my/time_tracking/mode_switcher_component.rb
@@ -0,0 +1,53 @@
+# 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 ModeSwitcherComponent < ApplicationComponent
+ options :current_mode,
+ :view_mode
+
+ def call
+ render(Primer::Alpha::SegmentedControl.new("aria-label": I18n.t(:label_meeting_date_time))) do |control|
+ %i[day week month].each do |action|
+ control.with_item(
+ tag: :a,
+ href: url_for(params.permit(:controller, :date).merge(action:, view_mode: view_mode)),
+ icon: "calendar", # TODO: Replace with proper icon
+ label: t("label_#{action}"),
+ title: t("label_#{action}"),
+ selected: (current_mode == action)
+ )
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.yml
index 7b688e0302a..8d68c796eea 100644
--- a/modules/costs/config/locales/en.yml
+++ b/modules/costs/config/locales/en.yml
@@ -175,7 +175,7 @@ en:
label_previous_week: "Previous week"
label_previous_month: "Previous month"
label_specific_day: "Day %{day}"
- label_specific_week: "Week #%{week}"
+ label_specific_week: "Calendar week %{week}"
label_specific_month: "Month %{month}"
label_list: "List"
label_month: "Month"