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

add menu, handle moving and destroying

Ivan Kuchin418374f7bf4a
diff --git a/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb b/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb
index 3780a5e3e8e..21160383e14 100644
--- a/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb
+++ b/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb
@@ -69,7 +69,11 @@ See COPYRIGHT and LICENSE files for more details.
else
definitions.each do |definition|
component.with_row(data: { "projects--settings--border-box-filter-target": "searchItem" }) do
- render(Settings::ProjectLifeCycleStepDefinitions::RowComponent.new(definition))
+ render(Settings::ProjectLifeCycleStepDefinitions::RowComponent.new(
+ definition,
+ first?: definition == definitions.first,
+ last?: definition == definitions.last,
+ ))
end
end
end
diff --git a/app/components/settings/project_life_cycle_step_definitions/row_component.html.erb b/app/components/settings/project_life_cycle_step_definitions/row_component.html.erb
index ec8642a03b8..83b6773ae6d 100644
--- a/app/components/settings/project_life_cycle_step_definitions/row_component.html.erb
+++ b/app/components/settings/project_life_cycle_step_definitions/row_component.html.erb
@@ -46,5 +46,40 @@ See COPYRIGHT and LICENSE files for more details.
render(Primer::Beta::Text.new) { t("project.count", count: definition.project_count) }
end
end
+ row_container.with_column do
+ render(Primer::Alpha::ActionMenu.new) do |menu|
+ menu.with_show_button(icon: "kebab-horizontal", "aria-label": t(:button_actions), scheme: :invisible)
+
+ menu.with_item(
+ label: t(:label_edit),
+ href: edit_admin_settings_project_life_cycle_step_definition_path(definition)
+ ) do |item|
+ item.with_leading_visual_icon(icon: :pencil)
+ end
+
+ unless first?
+ move_action(menu:, move_to: :highest, label: t("label_agenda_item_move_to_top"), icon: "move-to-top")
+ move_action(menu:, move_to: :higher, label: t("label_agenda_item_move_up"), icon: "chevron-up")
+ end
+ unless last?
+ move_action(menu:, move_to: :lower, label: t("label_agenda_item_move_down"), icon: "chevron-down")
+ move_action(menu:, move_to: :lowest, label: t("label_agenda_item_move_to_bottom"), icon: "move-to-bottom")
+ end
+
+ menu.with_item(
+ label: t(:text_destroy),
+ scheme: :danger,
+ href: admin_settings_project_life_cycle_step_definition_path(definition),
+ form_arguments: {
+ method: :delete,
+ data: {
+ confirm: t("text_are_you_sure_with_project_life_cycle_step")
+ }
+ }
+ ) do |item|
+ item.with_leading_visual_icon(icon: :trash)
+ end
+ end
+ end
end
%>
diff --git a/app/components/settings/project_life_cycle_step_definitions/row_component.rb b/app/components/settings/project_life_cycle_step_definitions/row_component.rb
index 9d2ae086248..1f165751a6c 100644
--- a/app/components/settings/project_life_cycle_step_definitions/row_component.rb
+++ b/app/components/settings/project_life_cycle_step_definitions/row_component.rb
@@ -32,6 +32,22 @@ module Settings
include OpPrimer::ComponentHelpers
alias_method :definition, :model
+
+ options :first?, :last?
+
+ private
+
+ def move_action(menu:, move_to:, label:, icon:)
+ menu.with_item(
+ label:,
+ href: move_admin_settings_project_life_cycle_step_definition_path(definition, move_to:),
+ form_arguments: {
+ method: :patch
+ }
+ ) do |item|
+ item.with_leading_visual_icon(icon:)
+ end
+ end
end
end
end
diff --git a/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb b/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb
index 6afae30c38d..30c5f31f37b 100644
--- a/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb
+++ b/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb
@@ -33,7 +33,7 @@ module Admin::Settings
before_action :check_feature_flag
before_action :find_definitions, only: %i[index]
- before_action :find_definition, only: %i[edit update]
+ before_action :find_definition, only: %i[edit update destroy move]
def index; end
@@ -73,6 +73,28 @@ module Admin::Settings
end
end
+ def destroy
+ if @definition.destroy
+ flash[:notice] = I18n.t(:notice_successful_delete)
+ else
+ # TODO: handle better
+ flash[:error] = I18n.t(:notice_bad_request)
+ end
+
+ redirect_to action: :index
+ end
+
+ def move
+ if @definition.update(params.permit(:move_to))
+ flash[:notice] = I18n.t(:notice_successful_update)
+ else
+ # TODO: handle better
+ flash[:error] = I18n.t(:notice_bad_request)
+ end
+
+ redirect_to action: :index
+ end
+
private
def check_feature_flag
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 16d48fbec46..6f6a63d212c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3827,6 +3827,7 @@ en:
text_are_you_sure_continue: "Are you sure you want to continue?"
text_are_you_sure_with_children: "Delete work package and all child work packages?"
text_are_you_sure_with_project_custom_fields: "Deleting this attribute will also delete its values in all projects. Are you sure you want to do this?"
+ text_are_you_sure_with_project_life_cycle_step: "Deleting this step will also delete its usages in all projects. Are you sure you want to do this?"
text_assign_to_project: "Assign to the project"
text_form_configuration: >
You can customize which fields will be displayed in work package forms.
diff --git a/config/routes.rb b/config/routes.rb
index 010880a0eac..0422fcab42a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -515,11 +515,14 @@ Rails.application.routes.draw do
resource :projects, controller: "/admin/settings/projects_settings", only: %i[show update]
resource :new_project, controller: "/admin/settings/new_project_settings", only: %i[show update]
resources :project_life_cycle_step_definitions, controller: "/admin/settings/project_life_cycle_step_definitions",
- only: %i[index create edit update] do
+ only: %i[index create edit update destroy] do
collection do
get :new_stage
get :new_gate
end
+ member do
+ patch :move
+ end
end
resources :project_custom_fields, controller: "/admin/settings/project_custom_fields" do
member do