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
Spice things up with Hotwire ;)
Aaron Contrerasc15c2e5ba64c
diff --git a/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts b/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.tsindex 43ad1ec3de4..0374a7fc805 100644--- a/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts+++ b/frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts@@ -29,25 +29,40 @@*/import { ApplicationController } from 'stimulus-use';+import { FrameElement } from '@hotwired/turbo';export default class RefreshOnFormChangesController extends ApplicationController {static targets = ['form',+ 'turboFrame',];static values = {refreshUrl: String,+ turboRefreshUrl: String,};declare readonly formTarget:HTMLFormElement;+ declare readonly turboFrameTarget:FrameElement;+ declare readonly hasTurboFrameTarget:boolean;declare refreshUrlValue:string;+ declare turboRefreshUrlValue:string;triggerReload():void {+ window.location.href = `${this.refreshUrlValue}?${this.getSerializedFormData()}`;+ }++ triggerTurboReload():void {+ if (this.hasTurboFrameTarget) {+ this.turboFrameTarget.src = `${this.turboRefreshUrlValue}?${this.getSerializedFormData()}`;+ }+ }++ private getSerializedFormData():string {// without the cast to undefined, the URLSearchParams constructor will// not accept the FormData object.const formData = new FormData(this.formTarget) as unknown as undefined;- const serializedFormData = new URLSearchParams(formData).toString();- window.location.href = `${this.refreshUrlValue}?${serializedFormData}`;+ return new URLSearchParams(formData).toString();}}diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rbindex be5a1262a65..d5039829952 100644--- a/modules/meeting/app/controllers/meetings_controller.rb+++ b/modules/meeting/app/controllers/meetings_controller.rb@@ -28,11 +28,11 @@class MeetingsController < ApplicationControlleraround_action :set_time_zone- 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 :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 :convert_params, only: %i[create update]- before_action :authorize, except: %i[index new]+ before_action :authorize, except: %i[index new participants_section]before_action :authorize_global, only: %i[index new]helper :watchers@@ -83,6 +83,10 @@ class MeetingsController < ApplicationController:meetingsend+ def participants_section+ render layout: false+ end+def copyparams[:copied_from_meeting_id] = @meeting.idparams[:copied_meeting_agenda_text] = @meeting.agenda.text if @meeting.agenda.present?diff --git a/modules/meeting/app/helpers/meetings_helper.rb b/modules/meeting/app/helpers/meetings_helper.rbindex 986ff3f1ddf..69a7f88ca28 100644--- a/modules/meeting/app/helpers/meetings_helper.rb+++ b/modules/meeting/app/helpers/meetings_helper.rb@@ -78,11 +78,7 @@ module MeetingsHelperenddef new_form_refresh_url- if global_create_context?- new_meeting_path- else- new_project_meeting_path(@project)- end+ participants_section_meetings_pathenddef options_for_project_selectiondiff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rbindex 884979fa0f1..0f2cc1b5570 100644--- a/modules/meeting/app/models/meeting.rb+++ b/modules/meeting/app/models/meeting.rb@@ -72,7 +72,7 @@ class Meeting < ApplicationRecordaccepts_nested_attributes_for :participants, allow_destroy: true- validates_presence_of :title, :duration+ validates_presence_of :title, :project_id, :duration# We only save start_time as an aggregated value of start_date and hour,# but still need start_date and _hour for validation purposesdiff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erbindex 7fc6ab65e78..9d949387a88 100644--- a/modules/meeting/app/views/meetings/_form.html.erb+++ b/modules/meeting/app/views/meetings/_form.html.erb@@ -47,7 +47,7 @@ See COPYRIGHT and LICENSE files for more details.'application-target': 'dynamic',controller: 'select-field-with-prompt',action: 'change->select-field-with-prompt#togglePromptStyling ' \- 'change->refresh-on-form-changes#triggerReload'+ 'change->refresh-on-form-changes#triggerTurboReload'} %></div><% end %>@@ -103,49 +103,10 @@ See COPYRIGHT and LICENSE files for more details.</div></div>- <% if @project %>- <div class="form--field">- <label class="form--label"><%=Meeting.human_attribute_name(:participants) %></label>- <div class="form--field-container">- <table class="form--matrix">- <thead>- <tr class="form--matrix-header-row">- <th class="form--matrix-header-cell"><%= Meeting.human_attribute_name(:name) %></th>- <th class="form--matrix-header-cell"><%= Meeting.human_attribute_name(:participants_invited) %></th>- <th class="form--matrix-header-cell"><%= Meeting.human_attribute_name(:participants_attended) %></th>- </tr>- </thead>- <tbody>- <% @meeting.all_changeable_participants.sort.each do |user| -%>- <%= hidden_field_tag "meeting[participants_attributes][][user_id]", user.id %>- <tr class="form--matrix-row">- <td class="form--matrix-cell"><%=h user %></td>- <% if @meeting.participants.present? && participant = @meeting.participants.detect{|p| p.user_id == user.id} -%>- <%= hidden_field_tag "meeting[participants_attributes][][id]", participant.id %>- <td class="form--matrix-checkbox-cell">- <%= label_tag "checkbox_invited_#{user.id}", user.name + " " + t(:description_invite), :class => "hidden-for-sighted" %>- <%= styled_check_box_tag "meeting[participants_attributes][][invited]", 1, participant.invited?, :id => "checkbox_invited_#{user.id}" %>- </td>- <td class="form--matrix-checkbox-cell">- <%= label_tag "checkbox_attended_#{user.id}", user.name + " " + t(:description_attended), :class => "hidden-for-sighted" %>- <%= styled_check_box_tag "meeting[participants_attributes][][attended]", 1, participant.attended?, :id => "checkbox_attended_#{user.id}" %>- </td>- <% else -%>- <td class="form--matrix-checkbox-cell">- <%= label_tag "checkbox_invited_#{user.id}", user.name + " " + t(:description_invite), :class => "hidden-for-sighted" %>- <%= styled_check_box_tag "meeting[participants_attributes][][invited]", value = "1", checked = false, :id => "checkbox_invited_#{user.id}" %>- </td>- <td class="form--matrix-checkbox-cell">- <%= label_tag "checkbox_attended_#{user.id}", user.name + " " + t(:description_attended), :class => "hidden-for-sighted" %>- <%= styled_check_box_tag "meeting[participants_attributes][][attended]", value = "1", checked = false, :id => "checkbox_attended_#{user.id}" %>- </td>- <% end -%>- </tr>- <% end -%>- </tbody>- </table>- </div>- </div>+ <%= turbo_frame_tag "participants_section",+ src: new_form_refresh_url,+ data: { refresh_on_form_changes_target: 'turboFrame' },+ loading: :lazy do %><% end %><%= hidden_field_tag "copied_from_meeting_id", params[:copied_from_meeting_id] if params[:copied_from_meeting_id].present? %>diff --git a/modules/meeting/app/views/meetings/new.html.erb b/modules/meeting/app/views/meetings/new.html.erbindex 755498e2fab..48403b36920 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-refresh-url-value': new_form_refresh_url }} do |f| -%>+ 'refresh-on-form-changes-turbo-refresh-url-value': new_form_refresh_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/participants_section.html.erb b/modules/meeting/app/views/meetings/participants_section.html.erbnew file mode 100644index 00000000000..dc9ba49c208--- /dev/null+++ b/modules/meeting/app/views/meetings/participants_section.html.erb@@ -0,0 +1,74 @@+<%#-- 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_frame_tag "participants_section" do %>+ <% if @project %>+ <div class="form--field">+ <label class="form--label"><%=Meeting.human_attribute_name(:participants) %></label>+ <div class="form--field-container">+ <table class="form--matrix">+ <thead>+ <tr class="form--matrix-header-row">+ <th class="form--matrix-header-cell"><%= Meeting.human_attribute_name(:name) %></th>+ <th class="form--matrix-header-cell"><%= Meeting.human_attribute_name(:participants_invited) %></th>+ <th class="form--matrix-header-cell"><%= Meeting.human_attribute_name(:participants_attended) %></th>+ </tr>+ </thead>+ <tbody>+ <% @meeting.all_changeable_participants.sort.each do |user| -%>+ <%= hidden_field_tag "meeting[participants_attributes][][user_id]", user.id %>+ <tr class="form--matrix-row">+ <td class="form--matrix-cell"><%=h user %></td>+ <% if @meeting.participants.present? && participant = @meeting.participants.detect{|p| p.user_id == user.id} -%>+ <%= hidden_field_tag "meeting[participants_attributes][][id]", participant.id %>+ <td class="form--matrix-checkbox-cell">+ <%= label_tag "checkbox_invited_#{user.id}", user.name + " " + t(:description_invite), :class => "hidden-for-sighted" %>+ <%= styled_check_box_tag "meeting[participants_attributes][][invited]", 1, participant.invited?, :id => "checkbox_invited_#{user.id}" %>+ </td>+ <td class="form--matrix-checkbox-cell">+ <%= label_tag "checkbox_attended_#{user.id}", user.name + " " + t(:description_attended), :class => "hidden-for-sighted" %>+ <%= styled_check_box_tag "meeting[participants_attributes][][attended]", 1, participant.attended?, :id => "checkbox_attended_#{user.id}" %>+ </td>+ <% else -%>+ <td class="form--matrix-checkbox-cell">+ <%= label_tag "checkbox_invited_#{user.id}", user.name + " " + t(:description_invite), :class => "hidden-for-sighted" %>+ <%= styled_check_box_tag "meeting[participants_attributes][][invited]", value = "1", checked = false, :id => "checkbox_invited_#{user.id}" %>+ </td>+ <td class="form--matrix-checkbox-cell">+ <%= label_tag "checkbox_attended_#{user.id}", user.name + " " + t(:description_attended), :class => "hidden-for-sighted" %>+ <%= styled_check_box_tag "meeting[participants_attributes][][attended]", value = "1", checked = false, :id => "checkbox_attended_#{user.id}" %>+ </td>+ <% end -%>+ </tr>+ <% end -%>+ </tbody>+ </table>+ </div>+ </div>+ <% end %>+<% end %>diff --git a/modules/meeting/config/routes.rb b/modules/meeting/config/routes.rbindex 0c743ee9e84..97ef97550ff 100644--- a/modules/meeting/config/routes.rb+++ b/modules/meeting/config/routes.rb@@ -74,5 +74,9 @@ OpenProject::Application.routes.draw do:via => :get,:as => 'tab'end++ collection do+ get :participants_section+ endendenddiff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rbindex 0d85082ea5b..c2135c721b0 100644--- a/modules/meeting/lib/open_project/meeting/engine.rb+++ b/modules/meeting/lib/open_project/meeting/engine.rb@@ -40,7 +40,7 @@ module OpenProject::Meetingproject_module :meetings dopermission :view_meetings, meetings: %i[index show], meeting_agendas: %i[history show diff],meeting_minutes: %i[history show diff]- permission :create_meetings, { meetings: %i[new create copy] }, require: :member+ permission :create_meetings, { meetings: %i[new participants_section create copy] }, require: :memberpermission :edit_meetings, { meetings: %i[edit update] }, require: :memberpermission :delete_meetings, { meetings: [:destroy] }, require: :memberpermission :meetings_send_invite, { meetings: [:icalendar] }, require: :memberdiff --git a/modules/meeting/spec/controllers/meetings_controller_spec.rb b/modules/meeting/spec/controllers/meetings_controller_spec.rbindex ec5708838fb..8173a5a4896 100644--- a/modules/meeting/spec/controllers/meetings_controller_spec.rb+++ b/modules/meeting/spec/controllers/meetings_controller_spec.rb@@ -117,6 +117,27 @@ RSpec.describe MeetingsController doendend+ 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++ 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 }+ end+ end+describe 'edit' dolet(:meeting) { create(:meeting, project:) }