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

Make labels into links

Marcello Rocha02366a91d1b3
diff --git a/app/components/admin/custom_fields/hierarchy/item_component.html.erb b/app/components/admin/custom_fields/hierarchy/item_component.html.erb
index 7ab34e1b8a9..c9095d506b8 100644
--- a/app/components/admin/custom_fields/hierarchy/item_component.html.erb
+++ b/app/components/admin/custom_fields/hierarchy/item_component.html.erb
@@ -42,8 +42,10 @@ See COPYRIGHT and LICENSE files for more details.
flex_layout(align_items: :center, justify_content: :space_between) do |item_container|
item_container.with_column(flex_layout: true) do |item_information|
item_information.with_column(mr: 2) do
- render(Primer::Beta::Text.new(font_weight: :bold)) do
- @hierarchy_item.label
+ render(Primer::Beta::Link.new(href: custom_field_item_path(@hierarchy_item.root, @hierarchy_item), underline: false)) do
+ render(Primer::Beta::Text.new(font_weight: :bold)) do
+ @hierarchy_item.label
+ end
end
end
@@ -52,16 +54,21 @@ See COPYRIGHT and LICENSE files for more details.
render(Primer::Beta::Text.new(color: :subtle)) { short_text }
end
end
+ end
- # Actions
- item_container.with_column do
- render(Primer::Alpha::ActionMenu.new(data: { test_selector: "op-hierarchy-item--action-menu" })) do |menu|
- menu.with_show_button(icon: "kebab-horizontal",
- scheme: :invisible,
- "aria-label": I18n.t("custom_fields.admin.items.actions"))
- edit_action_item(menu)
- deletion_action_item(menu)
- end
+ if @hierarchy_item.children.exists?
+ item_information.with_column(mr: 2) do
+ render(Primer::Beta::Text.new) { children_count }
+ end
+ end
+
+ item_container.with_column do
+ render(Primer::Alpha::ActionMenu.new(data: { test_selector: "op-hierarchy-item--action-menu" })) do |menu|
+ menu.with_show_button(icon: "kebab-horizontal",
+ scheme: :invisible,
+ "aria-label": I18n.t("custom_fields.admin.items.actions"))
+ edit_action_item(menu)
+ deletion_action_item(menu)
end
end
end
diff --git a/app/components/admin/custom_fields/hierarchy/item_component.rb b/app/components/admin/custom_fields/hierarchy/item_component.rb
index 142750b088b..0183d55a25d 100644
--- a/app/components/admin/custom_fields/hierarchy/item_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_component.rb
@@ -54,6 +54,10 @@ module Admin
@edit_item_form_data.fetch(:show, false)
end
+ def children_count
+ pluralize(@hierarchy_item.children.count, "sub-item")
+ end
+
def deletion_action_item(menu)
menu.with_item(label: I18n.t(:button_delete),
scheme: :danger,
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index c34fdb7299b..9fc37427bde 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -46,6 +46,8 @@ class CustomField < ApplicationRecord
dependent: :destroy,
inverse_of: "custom_field"
+ scope :hierarchy_root_and_children, -> { includes(hierarchy_root: { children: :children }) }
+
acts_as_list scope: [:type]
validates :field_format, presence: true
diff --git a/app/models/custom_field/hierarchy/item.rb b/app/models/custom_field/hierarchy/item.rb
index 5be42dd0feb..acdbaaf9606 100644
--- a/app/models/custom_field/hierarchy/item.rb
+++ b/app/models/custom_field/hierarchy/item.rb
@@ -33,4 +33,6 @@ class CustomField::Hierarchy::Item < ApplicationRecord
belongs_to :custom_field
has_closure_tree order: "sort_order", numeric_order: true, dependent: :destroy
+
+ scope :including_children, -> { includes(children: :children) }
end
diff --git a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb
index 3b8f132a776..72e682a2332 100644
--- a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb
+++ b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb
@@ -84,7 +84,7 @@ module CustomFields
# @param item [CustomField::Hierarchy::Item] the parent of the node
# @return [Success(Array<CustomField::Hierarchy::Item>)]
def get_branch(item:)
- Success(item.ancestors.reverse)
+ Success(item.self_and_ancestors.reverse)
end
# Move an item/node to a new parent item/node
diff --git a/app/views/admin/custom_fields/hierarchy/items/index.html.erb b/app/views/admin/custom_fields/hierarchy/items/index.html.erb
index 48cc28d03f0..f491a1448b0 100644
--- a/app/views/admin/custom_fields/hierarchy/items/index.html.erb
+++ b/app/views/admin/custom_fields/hierarchy/items/index.html.erb
@@ -31,4 +31,6 @@ See COPYRIGHT and LICENSE files for more details.
<%= render(Admin::CustomFields::EditFormHeaderComponent.new(custom_field: @custom_field, selected: :items)) %>
-<%= render(Admin::CustomFields::Hierarchy::ItemsComponent.new(custom_field: @custom_field)) %>
+<%= turbo_frame_tag :hierarchy_list, data: { turbo_action: :advance } do %>
+ <%= render(Admin::CustomFields::Hierarchy::ItemsComponent.new(custom_field: @custom_field)) %>
+<% end %>
diff --git a/app/views/admin/custom_fields/hierarchy/items/show.html.erb b/app/views/admin/custom_fields/hierarchy/items/show.html.erb
new file mode 100644
index 00000000000..4bff0023c4e
--- /dev/null
+++ b/app/views/admin/custom_fields/hierarchy/items/show.html.erb
@@ -0,0 +1,36 @@
+<%#-- 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.
+
+++#%>
+
+<% html_title t(:label_administration), "#{CustomField.model_name.human} #{h @custom_field.name}", t(:label_item_plural) %>
+
+<%= render(Admin::CustomFields::EditFormHeaderComponent.new(custom_field: @custom_field, selected: :items)) %>
+
+<%= turbo_frame_tag :hierarchy_list, data: { turbo_action: :advance } do %>
+ <%= render(Admin::CustomFields::Hierarchy::ItemsComponent.new(item: @hierarchy_item)) %>
+<% end %>
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 0895f2c65f5..e1401e38cea 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -40,6 +40,7 @@ See COPYRIGHT and LICENSE files for more details.
<meta name="current_menu_item" content="<%= current_menu_item %>"/>
<%# Disable prefetching while we have data-turbo=false on body %>
<meta name="turbo-prefetch" content="false">
+ <meta name="turbo-refresh-method" content="morph">
</head>
<body
class="<%= body_css_classes %> __overflowing_element_container __overflowing_body"
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2768c8b676b..50c86ac363c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -254,6 +254,11 @@ en:
short: "Short name"
notice:
remember_items_and_projects: "Remember to set items and projects in the respective tabs for this custom field."
+ hierarchy:
+ subitems:
+ zero: no sub-items
+ one: 1 sub-item
+ other: "%{count} sub-items"
text_add_new_custom_field: >
To add new custom fields to a project you first need to create them before
diff --git a/config/routes.rb b/config/routes.rb
index 1098044540e..9dac6ae20b7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -179,9 +179,10 @@ Rails.application.routes.draw do
controller: "/admin/custom_fields/custom_field_projects",
only: :destroy
resources :items,
- controller: "/admin/custom_fields/hierarchy/items",
- except: %i[show] do
+ controller: "/admin/custom_fields/hierarchy/items" do
get :deletion_dialog, on: :member
+ get :new_child, on: :member, action: :new
+ post :new_child, on: :member, action: :create
end
end
end
diff --git a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb
index 73e6d019d00..7a197909d85 100644
--- a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb
+++ b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb
@@ -140,9 +140,9 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService do
expect(result).to be_success
ancestors = result.value!
- expect(ancestors.size).to eq(2)
- expect(ancestors).to contain_exactly(root, luke)
- expect(ancestors.last).to eq(luke)
+ expect(ancestors.size).to eq(3)
+ expect(ancestors).to contain_exactly(root, luke, leia)
+ expect(ancestors.last).to eq(leia)
end
end
@@ -150,7 +150,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService do
it "returns a empty list" do
result = service.get_branch(item: root)
expect(result).to be_success
- expect(result.value!).to be_empty
+ expect(result.value!).to match_array(root)
end
end
end