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

split out activity component and add menu

Klaus Zanders346b7ff75545
diff --git a/modules/costs/app/components/admin/time_entry_activities/activity_component.html.erb b/modules/costs/app/components/admin/time_entry_activities/activity_component.html.erb
new file mode 100644
index 00000000000..44194f0d36e
--- /dev/null
+++ b/modules/costs/app/components/admin/time_entry_activities/activity_component.html.erb
@@ -0,0 +1,31 @@
+<%=
+ flex_layout(align_items: :center, justify_content: :space_between) do |activity_container|
+ activity_container.with_column(flex_layout: true) do |activity_info|
+ activity_info.with_column(mr: 2) do
+ render(Primer::OpenProject::DragHandle.new(draggable: true))
+ end
+
+ activity_info.with_column(mr: 2) do
+ render(Primer::Beta::Link.new(href: edit_admin_time_entry_activity_path(activity), underline: false)) do
+ render(Primer::Beta::Text.new(font_weight: :bold)) { activity.name }
+ end
+ end
+
+ activity_info.with_column(mr: 2) do
+ render(Primer::Beta::Text.new(color: :subtle)) { activity.active? ? "Active" : "Inactive" }
+ end
+ end
+
+ activity_container.with_column do
+ render(Primer::Alpha::ActionMenu.new(test_selector: "op-time-entry-acrtivity--action-menu")) do |menu|
+ menu.with_show_button(
+ icon: "kebab-horizontal",
+ scheme: :invisible,
+ "aria-label": "Actions"
+ )
+
+ build_activity_menu(menu)
+ end
+ end
+ end
+%>
diff --git a/modules/costs/app/components/admin/time_entry_activities/activity_component.rb b/modules/costs/app/components/admin/time_entry_activities/activity_component.rb
new file mode 100644
index 00000000000..71946da846b
--- /dev/null
+++ b/modules/costs/app/components/admin/time_entry_activities/activity_component.rb
@@ -0,0 +1,133 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Admin
+ module TimeEntryActivities
+ class ActivityComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+
+ options :activity
+ options :max_activity_position
+
+ private
+
+ def first_item?
+ activity.position == 1
+ end
+
+ def last_item?
+ activity.position == max_activity_position
+ end
+
+ def build_activity_menu(menu)
+ edit_activity(menu)
+ menu.with_divider
+ if !first_item?
+ move_to_top_activity(menu)
+ move_up_activity(menu)
+ end
+ if !last_item?
+ move_down_activity(menu)
+ move_to_bottom_activity(menu)
+ end
+ menu.with_divider
+ deletion_activity(menu)
+ end
+
+ def edit_activity(menu)
+ menu.with_item(label: I18n.t(:button_edit),
+ tag: :a,
+ href: edit_admin_time_entry_activity_path(activity)) do |item|
+ item.with_leading_visual_icon(icon: :pencil)
+ end
+ end
+
+ def move_to_top_activity(menu)
+ form_inputs = [{ name: "position", value: 1 }]
+
+ menu.with_item(label: I18n.t(:label_sort_highest),
+ tag: :button,
+ href: admin_time_entry_activity_move_path(activity),
+ # content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ form_arguments: { method: :post, inputs: form_inputs }) do |item|
+ item.with_leading_visual_icon(icon: "move-to-top")
+ end
+ end
+
+ def move_up_activity(menu)
+ form_inputs = [{ name: "position", value: activity.position - 1 }]
+
+ menu.with_item(label: I18n.t(:label_sort_higher),
+ tag: :button,
+ href: admin_time_entry_activity_move_path(activity),
+ # content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ form_arguments: { method: :post, inputs: form_inputs }) do |item|
+ item.with_leading_visual_icon(icon: "chevron-up")
+ end
+ end
+
+ def move_down_activity(menu)
+ form_inputs = [{ name: "position", value: activity.position + 1 }]
+
+ menu.with_item(label: I18n.t(:label_sort_lower),
+ tag: :button,
+ href: admin_time_entry_activity_move_path(activity),
+ # content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ form_arguments: { method: :post, inputs: form_inputs }) do |item|
+ item.with_leading_visual_icon(icon: "chevron-down")
+ end
+ end
+
+ def move_to_bottom_activity(menu)
+ form_inputs = [{ name: "position", value: max_activity_position + 1 }]
+
+ menu.with_item(label: I18n.t(:label_sort_lowest),
+ tag: :button,
+ href: admin_time_entry_activity_move_path(activity),
+ # content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ form_arguments: { method: :post, inputs: form_inputs }) do |item|
+ item.with_leading_visual_icon(icon: "move-to-bottom")
+ end
+ end
+
+ def deletion_activity(menu)
+ menu.with_item(label: I18n.t(:button_delete),
+ tag: :button,
+ scheme: :danger,
+ href: admin_time_entry_activity_path(activity),
+ # content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ form_arguments: { method: :delete }) do |item|
+ item.with_leading_visual_icon(icon: :trash)
+ end
+ end
+ end
+ end
+end
diff --git a/modules/costs/app/components/admin/time_entry_activities/index_component.html.erb b/modules/costs/app/components/admin/time_entry_activities/index_component.html.erb
index 9884eb58a26..ff3163ae6e1 100644
--- a/modules/costs/app/components/admin/time_entry_activities/index_component.html.erb
+++ b/modules/costs/app/components/admin/time_entry_activities/index_component.html.erb
@@ -35,47 +35,7 @@
else
time_entry_activities.each do |activity|
component.with_row(test_selector: "time-entry-activity-row-#{activity.id}") do
- flex_layout(align_items: :center, justify_content: :space_between) do |activity_container|
- activity_container.with_column(flex_layout: true) do |activity_info|
- activity_info.with_column(mr: 2) do
- render(Primer::OpenProject::DragHandle.new(draggable: true))
- end
-
- activity_info.with_column(mr: 2) do
- render(Primer::Beta::Link.new(href: edit_admin_time_entry_activity_path(activity), underline: false)) do
- render(Primer::Beta::Text.new(font_weight: :bold)) { activity.name }
- end
- end
-
- activity_info.with_column(mr: 2) do
- render(Primer::Beta::Text.new(color: :subtle)) { activity.active? ? "Active" : "Inactive" }
- end
- end
-
- activity_container.with_column do
- render(Primer::Alpha::ActionMenu.new(test_selector: "op-time-entry-acrtivity--action-menu")) do |menu|
- menu.with_show_button(
- icon: "kebab-horizontal",
- scheme: :invisible,
- "aria-label": "Actions"
- )
-
- menu.with_item(label: I18n.t(:button_edit), tag: :a, href: edit_admin_time_entry_activity_path(activity)) do |item|
- item.with_leading_visual_icon(icon: :pencil)
- end
-
- menu.with_item(
- label: I18n.t(:button_delete),
- scheme: :danger,
- tag: :a,
- method: :delete,
- href: admin_time_entry_activity_path(activity)
- ) do |item|
- item.with_leading_visual_icon(icon: :trash)
- end
- end
- end
- end
+ render(Admin::TimeEntryActivities::ActivityComponent.new(activity: activity, max_activity_position: max_activity_position))
end
end
end
diff --git a/modules/costs/app/components/admin/time_entry_activities/index_component.rb b/modules/costs/app/components/admin/time_entry_activities/index_component.rb
index 35845b2d96d..aa10de1c8a0 100644
--- a/modules/costs/app/components/admin/time_entry_activities/index_component.rb
+++ b/modules/costs/app/components/admin/time_entry_activities/index_component.rb
@@ -38,6 +38,10 @@ module Admin
private
+ def max_activity_position
+ time_entry_activities.map(&:position).max
+ end
+
def wrapper_data_attributes
{
# controller: "projects--settings--border-box-filter",