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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
handle drag-n-drop ordering, except for expected turbo stream response
Ivan Kuchin946b6a81df8e
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.erbindex 21160383e14..ce0ba8d7c44 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@@ -50,7 +50,7 @@ See COPYRIGHT and LICENSE files for more details.endflex.with_row do- render(border_box_container(mb: 3)) do |component|+ render(border_box_container(mb: 3, data: drop_target_config)) do |component|component.with_header(font_weight: :bold, py: 2) doflex_layout(justify_content: :space_between, align_items: :center) do |header_container|header_container.with_column do@@ -68,7 +68,12 @@ See COPYRIGHT and LICENSE files for more details.endelsedefinitions.each do |definition|- component.with_row(data: { "projects--settings--border-box-filter-target": "searchItem" }) do+ component.with_row(+ data: {+ "projects--settings--border-box-filter-target": "searchItem",+ **draggable_item_config(definition)+ }+ ) dorender(Settings::ProjectLifeCycleStepDefinitions::RowComponent.new(definition,first?: definition == definitions.first,diff --git a/app/components/settings/project_life_cycle_step_definitions/index_component.rb b/app/components/settings/project_life_cycle_step_definitions/index_component.rbindex 107f81e0aed..f34bf7f8a91 100644--- a/app/components/settings/project_life_cycle_step_definitions/index_component.rb+++ b/app/components/settings/project_life_cycle_step_definitions/index_component.rb@@ -37,10 +37,25 @@ module Settingsdef wrapper_data_attributes{- controller: "projects--settings--border-box-filter",+ controller: "projects--settings--border-box-filter generic-drag-and-drop","application-target": "dynamic"}end++ def drop_target_config+ {+ "is-drag-and-drop-target": true,+ "target-container-accessor": "& > ul",+ "target-allowed-drag-type": "life-cycle-step-definition"+ }+ end++ def draggable_item_config(definition)+ {+ "draggable-type": "life-cycle-step-definition",+ "drop-url": drop_admin_settings_project_life_cycle_step_definition_path(definition)+ }+ endendendenddiff --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.erbindex 2c02f43f8f1..91c3064f4c4 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@@ -30,6 +30,9 @@ See COPYRIGHT and LICENSE files for more details.<%=flex_layout(align_items: :center, justify_content: :space_between) do |row_container|row_container.with_column(flex_layout: true, classes: "gap-2") do |title_container|+ title_container.with_column do+ render(Primer::OpenProject::DragHandle.new)+ endtitle_container.with_column dorender(Primer::Beta::Link.new(classes: 'filter-target-visible-text',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.rbindex 30c5f31f37b..402101a2587 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::Settingsbefore_action :check_feature_flagbefore_action :find_definitions, only: %i[index]- before_action :find_definition, only: %i[edit update destroy move]+ before_action :find_definition, only: %i[edit update destroy move drop]def index; end@@ -58,7 +58,7 @@ module Admin::Settingsif @definition.saveflash[:notice] = I18n.t(:notice_successful_create)- redirect_to action: :index+ redirect_to action: :index, status: :see_otherelserender :form, status: :unprocessable_entityend@@ -67,7 +67,7 @@ module Admin::Settingsdef updateif @definition.update(definition_params)flash[:notice] = I18n.t(:notice_successful_update)- redirect_to action: :index+ redirect_to action: :index, status: :see_otherelserender :form, status: :unprocessable_entityend@@ -81,7 +81,7 @@ module Admin::Settingsflash[:error] = I18n.t(:notice_bad_request)end- redirect_to action: :index+ redirect_to action: :index, status: :see_otherenddef move@@ -92,7 +92,18 @@ module Admin::Settingsflash[:error] = I18n.t(:notice_bad_request)end- redirect_to action: :index+ redirect_to action: :index, status: :see_other+ end++ def drop+ if @definition.update(params.permit(:position))+ flash[:notice] = I18n.t(:notice_successful_update)+ else+ # TODO: handle better+ flash[:error] = I18n.t(:notice_bad_request)+ end++ redirect_to action: :index, status: :see_otherendprivatediff --git a/config/routes.rb b/config/routes.rbindex 0422fcab42a..544b8597faf 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -522,6 +522,7 @@ Rails.application.routes.draw doendmember dopatch :move+ put :drop # should be patch, but requires passing method to generic-drag-and-drop controllerendendresources :project_custom_fields, controller: "/admin/settings/project_custom_fields" do