Skip to content

Commit 432db26

Browse files
mrmiroliverguenther
andcommitted
Add section autocompleter and refresh logic
Co-authored-by: Oliver Guenther <o.guenther@openproject.com>
1 parent 8039a21 commit 432db26

File tree

9 files changed

+163
-8
lines changed

9 files changed

+163
-8
lines changed

modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
id: "add-work-package-to-meeting-form",
55
model: @meeting_agenda_item,
66
method: :post,
7-
url: work_package_meeting_agenda_items_path(@work_package)
7+
url: work_package_meeting_agenda_items_path(@work_package),
8+
data: data_attributes
89
) do |f|
910
flex_layout(mb: 3) do |flex|
1011
flex.with_row do
1112
if @base_errors&.any?
1213
render(Primer::Alpha::Banner.new(mb: 3, icon: :stop, scheme: :danger)) { @base_errors.join("\n") }
1314
end
1415
end
15-
flex.with_row do
16+
flex.with_row(mb: 3) do
1617
render(MeetingAgendaItem::MeetingForm.new(f, wrapper_id: "add-work-package-to-meeting-dialog"))
1718
end
19+
flex.with_row do
20+
render(Meeting::AddToSection.new(f, wrapper_id: "add-work-package-to-meeting-dialog"))
21+
end
1822
flex.with_row(mt: 3) do
1923
render(MeetingAgendaItem::Notes.new(f))
2024
end

modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,15 @@ def initialize(work_package:, meeting_agenda_item: nil, base_errors: nil)
4040
@meeting_agenda_item = meeting_agenda_item || MeetingAgendaItem.new(work_package: @work_package)
4141
@base_errors = base_errors
4242
end
43+
44+
private
45+
46+
def data_attributes
47+
{
48+
controller: "refresh-on-form-changes",
49+
"refresh-on-form-changes-target": "form",
50+
"refresh-on-form-changes-turbo-stream-url-value": refresh_form_work_package_meeting_agenda_items_path(@work_package)
51+
}
52+
end
4353
end
4454
end

modules/meeting/app/controllers/work_package_meetings_tab_controller.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def add_work_package_to_meeting # rubocop:disable Metrics/AbcSize
6969
work_package_id: @work_package.id,
7070
presenter_id: current_user.id,
7171
item_type: MeetingAgendaItem::ITEM_TYPES[:work_package],
72-
meeting_section_id: backlog_id
72+
meeting_section_id: params[:meeting_agenda_item][:meeting_section_id]
7373
)
7474
)
7575

@@ -87,6 +87,30 @@ def add_work_package_to_meeting # rubocop:disable Metrics/AbcSize
8787
respond_with_turbo_streams
8888
end
8989

90+
def refresh_form
91+
@meeting_agenda_item = MeetingAgendaItem.new(
92+
meeting: Meeting.find(params[:meeting_agenda_item][:meeting_id]),
93+
notes: params[:meeting_agenda_item][:notes]
94+
)
95+
96+
call = MeetingAgendaItems::SetAttributesService.new(
97+
user: current_user,
98+
model: @meeting_agenda_item,
99+
contract_class: EmptyContract
100+
).call
101+
102+
meeting_agenda_item = call.result
103+
104+
update_via_turbo_stream(
105+
component: WorkPackageMeetingsTab::AddWorkPackageToMeetingFormComponent.new(
106+
work_package: @work_package,
107+
meeting_agenda_item: meeting_agenda_item
108+
)
109+
)
110+
111+
respond_with_turbo_streams
112+
end
113+
90114
private
91115

92116
def set_work_package
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
class Meeting::AddToSection < ApplicationForm
32+
form do |meeting_form|
33+
meeting_form.autocompleter(
34+
name: :meeting_section_id,
35+
label: I18n.t("label_add_work_package_to_meeting_section_label"),
36+
caption: I18n.t("label_section_selection_caption"),
37+
input_width: :large,
38+
autocomplete_options: {
39+
decorated: true,
40+
defaultData: false,
41+
multiple: false,
42+
focus_directly: false,
43+
disabled: meeting.blank?,
44+
placeholder: placeholder_text,
45+
append_to: append_to_container
46+
}
47+
) do |select|
48+
items.each do |item|
49+
select.option(
50+
value: item.id,
51+
label: option_title(item),
52+
selected: preselected_option.present? && item.id == preselected_option[:id]
53+
)
54+
end
55+
end
56+
end
57+
58+
def initialize(wrapper_id: nil)
59+
super()
60+
61+
@wrapper_id = wrapper_id
62+
end
63+
64+
private
65+
66+
delegate :meeting, to: :model
67+
68+
def append_to_container
69+
@wrapper_id.nil? ? "body" : "##{@wrapper_id}"
70+
end
71+
72+
def items
73+
items = []
74+
items.concat(meeting.sections) unless meeting.blank? || any_non_backlog_sections?
75+
items.push(meeting.backlog) if meeting.present?
76+
77+
items
78+
end
79+
80+
def option_title(item)
81+
return I18n.t("meeting_section.untitled_title") if item.title.blank?
82+
return I18n.t("label_series_backlog") if item.backlog? && meeting.recurring?
83+
84+
item.title
85+
end
86+
87+
def preselected_option
88+
return if meeting.blank?
89+
90+
if meeting.recurring?
91+
without_backlog = items.reject(&:backlog?)
92+
item = without_backlog.last
93+
else
94+
item = meeting.backlog
95+
end
96+
97+
item
98+
end
99+
100+
def any_non_backlog_sections?
101+
meeting.sections.none? || (meeting.sections.one? && meeting.sections.first.title.blank?)
102+
end
103+
104+
def placeholder_text
105+
I18n.t("placeholder_section_select_meeting_first") if meeting.blank?
106+
end
107+
end

