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
added nested drag and drop support as introduced on project custom fields
Jonas Jabaridc8a7fed0906
diff --git a/modules/meeting/app/components/meeting_agenda_items/list_component.html.erb b/modules/meeting/app/components/meeting_agenda_items/list_component.html.erbindex 177bfb774e3..497285cbc93 100644--- a/modules/meeting/app/components/meeting_agenda_items/list_component.html.erb+++ b/modules/meeting/app/components/meeting_agenda_items/list_component.html.erb@@ -3,7 +3,7 @@# The borderBox needs to be `position: relative` because of bug #49853# (The action menu items float somewhere on the page as soon as you have to scroll the Box in Firefox)flex_layout do |flex|- flex.with_row do+ flex.with_row(classes: 'dragula-container', data: { 'allowed-drop-type': 'section' }.merge(drop_target_config) ) dofirst_and_last = [@meeting.sections.first, @meeting.sections.last]render(MeetingSections::ShowComponent.with_collection(diff --git a/modules/meeting/app/components/meeting_agenda_items/list_component.rb b/modules/meeting/app/components/meeting_agenda_items/list_component.rbindex e5b549b5e37..1a6ded0c0f7 100644--- a/modules/meeting/app/components/meeting_agenda_items/list_component.rb+++ b/modules/meeting/app/components/meeting_agenda_items/list_component.rb@@ -44,18 +44,16 @@ module MeetingAgendaItemsdef wrapper_data_attributes{- controller: "meeting-agenda-item-drag-and-drop",- "application-target": "dynamic",- "target-tag": "ul"+ controller: "generic-drag-and-drop",+ "application-target": "dynamic"}end- # def insert_target_modified?- # true- # end-- # def insert_target_modifier_id- # "meeting-agenda-items-new-item"- # end+ def drop_target_config+ {+ "is-drag-and-drop-target": true,+ "target-allowed-drag-type": "section" # the type of dragged items which are allowed to be dropped in this target+ }+ endendenddiff --git a/modules/meeting/app/components/meeting_sections/show_component.html.erb b/modules/meeting/app/components/meeting_sections/show_component.html.erbindex bdc70ca49f1..45a7315ef69 100644--- a/modules/meeting/app/components/meeting_sections/show_component.html.erb+++ b/modules/meeting/app/components/meeting_sections/show_component.html.erb@@ -1,5 +1,5 @@<%=- component_wrapper(class: "op-meeting-section-container", data: { test_selector: "meeting-section-container-#{@meeting_section.id}" }) do+ component_wrapper(class: "op-meeting-section-container", data: { test_selector: "meeting-section-container-#{@meeting_section.id}" }.merge(draggable_item_config)) dounless hide_section?render(Primer::Beta::BorderBox.new(mt: top_margin, data: drag_and_drop_target_config)) do |component|if render_section_wrapper?diff --git a/modules/meeting/app/components/meeting_sections/show_component.rb b/modules/meeting/app/components/meeting_sections/show_component.rbindex 2fa29e9e9bd..d625d060f34 100644--- a/modules/meeting/app/components/meeting_sections/show_component.rb+++ b/modules/meeting/app/components/meeting_sections/show_component.rb@@ -71,12 +71,20 @@ module MeetingSectionsendend+ def draggable_item_config+ {+ "draggable-id": @meeting_section.id,+ "draggable-type": "section",+ "drop-url": drop_meeting_section_path(@meeting, @meeting_section)+ }+ end+def drag_and_drop_target_config{"is-drag-and-drop-target": true,"target-container-accessor": ".Box > ul", # the accessor of the container that contains the drag and drop items"target-id": @meeting_section.id, # the id of the target- "target-allowed-drag-type": "custom-field" # the type of dragged items which are allowed to be dropped in this target+ "target-allowed-drag-type": "agenda-item" # the type of dragged items which are allowed to be dropped in this target}enddiff --git a/modules/meeting/app/contracts/meeting_sections/base_contract.rb b/modules/meeting/app/contracts/meeting_sections/base_contract.rbindex ff89265cabe..22d37b633d8 100644--- a/modules/meeting/app/contracts/meeting_sections/base_contract.rb+++ b/modules/meeting/app/contracts/meeting_sections/base_contract.rb@@ -35,6 +35,8 @@ module MeetingSectionsendattribute :meeting+attribute :name+ attribute :positionendenddiff --git a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb b/modules/meeting/app/controllers/meeting_agenda_items_controller.rbindex 3523cdc560b..4a89739eeec 100644--- a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb+++ b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb@@ -150,13 +150,15 @@ class MeetingAgendaItemsController < ApplicationControllerenddef drop- call = ::MeetingAgendaItems::UpdateService- .new(user: current_user, model: @meeting_agenda_item)- .call(position: params[:position].to_i)+ call = ::MeetingAgendaItems::DropService.new(+ user: current_user, meeting_agenda_item: @meeting_agenda_item+ ).call(+ target_id: params[:target_id],+ position: params[:position]+ )if call.success?- update_show_items_via_turbo_stream- update_header_component_via_turbo_stream+ update_all_via_turbo_stream # TODO: more specific UI updateelsegeneric_call_failure_response(call)enddiff --git a/modules/meeting/app/controllers/meeting_sections_controller.rb b/modules/meeting/app/controllers/meeting_sections_controller.rbindex 71c3c16a7f8..ec46f6c7341 100644--- a/modules/meeting/app/controllers/meeting_sections_controller.rb+++ b/modules/meeting/app/controllers/meeting_sections_controller.rb@@ -135,13 +135,14 @@ class MeetingSectionsController < ApplicationControllerenddef drop- call = ::MeetingAgendaItems::UpdateService+ call = ::MeetingSections::UpdateService.new(user: current_user, model: @meeting_section).call(position: params[:position].to_i)+ p call.errors+if call.success?- update_show_items_via_turbo_stream- update_header_component_via_turbo_stream+ update_all_via_turbo_streamelsegeneric_call_failure_response(call)end@@ -150,7 +151,7 @@ class MeetingSectionsController < ApplicationControllerenddef move- call = ::MeetingAgendaItems::UpdateService+ call = ::MeetingSections::UpdateService.new(user: current_user, model: @meeting_section).call(move_to: params[:move_to]&.to_sym)diff --git a/modules/meeting/app/services/meeting_agenda_items/drop_service.rb b/modules/meeting/app/services/meeting_agenda_items/drop_service.rbnew file mode 100644index 00000000000..d7f8db2b204--- /dev/null+++ b/modules/meeting/app/services/meeting_agenda_items/drop_service.rb@@ -0,0 +1,93 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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.+#++++module MeetingAgendaItems+ class DropService < ::BaseServices::BaseCallable+ def initialize(user:, meeting_agenda_item:)+ super()+ @user = user+ @meeting_agenda_item = meeting_agenda_item+ end++ def perform(params)+ service_call = validate_permissions+ service_call = perform_drop(service_call, params) if service_call.success?++ service_call+ end++ def validate_permissions+ if @user.admin?+ ServiceResult.success+ else+ ServiceResult.failure(errors: { base: :error_unauthorized })+ end+ end++ def perform_drop(service_call, params)+ begin+ section_changed, current_section, old_section = check_and_update_section_if_changed(params)+ update_position(params[:position]&.to_i)++ service_call.success = true+ service_call.result = { section_changed:, current_section:, old_section: }+ rescue StandardError => e+ service_call.success = false+ service_call.errors = e.message+ end++ service_call+ end++ private++ def check_and_update_section_if_changed(params)+ current_section = @meeting_agenda_item.meeting_section+ new_section_id = params[:target_id]&.to_i++ if current_section.id != new_section_id+ old_section = current_section+ current_section = update_section(new_section_id)+ return [true, current_section, old_section]+ end++ [false, current_section, nil]+ end++ def update_section(new_section_id)+ current_section = MeetingSection.find(new_section_id)+ @meeting_agenda_item.remove_from_list+ @meeting_agenda_item.update(meeting_section: current_section)+ current_section+ end++ def update_position(new_position)+ @meeting_agenda_item.insert_at(new_position)+ end+ end+end