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

Move view mode switching to a TabNav

Klaus Zanders681a0e7081cb
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 9a4539d2adb..82afbdfbdcd 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
@@ -1,6 +1,7 @@
<% helpers.html_title t(:label_my_time_tracking), "#{t("label_#{mode}")} #{t(:label_calendar)} #{I18n.l(date)}" -%>
<%= flex_layout(data: wrapper_data, classes: "my-time-tracking-calendar-view") do |calendar_page| %>
<% calendar_page.with_row { render(My::TimeTracking::HeaderComponent.new(mode:, date:, view_mode: :calendar)) } %>
+ <% calendar_page.with_row { render(My::TimeTracking::ViewModeSwitcherComponent.new(mode:, date:, view_mode: :calendar)) } %>
<% calendar_page.with_row { render(My::TimeTracking::SubHeaderComponent.new(mode:, date:, view_mode: :calendar)) } %>
<% calendar_page.with_row(classes: "op-fc-wrapper", data: { "my--time-tracking-target" => "calendar" }) %>
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 bd4f8b7fd8b..fa96e9ac17b 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
@@ -7,25 +7,5 @@
]
)
- header.with_action_menu(
- menu_arguments: { anchor_align: :end },
- button_arguments: { button_block: view_mode_block }
- ) do |menu|
- menu.with_item(
- label: t(:label_calendar),
- tag: :a,
- href: my_time_tracking_path(date: date, mode: mode, view_mode: "calendar")
- ) do |item|
- item.with_leading_visual_icon(icon: :calendar)
- end
- menu.with_item(
- label: t(:label_list),
- tag: :a,
- href: my_time_tracking_path(date: date, mode: mode, view_mode: "list")
- ) do |item|
- item.with_leading_visual_icon(icon: "list-unordered")
- end
- end
-
header.with_action_zen_mode_button
end %>
diff --git a/modules/costs/app/components/my/time_tracking/header_component.rb b/modules/costs/app/components/my/time_tracking/header_component.rb
index 91f70a3a9d9..4ac91f705c6 100644
--- a/modules/costs/app/components/my/time_tracking/header_component.rb
+++ b/modules/costs/app/components/my/time_tracking/header_component.rb
@@ -32,22 +32,6 @@ module My
module TimeTracking
class HeaderComponent < ApplicationComponent
options :date, :mode, :view_mode
-
- def view_mode_block
- if view_mode == :list
- lambda do |button|
- button.with_leading_visual_icon(icon: "list-unordered")
- button.with_trailing_action_icon(icon: "triangle-down")
- t(:label_list)
- end
- else
- lambda do |button|
- button.with_leading_visual_icon(icon: :calendar)
- button.with_trailing_action_icon(icon: "triangle-down")
- t(:label_calendar)
- end
- end
- end
end
end
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 0424eb7ead5..06dfae607b9 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,7 @@
<% helpers.html_title t(:label_my_time_tracking), "#{t("label_#{mode}")} #{t(:label_list)} #{I18n.l(date)}" -%>
<%= component_wrapper(tag: "div", data: wrapper_data) do %>
<%= render(My::TimeTracking::HeaderComponent.new(mode:, date:, view_mode: :list)) %>
+ <%= render(My::TimeTracking::ViewModeSwitcherComponent.new(mode:, date:, view_mode: :list)) %>
<%= render(My::TimeTracking::SubHeaderComponent.new(mode:, date:, view_mode: :list)) %>
<%= flex_layout(classes: ["my-time-tracking-list-view"]) do |flex| %>
diff --git a/modules/costs/app/components/my/time_tracking/view_mode_switcher_component.rb b/modules/costs/app/components/my/time_tracking/view_mode_switcher_component.rb
new file mode 100644
index 00000000000..1a3accefbc2
--- /dev/null
+++ b/modules/costs/app/components/my/time_tracking/view_mode_switcher_component.rb
@@ -0,0 +1,57 @@
+# 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 ViewModeSwitcherComponent < ApplicationComponent
+ options :mode,
+ :view_mode,
+ :date
+
+ def call
+ render(Primer::Alpha::TabNav.new(label: I18n.l(:label_view_mode_switcher))) do |component|
+ component.with_tab(selected: view_mode == :calendar, href: link(:calendar)) do |tab|
+ tab.with_text { I18n.t(:label_calendar) }
+ tab.with_icon(icon: :calendar)
+ end
+
+ component.with_tab(selected: view_mode == :list, href: link(:list)) do |tab|
+ tab.with_text { I18n.t(:label_list) }
+ tab.with_icon(icon: "op-view-list")
+ end
+ end
+ end
+
+ def link(new_view_mode)
+ my_time_tracking_path(date: date, mode: mode, view_mode: new_view_mode)
+ end
+ end
+ end
+end