modules/meeting/app/forms/meeting_agenda_item/meeting_form.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,30 @@ class MeetingAgendaItem::MeetingForm < ApplicationForm
3939
caption: I18n.t("label_meeting_selection_caption"),
4040
autocomplete_options: {
4141
component: "opce-meeting-autocompleter",
42+
hiddenFieldAction: "change->refresh-on-form-changes#triggerTurboStream",
4243
items: meeting_options,
4344
group_by: "group_label",
4445
focus_directly: true,
4546
defaultData: false,
4647
bindLabel: "name",
4748
bindValue: "id",
4849
multiple: false,
49-
append_to: append_to_container
50+
append_to: append_to_container,
51+
model: meeting_options.detect { |option| option[:id] == model.meeting_id },
52+
inputValue: model.meeting_id
5053
}
5154
)
5255
end
5356

5457
def initialize(disabled: false, wrapper_id: nil)
5558
super()
59+
5660
@disabled = disabled
5761
@wrapper_id = wrapper_id
5862
end
5963

64+
private
65+
6066
def meeting_options
6167
meetings = MeetingAgendaItems::CreateContract
6268
.assignable_meetings(User.current)

modules/meeting/app/services/group_meetings_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def group_meetings # rubocop:disable Metrics/AbcSize
8181
groups
8282
end
8383

84-
# Flattens groups into autocompleter options
84+
# Flatten groups into autocompleter options
8585
def build_options
8686
group_meetings.flat_map do |key, meetings|
8787
label = I18n.t("label_meeting_index_#{key}")

modules/meeting/config/locales/en.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,12 @@ en:
602602
text_meeting_not_editable_anymore: "This meeting is not editable anymore."
603603
text_meeting_not_present_anymore: "This meeting was deleted. Please select another meeting."
604604

605-
label_add_work_package_to_meeting_dialog_title: "Add work package to meeting"
605+
label_add_work_package_to_meeting_dialog_title: "Select meeting"
606+
label_add_work_package_to_meeting_section_label: "Add to section"
606607
label_add_work_package_to_meeting_dialog_button: "Add to meeting"
607-
label_meeting_selection_caption: "It's only possible to add this work package to upcoming or ongoing open meetings."
608+
label_meeting_selection_caption: "It is only possible to add this work package to an upcoming or an ongoing meeting."
609+
label_section_selection_caption: "Choose a particular section of the agenda or add it to the backlog."
610+
placeholder_section_select_meeting_first: "Meeting selection is required first"
608611

609612
text_add_work_package_to_meeting_description: "A work package can be added to one or multiple meetings for discussion. Any notes concerning it are also visible here."
610613
text_agenda_item_no_notes: "No notes provided"

modules/meeting/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
collection do
8383
get :dialog, controller: "work_package_meetings_tab", action: :add_work_package_to_meeting_dialog
8484
post :create, controller: "work_package_meetings_tab", action: :add_work_package_to_meeting
85+
get :refresh_form, controller: "work_package_meetings_tab", action: :refresh_form
8586
end
8687
end
8788
end

modules/meeting/lib/open_project/meeting/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Engine < ::Rails::Engine
6767
details_dialog update_details toggle_notifications],
6868
recurring_meetings: %i[edit cancel_edit update update_title details_dialog update_details
6969
notify end_series end_series_dialog],
70-
work_package_meetings_tab: %i[add_work_package_to_meeting_dialog add_work_package_to_meeting],
70+
work_package_meetings_tab: %i[add_work_package_to_meeting_dialog add_work_package_to_meeting refresh_form],
7171
meeting_participants: %i[create destroy mark_all_attended toggle_attendance manage_participants_dialog]
7272
},
7373
permissible_on: :project,

0 commit comments

Comments
 (0)