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

Normalizes form URL

Marcello Rochafbe039332593
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 eabc0eea2cc..8cf7afea3a1 100644
--- a/app/components/admin/custom_fields/hierarchy/item_component.html.erb
+++ b/app/components/admin/custom_fields/hierarchy/item_component.html.erb
@@ -29,15 +29,14 @@ See COPYRIGHT and LICENSE files for more details.
<%=
component_wrapper(tag: "turbo-frame", refresh: :morph) do
- if show_edit_form?
- render Admin::CustomFields::Hierarchy::ItemFormComponent.new(
- target_item: model,
- url: custom_field_item_path(@root.custom_field_id, model),
- method: :put
- )
+ if show_form?
+ render Admin::CustomFields::Hierarchy::ItemFormComponent.new(model)
else
flex_layout(align_items: :center, justify_content: :space_between, test_selector: "op-custom-fields--hierarchy-item") do |item_container|
item_container.with_column(flex_layout: true) do |item_information|
+ item_information.with_column(mr: 2) do
+ render(Primer::OpenProject::DragHandle.new)
+ end
item_information.with_column(mr: 2) do
render(Primer::Beta::Link.new(href: custom_field_item_path(@root.custom_field_id, model), underline: false)) do
render(Primer::Beta::Text.new(font_weight: :bold)) { model.label }
@@ -62,8 +61,7 @@ See COPYRIGHT and LICENSE files for more details.
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)
+ menu_items(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 980fc9307e4..579a16e8a65 100644
--- a/app/components/admin/custom_fields/hierarchy/item_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_component.rb
@@ -38,7 +38,7 @@ module Admin
def initialize(item:, show_edit_form: false)
super(item)
@show_edit_form = show_edit_form
- @root = item.root
+ @root = item.root || item.parent.root
end
def wrapper_uniq_by
@@ -49,12 +49,24 @@ module Admin
"(#{model.short})"
end
- def show_edit_form? = @show_edit_form
+ def show_form? = @show_edit_form || model.new_record?
def children_count
I18n.t("custom_fields.admin.hierarchy.subitems", count: model.children.count)
end
+ def menu_items(menu)
+ edit_action_item(menu)
+ menu.with_divider
+ add_above_action_item(menu)
+ add_below_action_item(menu)
+ add_sub_item_action_item(menu)
+ menu.with_divider
+ deletion_action_item(menu)
+ end
+
+ private
+
def deletion_action_item(menu)
menu.with_item(label: I18n.t(:button_delete),
scheme: :danger,
@@ -72,6 +84,33 @@ module Admin
item.with_leading_visual_icon(icon: :pencil)
end
end
+
+ def add_above_action_item(menu)
+ menu.with_item(
+ label: I18n.t(:button_add_item_above),
+ tag: :a,
+ content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ href: new_child_custom_field_item_path(@root.custom_field_id, model.parent, position: model.sort_order)
+ ) { _1.with_leading_visual_icon(icon: "fold-up") }
+ end
+
+ def add_below_action_item(menu)
+ menu.with_item(
+ label: I18n.t(:button_add_item_below),
+ tag: :a,
+ content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ href: new_child_custom_field_item_path(@root.custom_field_id, model.parent, position: model.sort_order + 1)
+ ) { _1.with_leading_visual_icon(icon: "fold-down") }
+ end
+
+ def add_sub_item_action_item(menu)
+ menu.with_item(
+ label: I18n.t(:button_add_sub_item),
+ tag: :a,
+ content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ href: new_child_custom_field_item_path(@root.custom_field_id, model)
+ ) { _1.with_leading_visual_icon(icon: "op-arrow-in") }
+ end
end
end
end
diff --git a/app/components/admin/custom_fields/hierarchy/item_form_component.rb b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
index bf1ce2b250a..49db3f4deb5 100644
--- a/app/components/admin/custom_fields/hierarchy/item_form_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
@@ -47,7 +47,7 @@ module Admin
def url
if model.new_record?
- new_child_custom_field_item_path(root.custom_field_id, model.parent, position: model.sort_order)
+ new_child_custom_field_item_path(root.custom_field_id, model.parent)
else
custom_field_item_path(root.custom_field_id, model)
end
diff --git a/app/components/admin/custom_fields/hierarchy/items_component.rb b/app/components/admin/custom_fields/hierarchy/items_component.rb
index b505999f19c..1b519236754 100644
--- a/app/components/admin/custom_fields/hierarchy/items_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/items_component.rb
@@ -45,7 +45,7 @@ module Admin
end
def new_item_path
- position = children.any? ? children.last.sort_order + 1 : 0
+ position = model.children.any? ? children.last.sort_order + 1 : 0
new_child_custom_field_item_path(root.custom_field_id, model, position:)
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a752108b58e..d59da529359 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1474,6 +1474,9 @@ en:
button_actions: "Actions"
button_add: "Add"
button_add_comment: "Add comment"
+ button_add_item_above: "Add item above"
+ button_add_item_below: "Add item below"
+ button_add_sub_item: "Add sub-item"
button_add_member: Add member
button_add_watcher: "Add watcher"
button_annotate: "Annotate"