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
Implement drag & drop sorting for time entry activities
Klaus Zanders42e4c1237dea
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.erbindex 44194f0d36e..cd5930dd03e 100644--- 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@@ -1,30 +1,32 @@<%=- 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+ component_wrapper 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 }+ 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 }+ endend- end- activity_info.with_column(mr: 2) do- render(Primer::Beta::Text.new(color: :subtle)) { activity.active? ? "Active" : "Inactive" }+ activity_info.with_column(mr: 2) do+ render(Primer::Beta::Text.new(color: :subtle)) { activity.active? ? "Active" : "Inactive" }+ endend- 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"- )+ 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)+ build_activity_menu(menu)+ endendendenddiff --git a/modules/costs/app/components/admin/time_entry_activities/activity_component.rb b/modules/costs/app/components/admin/time_entry_activities/activity_component.rbindex d8f3c6839f7..16e9c4ec6e9 100644--- a/modules/costs/app/components/admin/time_entry_activities/activity_component.rb+++ b/modules/costs/app/components/admin/time_entry_activities/activity_component.rb@@ -33,12 +33,17 @@ module Adminclass ActivityComponent < ApplicationComponentinclude ApplicationHelperinclude OpPrimer::ComponentHelpers+ include OpTurbo::Streamableoptions :activityoptions :max_activity_positionprivate+ def wrapper_uniq_by+ activity.id+ end+def first_item?activity.position == 1end@@ -77,7 +82,7 @@ module Admintag: :button,href: move_admin_time_entry_activity_path(activity),# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },- form_arguments: { method: :post, inputs: form_inputs }) do |item|+ form_arguments: { method: :put, inputs: form_inputs }) do |item|item.with_leading_visual_icon(icon: "move-to-top")endend@@ -89,7 +94,7 @@ module Admintag: :button,href: move_admin_time_entry_activity_path(activity),# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },- form_arguments: { method: :post, inputs: form_inputs }) do |item|+ form_arguments: { method: :put, inputs: form_inputs }) do |item|item.with_leading_visual_icon(icon: "chevron-up")endend@@ -101,7 +106,7 @@ module Admintag: :button,href: move_admin_time_entry_activity_path(activity),# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },- form_arguments: { method: :post, inputs: form_inputs }) do |item|+ form_arguments: { method: :put, inputs: form_inputs }) do |item|item.with_leading_visual_icon(icon: "chevron-down")endend@@ -113,7 +118,7 @@ module Admintag: :button,href: move_admin_time_entry_activity_path(activity),# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },- form_arguments: { method: :post, inputs: form_inputs }) do |item|+ form_arguments: { method: :put, inputs: form_inputs }) do |item|item.with_leading_visual_icon(icon: "move-to-bottom")endenddiff --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.erbindex 96122131a93..d2da87b5829 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@@ -29,7 +29,7 @@endflex.with_row do- render(border_box_container(data: { test_selector: "admin-time-entry-activity" })) do |component|+ render(border_box_container(data: drop_target_config)) do |component|component.with_header(font_weight: :bold) { "Time entry activities" }if time_entry_activities.empty?@@ -38,7 +38,7 @@endelsetime_entry_activities.each do |activity|- component.with_row(test_selector: "time-entry-activity-row-#{activity.id}") do+ component.with_row(test_selector: "time-entry-activity-row-#{activity.id}", data: draggable_item_config(activity)) dorender(Admin::TimeEntryActivities::ActivityComponent.new(activity: activity, max_activity_position: max_activity_position))endenddiff --git a/modules/costs/app/components/admin/time_entry_activities/index_component.rb b/modules/costs/app/components/admin/time_entry_activities/index_component.rbindex aa10de1c8a0..74bb76c0ca9 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@@ -33,6 +33,7 @@ module Adminclass IndexComponent < ApplicationComponentinclude ApplicationHelperinclude OpPrimer::ComponentHelpers+ include OpTurbo::Streamableoptions :time_entry_activities@@ -44,10 +45,26 @@ module Admindef wrapper_data_attributes{- # controller: "projects--settings--border-box-filter",+ controller: "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": "time-entry-activity"+ }+ end++ def draggable_item_config(activity)+ {+ "draggable-id": activity.id,+ "draggable-type": "time-entry-activity",+ "drop-url": move_admin_time_entry_activity_path(activity)+ }+ endendendenddiff --git a/modules/costs/app/controllers/admin/time_entry_activities_controller.rb b/modules/costs/app/controllers/admin/time_entry_activities_controller.rbindex f78bdb03f8c..ef64ce661f1 100644--- a/modules/costs/app/controllers/admin/time_entry_activities_controller.rb+++ b/modules/costs/app/controllers/admin/time_entry_activities_controller.rb@@ -80,7 +80,7 @@ module Adminenddef move- if @time_entry_activity.update(move_to: move_to_attribute)+ if @time_entry_activity.update(move_params)flash[:notice] = I18n.t(:notice_successful_update)elseflash[:error] = I18n.t(:error_type_could_not_be_saved)@@ -95,13 +95,16 @@ module Adminprivate- def move_to_attribute+ def move_paramsmove_to = params[:move_to]+ position = Integer(params[:position], exception: false)if move_to.in? %w(highest higher lower lowest)- move_to+ { move_to: move_to }+ elsif position+ { position: position }else- raise ArgumentError, "Invalid move_to value: #{move_to}"+ {}endenddiff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rbindex ab83cb18271..e3037a9cb60 100644--- a/modules/costs/config/routes.rb+++ b/modules/costs/config/routes.rb@@ -71,7 +71,7 @@ Rails.application.routes.draw donamespace :admin doresources :time_entry_activities, except: [:show] domember do- post :move+ put :moveget :reassignendend