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

Set http statuses for turbo streams. Close dialogs when the submitted form inside succeeds.

Dombi Attilaa0d4d2a52c56
diff --git a/app/controllers/concerns/op_turbo/component_stream.rb b/app/controllers/concerns/op_turbo/component_stream.rb
index 974311eae4b..585c2411c72 100644
--- a/app/controllers/concerns/op_turbo/component_stream.rb
+++ b/app/controllers/concerns/op_turbo/component_stream.rb
@@ -33,7 +33,7 @@ module OpTurbo
def respond_to_with_turbo_streams(&format_block)
respond_to do |format|
format.turbo_stream do
- render turbo_stream: turbo_streams
+ render turbo_stream: turbo_streams, status:
end
format_block.call(format) if block_given?
@@ -41,19 +41,20 @@ module OpTurbo
end
alias_method :respond_with_turbo_streams, :respond_to_with_turbo_streams
- def update_via_turbo_stream(component:)
- modify_via_turbo_stream(component:, action: :update)
+ def update_via_turbo_stream(component:, status: :ok)
+ modify_via_turbo_stream(component:, action: :update, status:)
end
- def replace_via_turbo_stream(component:)
- modify_via_turbo_stream(component:, action: :replace)
+ def replace_via_turbo_stream(component:, status: :ok)
+ modify_via_turbo_stream(component:, action: :replace, status:)
end
- def remove_via_turbo_stream(component:)
- modify_via_turbo_stream(component:, action: :remove)
+ def remove_via_turbo_stream(component:, status: :ok)
+ modify_via_turbo_stream(component:, action: :remove, status:)
end
- def modify_via_turbo_stream(component:, action:)
+ def modify_via_turbo_stream(component:, action:, status:)
+ @status = status
turbo_streams << component.render_as_turbo_stream(
view_context:,
action:
@@ -75,5 +76,9 @@ module OpTurbo
def turbo_streams
@turbo_streams ||= []
end
+
+ def status
+ @status ||= :ok
+ end
end
end
diff --git a/app/helpers/stimulus_helper.rb b/app/helpers/stimulus_helper.rb
index 7b3d726f1e4..524d12b45d5 100644
--- a/app/helpers/stimulus_helper.rb
+++ b/app/helpers/stimulus_helper.rb
@@ -41,4 +41,12 @@ module StimulusHelper
end
# rubocop:enable Rails/HelperInstanceVariable
+
+ def close_dialog_on_success_data
+ {
+ controller: 'form-dialog',
+ 'application-target': 'dynamic',
+ action: 'turbo:submit-end->form-dialog#closeOnSuccess'
+ }
+ end
end
diff --git a/frontend/src/stimulus/controllers/dynamic/form-dialog.controller.ts b/frontend/src/stimulus/controllers/dynamic/form-dialog.controller.ts
new file mode 100644
index 00000000000..89b8117ecd2
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/form-dialog.controller.ts
@@ -0,0 +1,41 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 2023 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.
+ * ++
+ */
+
+import { ModalDialogElement } from '@openproject/primer-view-components/app/components/primer/alpha/modal_dialog';
+import { Controller } from '@hotwired/stimulus';
+
+export default class extends Controller {
+ closeOnSuccess({ detail: { success } }:CustomEvent) {
+ if (success) {
+ const dialog = this.element.closest('modal-dialog') as ModalDialogElement;
+ dialog && dialog.close(true);
+ }
+ }
+}
diff --git a/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erb b/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erb
index 4a44dd61a62..5d40c1862f9 100644
--- a/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erb
+++ b/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erb
@@ -3,7 +3,8 @@
primer_form_with(
model: @meeting,
method: :put,
- url: update_details_meeting_path(@meeting)
+ url: update_details_meeting_path(@meeting),
+ data: helpers.close_dialog_on_success_data
) do |f|
component_collection do |collection|
collection.with_component(Primer::Alpha::Dialog::Body.new) do
@@ -40,9 +41,7 @@
t("button_cancel")
end
- modal_footer.with_component(Primer::ButtonComponent.new(scheme: :primary,
- type: :submit,
- data: { 'submit-dialog-id': "edit-meeting-details-dialog" })) do
+ modal_footer.with_component(Primer::ButtonComponent.new(scheme: :primary, type: :submit)) do
t("button_save")
end
end
diff --git a/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erb b/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erb
index aa926b450b0..87a86d16b15 100644
--- a/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erb
+++ b/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erb
@@ -3,7 +3,8 @@
primer_form_with(
model: @meeting,
method: :put,
- url: update_participants_meeting_path(@meeting)
+ url: update_participants_meeting_path(@meeting),
+ data: helpers.close_dialog_on_success_data
) do |f|
component_collection do |collection|
collection.with_component(Primer::Alpha::Dialog::Body.new(style: "max-height: 460px;", my: 3)) do
@@ -97,9 +98,7 @@
t("button_cancel")
end
- footer.with_component(Primer::ButtonComponent.new(scheme: :primary,
- type: :submit,
- data: { 'submit-dialog-id': "edit-participants-dialog" })) do
+ footer.with_component(Primer::ButtonComponent.new(scheme: :primary, type: :submit)) do
t("button_save")
end
end
diff --git a/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb b/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb
index 95ed5abe88e..ed25d639578 100644
--- a/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb
+++ b/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb
@@ -4,7 +4,8 @@
primer_form_with(
model: @meeting_agenda_item,
method: :post,
- url: work_package_meeting_agenda_items_path(@work_package)
+ url: work_package_meeting_agenda_items_path(@work_package),
+ data: helpers.close_dialog_on_success_data
) do |f|
component_collection do |collection|
collection.with_component(Primer::Alpha::Dialog::Body.new(test_selector: 'op-add-work-package-to-meeting-dialog-body')) do
@@ -31,9 +32,7 @@
)) do
t("button_cancel")
end
- collection1.with_component(Primer::ButtonComponent.new(scheme: :primary,
- type: :submit,
- data: { 'submit-dialog-id': "add-work-package-to-meeting-dialog" })) do
+ collection1.with_component(Primer::ButtonComponent.new(scheme: :primary, type: :submit)) do
t("button_save")
end
end
diff --git a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb
index e37741c1328..0172a2fb9a5 100644
--- a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb
+++ b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb
@@ -64,11 +64,12 @@ module Meetings
)
end
- def update_sidebar_details_form_component_via_turbo_stream(meeting: @meeting)
+ def update_sidebar_details_form_component_via_turbo_stream(meeting: @meeting, status: :bad_request)
update_via_turbo_stream(
component: Meetings::Sidebar::DetailsFormComponent.new(
meeting:
- )
+ ),
+ status:
)
end
@@ -84,7 +85,8 @@ module Meetings
update_via_turbo_stream(
component: Meetings::Sidebar::ParticipantsFormComponent.new(
meeting:
- )
+ ),
+ status: :bad_request
)
end
@@ -103,7 +105,8 @@ module Meetings
meeting:,
meeting_agenda_item:,
type:
- )
+ ),
+ status: @meeting.errors.empty? ? :ok : :bad_request
)
end