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

Modify `turbo-frame` approach to use `turbo-stream`s

Aaron Contreras43092828e897
diff --git a/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts b/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts
index 0374a7fc805..50fb8ce8757 100644
--- a/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts
+++ b/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts
@@ -29,34 +29,34 @@
*/
import { ApplicationController } from 'stimulus-use';
-import { FrameElement } from '@hotwired/turbo';
+import { renderStreamMessage } from '@hotwired/turbo';
export default class RefreshOnFormChangesController extends ApplicationController {
static targets = [
'form',
- 'turboFrame',
];
static values = {
refreshUrl: String,
- turboRefreshUrl: String,
+ turboStreamUrl: String,
};
declare readonly formTarget:HTMLFormElement;
- declare readonly turboFrameTarget:FrameElement;
- declare readonly hasTurboFrameTarget:boolean;
declare refreshUrlValue:string;
- declare turboRefreshUrlValue:string;
+ declare turboStreamUrlValue:string;
triggerReload():void {
window.location.href = `${this.refreshUrlValue}?${this.getSerializedFormData()}`;
}
- triggerTurboReload():void {
- if (this.hasTurboFrameTarget) {
- this.turboFrameTarget.src = `${this.turboRefreshUrlValue}?${this.getSerializedFormData()}`;
- }
+ async triggerTurboStream():Promise<void> {
+ await fetch(`${this.turboStreamUrlValue}?${this.getSerializedFormData()}`, {
+ headers: {
+ Accept: 'text/vnd.turbo-stream.html',
+ },
+ }).then((r) => r.text())
+ .then((html) => renderStreamMessage(html));
}
private getSerializedFormData():string {
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index 4b94c4b2f8a..9c6cc41aaca 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -28,11 +28,11 @@
class MeetingsController < ApplicationController
around_action :set_time_zone
- before_action :find_optional_project, only: %i[index new participants_section create]
- before_action :build_meeting, only: %i[new participants_section create]
- before_action :find_meeting, except: %i[index new participants_section create]
+ before_action :find_optional_project, only: %i[index new create]
+ before_action :build_meeting, only: %i[new create]
+ before_action :find_meeting, except: %i[index new create]
before_action :convert_params, only: %i[create update]
- before_action :authorize, except: %i[index new participants_section]
+ before_action :authorize, except: %i[index new]
before_action :authorize_global, only: %i[index new]
helper :watchers
@@ -83,10 +83,6 @@ class MeetingsController < ApplicationController
:meetings
end
- def participants_section
- render layout: false
- end
-
def copy
params[:copied_from_meeting_id] = @meeting.id
params[:copied_meeting_agenda_text] = @meeting.agenda.text if @meeting.agenda.present?
@@ -128,12 +124,6 @@ class MeetingsController < ApplicationController
def build_meeting
@meeting = Meeting.new
- if meeting_params.present?
- convert_params
- @meeting.participants.clear # Start with a clean set of participants
- @meeting.participants_attributes = @converted_params.delete(:participants_attributes)
- @meeting.attributes = @converted_params
- end
@meeting.project = @project
@meeting.author = User.current
end
diff --git a/modules/meeting/app/helpers/meetings_helper.rb b/modules/meeting/app/helpers/meetings_helper.rb
index 844b7ca7327..284976935af 100644
--- a/modules/meeting/app/helpers/meetings_helper.rb
+++ b/modules/meeting/app/helpers/meetings_helper.rb
@@ -77,20 +77,6 @@ module MeetingsHelper
request.path == new_meeting_path
end
- def participants_section_refresh_url
- if global_create_context?
- participants_section_meetings_path
- else
- participants_section_meetings_path(project_id: @project.id)
- end
- end
-
- def participants_section_attributes
- attributes = { data: { refresh_on_form_changes_target: 'turboFrame' } }
- attributes = attributes.merge({ src: participants_section_refresh_url }) unless global_create_context?
- attributes
- end
-
def options_for_project_selection
Project.allowed_to(User.current, :create_meetings)
.filter { _1.module_enabled?('meetings') }
diff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erb
index 53b89352acc..11738e292f3 100644
--- a/modules/meeting/app/views/meetings/_form.html.erb
+++ b/modules/meeting/app/views/meetings/_form.html.erb
@@ -45,7 +45,7 @@ See COPYRIGHT and LICENSE files for more details.
name: 'project_id',
value: @project,
appendTo: 'body',
- hiddenFieldAction: 'change->refresh-on-form-changes#triggerTurboReload',
+ hiddenFieldAction: 'change->refresh-on-form-changes#triggerTurboStream',
},
id: 'project_id',
class: 'form--select-container -wide remote-field--input',
@@ -108,8 +108,7 @@ See COPYRIGHT and LICENSE files for more details.
</div>
</div>
- <%= turbo_frame_tag "participants_section", **participants_section_attributes do %>
- <% end %>
+ <%= render partial: 'meetings/participants_section' %>
<%= hidden_field_tag "copied_from_meeting_id", params[:copied_from_meeting_id] if params[:copied_from_meeting_id].present? %>
<%= hidden_field_tag "copied_meeting_agenda_text", params[:copied_meeting_agenda_text] if params[:copied_meeting_agenda_text].present? %>
diff --git a/modules/meeting/app/views/meetings/participants_section.html.erb b/modules/meeting/app/views/meetings/_participants_section.html.erb
similarity index 98%
rename from modules/meeting/app/views/meetings/participants_section.html.erb
rename to modules/meeting/app/views/meetings/_participants_section.html.erb
index dc9ba49c208..94c77daf95e 100644
--- a/modules/meeting/app/views/meetings/participants_section.html.erb
+++ b/modules/meeting/app/views/meetings/_participants_section.html.erb
@@ -26,7 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= turbo_frame_tag "participants_section" do %>
+
+<div id="participants-section">
<% if @project %>
<div class="form--field">
<label class="form--label"><%=Meeting.human_attribute_name(:participants) %></label>
@@ -71,4 +72,4 @@ See COPYRIGHT and LICENSE files for more details.
</div>
</div>
<% end %>
-<% end %>
+</div>
diff --git a/modules/meeting/app/views/meetings/new.html.erb b/modules/meeting/app/views/meetings/new.html.erb
index 6343a49db75..a11f9539fed 100644
--- a/modules/meeting/app/views/meetings/new.html.erb
+++ b/modules/meeting/app/views/meetings/new.html.erb
@@ -34,7 +34,7 @@ See COPYRIGHT and LICENSE files for more details.
:html => {:id => 'meeting-form',
:data => { :controller => 'refresh-on-form-changes',
'refresh-on-form-changes-target': 'form',
- 'refresh-on-form-changes-turbo-refresh-url-value': participants_section_refresh_url }} do |f| -%>
+ 'refresh-on-form-changes-turbo-stream-url-value': new_meeting_url }} do |f| -%>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= styled_button_tag t(:button_create), class: '-highlight' %>
<%= link_to t(:button_cancel), { :action => 'index', :project_id => @project },
diff --git a/modules/meeting/app/views/meetings/new.turbo_stream.erb b/modules/meeting/app/views/meetings/new.turbo_stream.erb
new file mode 100644
index 00000000000..9d5eea2c213
--- /dev/null
+++ b/modules/meeting/app/views/meetings/new.turbo_stream.erb
@@ -0,0 +1,31 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-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.
+
+++#%>
+
+
+<%= turbo_stream.replace 'participants-section', partial: 'meetings/participants_section' %>
diff --git a/modules/meeting/config/routes.rb b/modules/meeting/config/routes.rb
index 97ef97550ff..0c743ee9e84 100644
--- a/modules/meeting/config/routes.rb
+++ b/modules/meeting/config/routes.rb
@@ -74,9 +74,5 @@ OpenProject::Application.routes.draw do
:via => :get,
:as => 'tab'
end
-
- collection do
- get :participants_section
- end
end
end
diff --git a/modules/meeting/spec/controllers/meetings_controller_spec.rb b/modules/meeting/spec/controllers/meetings_controller_spec.rb
index 3937f468e2c..7a0528ded4b 100644
--- a/modules/meeting/spec/controllers/meetings_controller_spec.rb
+++ b/modules/meeting/spec/controllers/meetings_controller_spec.rb
@@ -95,72 +95,32 @@ RSpec.describe MeetingsController do
allow(Meeting).to receive(:new).and_return(meeting)
end
- describe 'html' do
- context 'when requesting the global page' do
- before do
- get 'new'
- end
-
- it { expect(response).to be_successful }
- it { expect(assigns(:meeting)).to eql meeting }
- end
-
- context 'when requesting the project-scoped page' do
- before do
- get 'new', params: { project_id: project.id }
- end
-
- it { expect(response).to be_successful }
- it { expect(assigns(:meeting)).to eql meeting }
- end
- end
- end
-
- describe 'participants_section' do
- render_views
-
- let(:meeting) { Meeting.new(project:) }
-
- before do
- allow(Project).to receive(:find).and_return(project)
- allow(Meeting).to receive(:new).and_return(meeting)
- end
-
- context 'with a project id' do
- before do
- allow(Project).to receive(:find).and_return(project)
- end
-
- describe 'html' do
- before do
- get :participants_section, params: { project_id: project.id }
- end
-
- it { expect(response).to be_successful }
- it { expect(response).to render_template :participants_section }
- it { expect(assigns(:meeting)).to eql meeting }
- it { expect(assigns(:project)).to eql project }
- end
- end
+ shared_examples_for 'new action' do |response_type:|
+ describe response_type do
+ context 'when requesting the page without a project id' do
+ before do
+ get 'new'
+ end
- context 'without a project id' do
- context 'with a project id' do
- before do
- allow(Project).to receive(:find).and_return(nil)
+ it { expect(response).to be_successful }
+ it { expect(assigns(:meeting)).to eql meeting }
+ it { expect(assigns(:project)).to be_nil }
end
- describe 'html' do
+ context 'when requesting the page with a project id' do
before do
- get :participants_section
+ get 'new', params: { project_id: project.id }
end
it { expect(response).to be_successful }
- it { expect(response).to render_template :participants_section }
it { expect(assigns(:meeting)).to eql meeting }
- it { expect(assigns(:project)).to be_nil }
+ it { expect(assigns(:project)).to eql project }
end
end
end
+
+ it_behaves_like 'new action', response_type: 'html'
+ it_behaves_like 'new action', response_type: 'turbo_stream'
end
describe 'edit' do
diff --git a/modules/meeting/spec/features/meetings_new_spec.rb b/modules/meeting/spec/features/meetings_new_spec.rb
index 0993f4a61e9..b4dfec2115e 100644
--- a/modules/meeting/spec/features/meetings_new_spec.rb
+++ b/modules/meeting/spec/features/meetings_new_spec.rb
@@ -57,7 +57,7 @@ RSpec.describe 'Meetings new', :js do
login_as current_user
end
- context 'with permission to create meetings', with_cuprite: false do
+ context 'when creating a meeting from the global page' do
before do
other_user
project
@@ -73,7 +73,7 @@ RSpec.describe 'Meetings new', :js do
['CET', 'UTC', '', 'Pacific Time (US & Canada)'].each do |zone|
let(:time_zone) { zone }
- it "allows creating a project and handles errors in time zone #{zone}" do
+ it "allows creating a project and handles errors in time zone #{zone}", with_cuprite: false do
index_page.visit!
new_page = index_page.click_create_new
@@ -110,11 +110,10 @@ RSpec.describe 'Meetings new', :js do
context 'as an admin' do
let(:current_user) { admin }
- it 'allows creating meeting in a project without members' do
+ it 'allows creating meeting in a project without members', with_cuprite: false do
index_page.visit!
new_page = index_page.click_create_new
-
new_page.set_title 'Some title'
new_page.set_project project
@@ -140,7 +139,7 @@ RSpec.describe 'Meetings new', :js do
['CET', 'UTC', '', 'Pacific Time (US & Canada)'].each do |zone|
let(:time_zone) { zone }
- it "allows creating a project and handles errors in time zone #{zone}" do
+ it "allows creating a project and handles errors in time zone #{zone}", with_cuprite: false do
index_page.visit!
new_page = index_page.click_create_new