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

simplified and refactored section naming approach as discussed with @oliverguenther

Jonas Jabariaccd3581f748
diff --git a/modules/meeting/app/components/meeting_sections/show_component.html.erb b/modules/meeting/app/components/meeting_sections/show_component.html.erb
index 4fe0a73f24f..ac0e581d780 100644
--- a/modules/meeting/app/components/meeting_sections/show_component.html.erb
+++ b/modules/meeting/app/components/meeting_sections/show_component.html.erb
@@ -3,7 +3,7 @@
render(Primer::Beta::BorderBox.new(mt: 3, data: drag_and_drop_target_config)) do |component|
if render_section_wrapper?
component.with_header(font_weight: :bold, pl: 0) do
- render(MeetingSections::HeaderComponent.new(meeting_section: @meeting_section))
+ render(MeetingSections::HeaderComponent.new(meeting_section: @meeting_section, state: @state))
end
end
if render_new_button_in_section?
diff --git a/modules/meeting/app/components/meeting_sections/show_component.rb b/modules/meeting/app/components/meeting_sections/show_component.rb
index 6cef52287b4..eb1bc55b5a6 100644
--- a/modules/meeting/app/components/meeting_sections/show_component.rb
+++ b/modules/meeting/app/components/meeting_sections/show_component.rb
@@ -34,7 +34,8 @@ module MeetingSections
with_collection_parameter :meeting_section
- def initialize(meeting_section:, first_and_last: [], form_hidden: true, form_type: :simple, insert_target_modified: true)
+ def initialize(meeting_section:, first_and_last: [], form_hidden: true, form_type: :simple, insert_target_modified: true,
+ force_wrapper: false, state: :show)
super
@meeting = meeting_section.meeting
@@ -44,6 +45,8 @@ module MeetingSections
@form_hidden = form_hidden
@form_type = form_type
@insert_target_modified = insert_target_modified
+ @force_wrapper = force_wrapper
+ @state = state
end
private
@@ -65,8 +68,7 @@ module MeetingSections
end
def render_section_wrapper?
- # true
- !@meeting_section.untitled? || @meeting.sections.count > 1
+ @force_wrapper || !@meeting_section.untitled? || @meeting.sections.count > 1
end
def render_new_button_in_section?
diff --git a/modules/meeting/app/contracts/meeting_sections/create_contract.rb b/modules/meeting/app/contracts/meeting_sections/create_contract.rb
index f0b6794cf94..93d5f8eb2a3 100644
--- a/modules/meeting/app/contracts/meeting_sections/create_contract.rb
+++ b/modules/meeting/app/contracts/meeting_sections/create_contract.rb
@@ -28,13 +28,16 @@
module MeetingSections
class CreateContract < BaseContract
+ # Note:
+ # the CreateContract is currently only called internally in the create action which substitutes the new action
+ # of the controller. The contract is not used in the context of a form.
+ # Only the UpdateContract is used alongside a user facing form.
+ # Thus we're not validating for title presence here, which enables us to create a section without a title which is required for
+ # the current UX implementation
+
validate :user_allowed_to_add,
:validate_meeting_existence
- # We allow an empty title to mark an untitled/implicit section
- # but users should not be able to create it with an empty title
- validates :title, presence: true
-
def self.assignable_meetings(user)
StructuredMeeting
.open
diff --git a/modules/meeting/app/contracts/meeting_sections/move_contract.rb b/modules/meeting/app/contracts/meeting_sections/move_contract.rb
new file mode 100644
index 00000000000..2a1259ec1d9
--- /dev/null
+++ b/modules/meeting/app/contracts/meeting_sections/move_contract.rb
@@ -0,0 +1,48 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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.
+#++
+
+module MeetingSections
+ class MoveContract < BaseContract
+ validate :user_allowed_to_edit
+
+ # We allow an empty title internally via create to mark an untitled/implicit section
+ # Moving/Dragging them needs to be possible as well
+ # this we're not validating the title here in contrast to the UpdateContract
+ # validates :title, presence: true
+
+ # Meeting agenda items can currently be only edited
+ # through the project permission :manage_agendas
+ # When MeetingRole becomes available, agenda items will
+ # be edited through meeting permissions :manage_agendas
+ def user_allowed_to_edit
+ unless user.allowed_in_project?(:manage_agendas, model.project)
+ errors.add :base, :error_unauthorized
+ end
+ end
+ end
+end
diff --git a/modules/meeting/app/contracts/meeting_sections/update_contract.rb b/modules/meeting/app/contracts/meeting_sections/update_contract.rb
index a900e4c624d..f01ca9887b5 100644
--- a/modules/meeting/app/contracts/meeting_sections/update_contract.rb
+++ b/modules/meeting/app/contracts/meeting_sections/update_contract.rb
@@ -30,6 +30,10 @@ module MeetingSections
class UpdateContract < BaseContract
validate :user_allowed_to_edit
+ # We allow an empty title internally via create to mark an untitled/implicit section
+ # but users should not be able to update it with an empty title through this contract
+ validates :title, presence: true
+
# Meeting agenda items can currently be only edited
# through the project permission :manage_agendas
# When MeetingRole becomes available, agenda items will
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 f1ffebcc29e..7557049e5c2 100644
--- a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb
+++ b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb
@@ -326,12 +326,15 @@ module Meetings
)
end
- def update_section_via_turbo_stream(meeting_section: @meeting_section, form_hidden: true, form_type: :simple)
+ def update_section_via_turbo_stream(meeting_section: @meeting_section, form_hidden: true, form_type: :simple,
+ force_wrapper: false, state: :show)
update_via_turbo_stream(
component: MeetingSections::ShowComponent.new(
meeting_section:,
form_type:,
- form_hidden:
+ form_hidden:,
+ force_wrapper:,
+ state:
)
)
end
diff --git a/modules/meeting/app/controllers/meeting_sections_controller.rb b/modules/meeting/app/controllers/meeting_sections_controller.rb
index afd8921b0d6..a57e94c55b6 100644
--- a/modules/meeting/app/controllers/meeting_sections_controller.rb
+++ b/modules/meeting/app/controllers/meeting_sections_controller.rb
@@ -42,8 +42,7 @@ class MeetingSectionsController < ApplicationController
.new(user: current_user)
.call(
{
- meeting_id: @meeting.id,
- title: t("meeting_section.default_title")
+ meeting_id: @meeting.id
}
)
@@ -51,7 +50,8 @@ class MeetingSectionsController < ApplicationController
if call.success?
add_section_via_turbo_stream
- update_section_header_via_turbo_stream(state: :edit)
+ update_section_via_turbo_stream(force_wrapper: true, state: :edit)
+ # update_section_header_via_turbo_stream(state: :edit)
update_new_button_via_turbo_stream(disabled: true)
else
render_base_error_in_flash_message_via_turbo_stream(call.errors)
@@ -72,8 +72,8 @@ class MeetingSectionsController < ApplicationController
end
def cancel_edit
- if @meeting_section.has_default_title? && @meeting_section.agenda_items.empty?
- # if the section has the default title and no agenda items, we can safely delete it
+ if @meeting_section.untitled? && @meeting_section.agenda_items.empty?
+ # if the section is untitled and no agenda items, we can safely delete it
destroy and return
else
update_section_header_via_turbo_stream(state: :show)
@@ -121,7 +121,7 @@ class MeetingSectionsController < ApplicationController
def drop
call = ::MeetingSections::UpdateService
- .new(user: current_user, model: @meeting_section)
+ .new(user: current_user, model: @meeting_section, contract_class: MeetingSections::MoveContract)
.call(position: params[:position].to_i)
if call.success?
@@ -139,7 +139,7 @@ class MeetingSectionsController < ApplicationController
def move
call = ::MeetingSections::UpdateService
- .new(user: current_user, model: @meeting_section)
+ .new(user: current_user, model: @meeting_section, contract_class: MeetingSections::MoveContract)
.call(move_to: params[:move_to]&.to_sym)
if call.success?
diff --git a/modules/meeting/app/forms/meeting_section/title.rb b/modules/meeting/app/forms/meeting_section/title.rb
index bca81cf1936..44b8dc9fcfb 100644
--- a/modules/meeting/app/forms/meeting_section/title.rb
+++ b/modules/meeting/app/forms/meeting_section/title.rb
@@ -30,9 +30,8 @@ class MeetingSection::Title < ApplicationForm
form do |meeting_section_form|
meeting_section_form.text_field(
name: :title,
- placeholder: I18n.t("meeting_section.default_title"),
+ placeholder: Meeting.human_attribute_name(:title),
label: Meeting.human_attribute_name(:title),
- value: init_value(meeting_section_form),
visually_hide_label: true,
required: true,
autofocus: true,
@@ -42,14 +41,4 @@ class MeetingSection::Title < ApplicationForm
}
)
end
-
- private
-
- def init_value(meeting_section_form)
- if meeting_section_form.builder.object.has_default_title? || meeting_section_form.builder.object.untitled?
- "" # will be set to "Untitled" in the model if left empty
- else
- meeting_section_form.builder.object.title
- end
- end
end
diff --git a/modules/meeting/app/models/meeting_section.rb b/modules/meeting/app/models/meeting_section.rb
index 21184bc660f..9e9db7b6bc6 100644
--- a/modules/meeting/app/models/meeting_section.rb
+++ b/modules/meeting/app/models/meeting_section.rb
@@ -46,10 +46,6 @@ class MeetingSection < ApplicationRecord
meeting.calculate_agenda_item_time_slots
end
- def has_default_title?
- title == I18n.t("meeting_section.default_title")
- end
-
def untitled?
title.blank?
end
diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.yml
index f5971fb325f..9361fe97c7c 100644
--- a/modules/meeting/config/locales/en.yml
+++ b/modules/meeting/config/locales/en.yml
@@ -143,8 +143,7 @@ en:
copied: "Copied from Meeting #%{id}"
meeting_section:
- default_title: "New section"
- untitled_title: "Untitled"
+ untitled_title: "Untitled section"
empty_text: "Drag items here or create a new one"
notice_successful_notification: "Notification sent successfully"
diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
index 2710025cf58..fb62aee232f 100644
--- a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
@@ -330,6 +330,8 @@ RSpec.describe "Structured meetings CRUD",
first_section = MeetingSection.find_by!(title: "First section")
+ meeting = first_section.meeting
+
# edit the first section
show_page.edit_section(first_section) do
fill_in "Title", with: "Updated first section title"
@@ -357,22 +359,49 @@ RSpec.describe "Structured meetings CRUD",
show_page.expect_section(title: "Updated first section title")
show_page.expect_no_section(title: "Second section")
- # add a section without a name
+ # add a section without a name is not possible
show_page.add_section do
click_on "Save"
+ expect(page).to have_text "Title can't be blank"
end
- ## "Untitled" is applied automatically as a name
- show_page.expect_section(title: "Updated first section title")
- show_page.expect_section(title: "Untitled")
-
# remove the first section
show_page.remove_section first_section
+ show_page.expect_no_section(title: "Updated first section title")
+
+ # now the meeting completely empty again
+
+ # add an item to the meeting
+ show_page.add_agenda_item do
+ fill_in "Title", with: "First item without explicit section"
+ end
+
+ # the agenda item is wrapped in an "untitled" section, but the section is not explicitly rendered
+ show_page.expect_no_section(title: "Untitled section")
+
+ # add a second section again
+ show_page.add_section do
+ fill_in "Title", with: "Second section"
+ click_on "Save"
+ end
+
+ ## the first section without a name is now explicitly rendered as "Untitled"
+ show_page.expect_section(title: "Untitled section")
+ show_page.expect_section(title: "Second section")
+
+ second_section = MeetingSection.find_by!(title: "Second section")
+
+ # remove the second section
+ show_page.remove_section second_section
## the last existing section is not explicitly rendered as a section as no name was specified for this section
## -> back to "no section mode"
- show_page.expect_no_section(title: "Updated first section title")
- show_page.expect_no_section(title: "Untitled")
+ show_page.expect_no_section(title: "Second section")
+ show_page.expect_no_section(title: "Untitled section")
+
+ # TBD: remove the agenda item again, the untitle section is not rendered explicitly and will not be removed
+ first_item = MeetingAgendaItem.find_by!(title: "First item without explicit section")
+ show_page.remove_agenda_item(first_item)
# add a second section again
show_page.add_section do
@@ -380,8 +409,8 @@ RSpec.describe "Structured meetings CRUD",
click_on "Save"
end
- ## the first section without a name is now explicitly rendered as "Untitled"
- show_page.expect_section(title: "Untitled")
+ ## the first section without a name is now again explicitly rendered as "Untitled"
+ show_page.expect_section(title: "Untitled section")
show_page.expect_section(title: "Second section")
second_section = MeetingSection.find_by!(title: "Second section")
@@ -394,7 +423,7 @@ RSpec.describe "Structured meetings CRUD",
show_page.expect_agenda_item_in_section title: "First item", section: second_section
- first_section = MeetingSection.find_by!(title: "")
+ first_section = meeting.sections.first
# add an item to the first section explicitly
show_page.add_agenda_item_to_section(section: first_section) do
@@ -422,7 +451,7 @@ RSpec.describe "Structured meetings CRUD",
# deleting a section with agenda items is not possible
show_page.select_section_action(second_section, "Delete") # delete is disabled
## -> no effect
- show_page.expect_section(title: "Untitled")
+ show_page.expect_section(title: "Untitled section")
show_page.expect_section(title: "Second section")
show_page.click_on_section_menu(second_section) # close the menu again
@@ -432,7 +461,7 @@ RSpec.describe "Structured meetings CRUD",
show_page.remove_section(second_section) # empty secion gets deleted
# only untitle secion is left -> will not be rendered explicitly as secion
- show_page.expect_no_section(title: "Untitled")
+ show_page.expect_no_section(title: "Untitled section")
show_page.expect_no_section(title: "Second section")
# the agenda items of the "untitled" section are still visible in "no-section mode"