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

Clean up implementation and use with_item_group in submenu

Mir Bhatiabb40ef2b7ae7
diff --git a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb
index fa08a8aa01a..5818042deb1 100644
--- a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb
+++ b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb
@@ -75,28 +75,24 @@
add_outcome_action_item(menu) if add_outcome_action?
end
- with_item_group(menu) do
- if editable?
- menu.with_sub_menu_item(label: "Move") do |submenu|
- unless first? && last?
- move_actions(submenu)
- end
+ if editable?
+ with_item_group(menu) do
+ menu.with_sub_menu_item(label: I18n.t("label_agenda_item_move")) do |submenu|
+ submenu.with_leading_visual_icon(icon: :"op-arrow-in")
+ with_item_group(submenu) { move_actions(submenu) } unless first? && last?
- submenu.with_divider if move_to_different_section_or_meeting_action_added? && !(first? && last?)
-
- if !in_template? || in_backlog?
- if in_backlog?
- move_to_current_meeting_action_item(submenu)
- else
- move_to_backlog_action_item(submenu)
+ with_item_group(submenu) do
+ if !in_template? || in_backlog?
+ if in_backlog?
+ move_to_current_meeting_action_item(submenu)
+ else
+ move_to_backlog_action_item(submenu)
+ end
+ move_to_section_action_item(submenu)
end
- move_to_section_action_item(submenu)
end
- if move_to_next_meeting_enabled?
- submenu.with_divider
- move_to_next_meeting_action_item(submenu)
- end
+ with_item_group(submenu) { move_to_next_meeting_action_item(submenu) }
end
end
end
diff --git a/modules/meeting/app/components/meeting_agenda_items/move_to_section_dialog_component.html.erb b/modules/meeting/app/components/meeting_agenda_items/move_to_section_dialog_component.html.erb
index a5aae3fa0b8..8fb43504a06 100644
--- a/modules/meeting/app/components/meeting_agenda_items/move_to_section_dialog_component.html.erb
+++ b/modules/meeting/app/components/meeting_agenda_items/move_to_section_dialog_component.html.erb
@@ -31,11 +31,12 @@ See COPYRIGHT and LICENSE files for more details.
render(
Primer::Alpha::Dialog.new(
title: "Move to section",
- id: "move-to-section-dialog"
+ id: "move-to-section-dialog",
+ size: :large
)
) do |dialog|
dialog.with_header(variant: :large)
- dialog.with_body do
+ dialog.with_body(classes: "Overlay-body_autocomplete_height") do
render(
MeetingAgendaItems::MoveToSectionFormComponent.new(
meeting: @meeting,
diff --git a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
index 05fd03b127d..2361d7aa108 100644
--- a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
+++ b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
@@ -38,6 +38,8 @@ class MeetingAgendaItemsController < ApplicationController
before_action :set_agenda_item_type, only: %i[new create]
before_action :set_meeting_agenda_item,
except: %i[new cancel_new create]
+ before_action :set_current_occurrence,
+ only: %i[new cancel_new edit cancel_edit create update destroy drop move move_to_section_dialog]
before_action :authorize
before_action :check_recurring_meeting_param, only: %i[move_to_next_meeting]
before_action :assign_drop_params, only: %i[drop]
@@ -53,33 +55,49 @@ class MeetingAgendaItemsController < ApplicationController
collapsed = false
end
end
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
- render_agenda_item_form_via_turbo_stream(meeting_section:, collapsed:, type: @agenda_item_type, current_occurrence:)
+ render_agenda_item_form_via_turbo_stream(meeting_section:, collapsed:, type: @agenda_item_type,
+ current_occurrence: @current_occurrence)
end
respond_with_turbo_streams
end
def cancel_new
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
if params[:meeting_section_id].present?
meeting_section = MeetingSection.find_by(id: params[:meeting_section_id])
if meeting_section.agenda_items.empty?
if meeting_section.backlog?
collapsed = false
end
- update_section_via_turbo_stream(form_hidden: true, meeting_section:, collapsed:, current_occurrence:)
+ update_section_via_turbo_stream(form_hidden: true, meeting_section:, collapsed:, current_occurrence: @current_occurrence)
end
end
- update_new_component_via_turbo_stream(hidden: true, meeting_section:, current_occurrence:)
+ update_new_component_via_turbo_stream(hidden: true, meeting_section:, current_occurrence: @current_occurrence)
update_new_button_via_turbo_stream(disabled: false) unless meeting_section&.backlog?
respond_with_turbo_streams
end
+ def edit
+ if @meeting_agenda_item.editable?
+ update_item_via_turbo_stream(state: :edit, display_notes_input: params[:display_notes_input],
+ current_occurrence: @current_occurrence)
+ else
+ update_all_via_turbo_stream
+ render_error_flash_message_via_turbo_stream(message: t("text_meeting_not_editable_anymore"))
+ end
+
+ respond_with_turbo_streams
+ end
+
+ def cancel_edit
+ update_item_via_turbo_stream(state: :show, current_occurrence: @current_occurrence)
+
+ respond_with_turbo_streams
+ end
+
def create # rubocop:disable Metrics/AbcSize
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
call = ::MeetingAgendaItems::CreateService
.new(user: current_user)
.call(
@@ -94,18 +112,18 @@ class MeetingAgendaItemsController < ApplicationController
if call.success?
if @meeting_agenda_item.meeting_section.backlog?
update_section_via_turbo_stream(meeting_section: @meeting_agenda_item.meeting_section, collapsed: false,
- current_occurrence:)
+ current_occurrence: @current_occurrence)
else
reset_meeting_from_agenda_item
# enable continue editing
update_header_component_via_turbo_stream
update_sidebar_details_component_via_turbo_stream
- add_item_via_turbo_stream(clear_slate: false, current_occurrence:)
+ add_item_via_turbo_stream(clear_slate: false, current_occurrence: @current_occurrence)
end
else
# show errors
update_new_component_via_turbo_stream(
- hidden: false, meeting_agenda_item: @meeting_agenda_item, type: @agenda_item_type, current_occurrence:
+ hidden: false, meeting_agenda_item: @meeting_agenda_item, type: @agenda_item_type, current_occurrence: @current_occurrence
)
render_base_error_in_flash_message_via_turbo_stream(call.errors)
end
@@ -113,27 +131,7 @@ class MeetingAgendaItemsController < ApplicationController
respond_with_turbo_streams
end
- def edit
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
- if @meeting_agenda_item.editable?
- update_item_via_turbo_stream(state: :edit, display_notes_input: params[:display_notes_input], current_occurrence:)
- else
- update_all_via_turbo_stream
- render_error_flash_message_via_turbo_stream(message: t("text_meeting_not_editable_anymore"))
- end
-
- respond_with_turbo_streams
- end
-
- def cancel_edit
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
- update_item_via_turbo_stream(state: :show, current_occurrence:)
-
- respond_with_turbo_streams
- end
-
def update # rubocop:disable Metrics/AbcSize
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
call = ::MeetingAgendaItems::UpdateService
.new(user: current_user, model: @meeting_agenda_item)
.call(meeting_agenda_item_params)
@@ -144,11 +142,11 @@ class MeetingAgendaItemsController < ApplicationController
update_header_component_via_turbo_stream
update_sidebar_details_component_via_turbo_stream
end
- update_item_via_turbo_stream(current_occurrence:)
+ update_item_via_turbo_stream(current_occurrence: @current_occurrence)
update_section_header_via_turbo_stream(meeting_section: @meeting_agenda_item.meeting_section)
else
# show errors
- update_item_via_turbo_stream(state: :edit, current_occurrence:)
+ update_item_via_turbo_stream(state: :edit, current_occurrence: @current_occurrence)
render_base_error_in_flash_message_via_turbo_stream(call.errors)
end
@@ -156,7 +154,6 @@ class MeetingAgendaItemsController < ApplicationController
end
def destroy # rubocop:disable Metrics/AbcSize
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
section = @meeting_agenda_item.meeting_section
call = ::MeetingAgendaItems::DeleteService
@@ -165,12 +162,12 @@ class MeetingAgendaItemsController < ApplicationController
if call.success?
if section.backlog?
- update_section_via_turbo_stream(meeting_section: section, collapsed: false, current_occurrence:)
+ update_section_via_turbo_stream(meeting_section: section, collapsed: false, current_occurrence: @current_occurrence)
else
reset_meeting_from_agenda_item
update_header_component_via_turbo_stream
update_sidebar_details_component_via_turbo_stream
- remove_item_via_turbo_stream(clear_slate: @meeting.agenda_items.empty?, current_occurrence:)
+ remove_item_via_turbo_stream(clear_slate: @meeting.agenda_items.empty?, current_occurrence: @current_occurrence)
# 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?
@@ -185,30 +182,28 @@ class MeetingAgendaItemsController < ApplicationController
end
def drop
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
meeting_agenda_item_section = @meeting_agenda_item.meeting_section
call = if @target_id.nil?
::MeetingAgendaItems::UpdateService
.new(user: current_user, model: @meeting_agenda_item)
- .call(meeting: current_occurrence, meeting_section: nil)
+ .call(meeting: @current_occurrence, meeting_section: nil)
else
::MeetingAgendaItems::DropService
.new(user: current_user, meeting_agenda_item: @meeting_agenda_item)
.call(target_id: @target_id, position: @position)
end
- handle_agenda_item_update_on_move(call, meeting_agenda_item_section, current_occurrence:)
+ handle_agenda_item_update_on_move(call, meeting_agenda_item_section, current_occurrence: @current_occurrence)
end
def move
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
call = ::MeetingAgendaItems::UpdateService
.new(user: current_user, model: @meeting_agenda_item)
.call(move_to: params[:move_to]&.to_sym)
if call.success?
- move_item_within_section_via_turbo_stream(current_occurrence:)
+ move_item_within_section_via_turbo_stream(current_occurrence: @current_occurrence)
else
generic_call_failure_response(call)
end
@@ -244,7 +239,7 @@ class MeetingAgendaItemsController < ApplicationController
end
def move_to_section_dialog
- meeting = params[:current_occurrence].present? ? Meeting.find(params[:current_occurrence]) : @meeting_agenda_item.meeting
+ meeting = @current_occurrence || @meeting_agenda_item.meeting
respond_with_dialog MeetingAgendaItems::MoveToSectionDialogComponent.new(
agenda_item: @meeting_agenda_item,
@@ -300,6 +295,10 @@ class MeetingAgendaItemsController < ApplicationController
@meeting_agenda_item = MeetingAgendaItem.find(params[:id])
end
+ def set_current_occurrence
+ @current_occurrence = Meeting.find_by(id: params[:current_occurrence])
+ end
+
def meeting_agenda_item_params
params
.require(:meeting_agenda_item)
@@ -340,7 +339,7 @@ class MeetingAgendaItemsController < ApplicationController
def assign_drop_params # rubocop:disable Metrics/AbcSize
@target_id, @position =
if params[:type] == "to_current"
- meeting = Meeting.find_by(id: params[:current_occurrence])
+ meeting = @current_occurrence
section = meeting.sections.reorder(position: :desc).first
[section&.id, section&.last_position]
elsif params[:type] == "to_backlog"
diff --git a/modules/meeting/app/controllers/meeting_sections_controller.rb b/modules/meeting/app/controllers/meeting_sections_controller.rb
index f7a7a48d2e8..e9ae958cf6d 100644
--- a/modules/meeting/app/controllers/meeting_sections_controller.rb
+++ b/modules/meeting/app/controllers/meeting_sections_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -36,8 +37,20 @@ class MeetingSectionsController < ApplicationController
before_action :set_meeting_section,
except: %i[create clear_backlog clear_backlog_dialog]
before_action :set_collapsed_state, only: %i[create cancel_edit destroy]
+ before_action :set_current_occurrence, only: %i[clear_backlog clear_backlog_dialog]
before_action :authorize
+ def edit
+ if @meeting_section.editable?
+ update_section_header_via_turbo_stream(state: :edit)
+ else
+ update_all_via_turbo_stream
+ render_error_flash_message_via_turbo_stream(message: t("text_meeting_not_editable_anymore"))
+ end
+
+ respond_with_turbo_streams
+ end
+
def create # rubocop:disable Metrics/AbcSize
call = ::MeetingSections::CreateService
.new(user: current_user)
@@ -66,17 +79,6 @@ class MeetingSectionsController < ApplicationController
respond_with_turbo_streams
end
- def edit
- if @meeting_section.editable?
- update_section_header_via_turbo_stream(state: :edit)
- else
- update_all_via_turbo_stream
- render_error_flash_message_via_turbo_stream(message: t("text_meeting_not_editable_anymore"))
- end
-
- respond_with_turbo_streams
- end
-
def cancel_edit
if @meeting_section.untitled? && @meeting_section.agenda_items.empty?
# if the section is untitled and no agenda items, we can safely delete it
@@ -179,7 +181,6 @@ class MeetingSectionsController < ApplicationController
end
def clear_backlog
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
errors = []
meeting_section = @meeting.backlog
@meeting.backlog.agenda_items.each do |item|
@@ -190,15 +191,15 @@ class MeetingSectionsController < ApplicationController
errors << call.errors unless call.success?
end
- update_section_via_turbo_stream(collapsed: true, meeting_section:, current_occurrence: current_occurrence)
+ update_section_via_turbo_stream(collapsed: true, meeting_section:, current_occurrence: @current_occurrence)
render_error_flash_message_via_turbo_stream(message: t("text_backlog_clear_error")) if errors.any?
respond_with_turbo_streams
end
def clear_backlog_dialog
- current_occurrence = Meeting.find_by(id: params[:current_occurrence])
- respond_with_dialog MeetingSections::Backlogs::ClearBacklogDialogComponent.new(@meeting, current_occurrence:)
+ respond_with_dialog MeetingSections::Backlogs::ClearBacklogDialogComponent.new(@meeting,
+ current_occurrence: @current_occurrence)
end
private
@@ -222,6 +223,10 @@ class MeetingSectionsController < ApplicationController
@meeting_section = MeetingSection.find(params[:id])
end
+ def set_current_occurrence
+ @current_occurrence = Meeting.find_by(id: params[:current_occurrence])
+ end
+
def set_collapsed_state
@collapsed = ActiveModel::Type::Boolean.new.cast(params[:collapsed])
end
diff --git a/modules/meeting/app/forms/meeting/add_to_section.rb b/modules/meeting/app/forms/meeting/add_to_section.rb
index 251bd22d8a9..4e933f6de8e 100644
--- a/modules/meeting/app/forms/meeting/add_to_section.rb
+++ b/modules/meeting/app/forms/meeting/add_to_section.rb
@@ -34,7 +34,7 @@ class Meeting::AddToSection < ApplicationForm
name: :meeting_section_id,
label: I18n.t("label_add_work_package_to_meeting_section_label"),
caption:,
- input_width: :large,
+ input_width:,
autocomplete_options: {
decorated: true,
defaultData: false,
@@ -70,9 +70,9 @@ class Meeting::AddToSection < ApplicationForm
@wrapper_id.nil? ? "body" : "##{@wrapper_id}"
end
- def items
+ def items # rubocop:disable Metrics/AbcSize
items = []
- items.concat(meeting.sections) unless meeting.blank? || meeting.templated?
+ items.concat(meeting.sections) if meeting.present? && !meeting.templated?
items.concat(@occurrence.sections) if @occurrence.present? && @occurrence != meeting
items.push(meeting.backlog) if meeting.present?
@@ -109,4 +109,8 @@ class Meeting::AddToSection < ApplicationForm
def caption
I18n.t("label_section_selection_caption") if @occurrence.nil?
end
+
+ def input_width
+ @occurrence.present? ? nil : :large
+ end
end