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
Add callback to auto destroy default sections
Mir Bhatia91a57c15032a
diff --git a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rbindex 9f29330ed80..71818bedb9b 100644--- a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb+++ b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb@@ -295,7 +295,12 @@ module Meetingsupdate_section_header_via_turbo_stream(meeting_section: old_section)if old_section.agenda_items.empty?- update_section_via_turbo_stream(meeting_section: old_section)+ if old_section.title.blank?+ # Special case when the only item is being moved out of current meeting+ update_list_via_turbo_stream+ else+ update_section_via_turbo_stream(meeting_section: old_section)+ endelseupdate_show_items_of_section_via_turbo_stream(meeting_section: old_section)enddiff --git a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb b/modules/meeting/app/controllers/meeting_agenda_items_controller.rbindex d235decaf53..390c53767d0 100644--- a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb+++ b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb@@ -166,7 +166,11 @@ class MeetingAgendaItemsController < ApplicationControllerupdate_header_component_via_turbo_streamupdate_sidebar_details_component_via_turbo_streamremove_item_via_turbo_stream(clear_slate: @meeting.agenda_items.empty?)- update_section_header_via_turbo_stream(meeting_section: section) if section&.reload.present?++ # If section is deleted via an after_destroy/after_update action, it needs to be handled separately+ if MeetingSection.exists?(section.id) && section&.reload.present?+ update_section_header_via_turbo_stream(meeting_section: section)+ endendelsegeneric_call_failure_response(call)diff --git a/modules/meeting/app/models/meeting_agenda_item.rb b/modules/meeting/app/models/meeting_agenda_item.rbindex 4b6a24fc0b7..72f79a07cc0 100644--- a/modules/meeting/app/models/meeting_agenda_item.rb+++ b/modules/meeting/app/models/meeting_agenda_item.rb@@ -67,14 +67,14 @@ class MeetingAgendaItem < ApplicationRecordallow_nil: truebefore_validation :add_to_latest_meeting_section-after_create :trigger_meeting_agenda_item_time_slots_calculationafter_save :trigger_meeting_agenda_item_time_slots_calculation, if: Proc.new { |item|item.duration_in_minutes_previously_changed? || item.position_previously_changed?}before_save :update_meeting_to_match_section+ after_update :delete_default_section_if_last_item_moved, if: :saved_change_to_meeting_section_id?after_destroy :trigger_meeting_agenda_item_time_slots_calculation- # after_destroy :delete_meeting_section_if_empty+ after_destroy :delete_default_section_if_last_item_deleteddef add_to_latest_meeting_sectionreturn if meeting.nil?@@ -90,6 +90,27 @@ class MeetingAgendaItem < ApplicationRecordendend+ def delete_default_section_if_last_item_deleted+ return if meeting_section.nil? || meeting.sections.count > 1 || meeting_section.backlog?++ check_and_destroy(meeting_section)+ end++ def delete_default_section_if_last_item_moved+ old_section_id = saved_change_to_meeting_section_id.first+ old_section = MeetingSection.find_by(id: old_section_id)+ return if old_section.nil? || old_section.backlog?++ check_and_destroy(old_section)+ end++ def check_and_destroy(section)+ # Only destroy the auto created default section, discernible via the blank title+ if section.agenda_items.empty? && section.title.blank?+ section.destroy+ end+ end+def update_meeting_to_match_section# TODO - see #63561self.meeting = meeting_section.meeting@@ -99,14 +120,6 @@ class MeetingAgendaItem < ApplicationRecordmeeting.calculate_agenda_item_time_slotsend- # def delete_meeting_section_if_empty- # # we need to delete the last existing section if the last meeting agenda item is deleted- # # as we don't render the section (including the section menu) if only one section exists- # # thus the section would silently exist in the database when the very last agenda item was deleted- # # which makes UI rendering inconsistent- # meeting_section.destroy if meeting_section.agenda_items.empty? && meeting.sections.count == 1- # end-def linked_work_package?item_type == "work_package" && work_package.present?enddiff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rbindex bda4b800d20..06039fe6510 100644--- a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb@@ -146,6 +146,7 @@ RSpec.describe "Meetings CRUD",find_field("Title").send_keys :escapeendshow_page.expect_item_edit_form(first, visible: false)+# Can removeshow_page.remove_agenda_item firstshow_page.assert_agenda_order! "Updated title", "Second"@@ -400,13 +401,15 @@ RSpec.describe "Meetings CRUD",show_page.add_section doclick_on "Save"expect(page).to have_text "Title can't be blank"+ click_on "Cancel"end# remove the first sectionshow_page.remove_section first_sectionshow_page.expect_no_section(title: "Updated first section title")- # now the meeting completely empty again+ # now the meeting is completely empty again+ show_page.expect_blankslate# add an item to the meetingshow_page.add_agenda_item do@@ -432,13 +435,14 @@ RSpec.describe "Meetings CRUD",show_page.remove_section second_section## the last existing section is not explicitly rendered as a section as no name was specified for this section- ## -> back to "no section mode"+ ## it goes back to "no section mode"show_page.expect_no_section(title: "Second section")show_page.expect_no_section(title: "Untitled section")- # TBD: remove the agenda item again, the untitled section is not rendered explicitly and will not be removed+ # removing the last agenda item will automatically remove the hidden first section as wellfirst_item = MeetingAgendaItem.find_by!(title: "First item without explicit section")show_page.remove_agenda_item(first_item)+ show_page.expect_blankslate# add a second section againshow_page.add_section do@@ -446,8 +450,8 @@ RSpec.describe "Meetings CRUD",click_on "Save"end- ## the first section without a name is now again explicitly rendered as "Untitled"- show_page.expect_section(title: "Untitled section")+ ## as there is no agenda item, the first section is not automatically created and thus+ ## there is only the explicitly created sectionshow_page.expect_section(title: "Second section")second_section = MeetingSection.find_by!(title: "Second section")@@ -460,21 +464,9 @@ RSpec.describe "Meetings CRUD",show_page.expect_agenda_item_in_section title: "First item", section: second_section- first_section = meeting.sections.first-- # add an item to the first section explicitly- show_page.add_agenda_item_to_section(section: first_section) do- fill_in "Title", with: "Second item"- fill_in "min", with: "30"- end-- show_page.expect_agenda_item_in_section title: "Second item", section: first_section-- # duration per section is shown- show_page.expect_section_duration(section: first_section, duration_text: "30 min")+ # duration for the section is shownshow_page.expect_section_duration(section: second_section, duration_text: "25 min")- item_in_first_section = MeetingAgendaItem.find_by!(title: "Second item")item_in_second_section = MeetingAgendaItem.find_by!(title: "First item")show_page.edit_agenda_item(item_in_second_section) do@@ -485,19 +477,15 @@ RSpec.describe "Meetings CRUD",# duration gets updatedshow_page.expect_section_duration(section: second_section, duration_text: "15 min")- # deleting a section with agenda items is not possible+ # deleting a section with agenda items is possible with a confirmationaccept_confirm doshow_page.select_section_action(second_section, "Delete")end- # only untitled section is left -> will not be rendered explicitly as section- show_page.expect_no_section(title: "Untitled section")- show_page.expect_no_section(title: "Second section")-expect { item_in_second_section.reload }.to raise_error(ActiveRecord::RecordNotFound)- # the agenda items of the "untitled" section are still visible in "no-section mode"- show_page.expect_agenda_item(title: item_in_first_section.title)+ # no sections are left, and so the blankslate will be rendered+ show_page.expect_blankslateendendend