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

Keep collapsed state for move actions

Mir Bhatia55872e847c58
diff --git a/frontend/src/stimulus/controllers/keep-collapsed-state.controller.ts b/frontend/src/stimulus/controllers/keep-collapsed-state.controller.ts
new file mode 100644
index 00000000000..d16b9c0dc9c
--- /dev/null
+++ b/frontend/src/stimulus/controllers/keep-collapsed-state.controller.ts
@@ -0,0 +1,83 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 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 { ApplicationController } from 'stimulus-use';
+import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
+
+export default class KeepCollapsedStateController extends ApplicationController {
+ private turboRequests:TurboRequestsService;
+
+ static targets = ['section'];
+ static values = {
+ collapsed: Boolean,
+ };
+
+ declare collapsedValue:boolean;
+ declare hasCollapsedValue:boolean;
+
+ declare sectionTarget:HTMLElement;
+
+ async connect() {
+ const context = await window.OpenProject.getPluginContext();
+ this.turboRequests = context.services.turboRequests;
+ }
+
+ rememberState() {
+ this.collapsedValue = this.sectionTarget.classList.contains('CollapsibleHeader--collapsed');
+ }
+
+ interceptMoveTo(event:Event):void {
+ event.preventDefault();
+
+ const target = event.currentTarget as HTMLElement;
+ const url = new URL(target.dataset.href!, window.location.origin);
+
+ if (this.hasCollapsedValue) {
+ url.searchParams.append('collapsed', this.collapsedValue.toString());
+ }
+
+ void this
+ .turboRequests
+ .request(
+ url.toString(),
+ {
+ method: 'PUT',
+ headers: {
+ 'X-CSRF-Token': (document.querySelector('meta[name="csrf-token"]') as HTMLMetaElement).content,
+ Accept: 'text/vnd.turbo-stream.html',
+ },
+ },
+ );
+ }
+
+ disconnect() {
+ super.disconnect();
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index fe23535486b..50ba7e3dcd9 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -20,6 +20,7 @@ import PatternInputController from './controllers/pattern-input.controller';
import HoverCardTriggerController from './controllers/hover-card-trigger.controller';
import ScrollIntoViewController from './controllers/scroll-into-view.controller';
import CkeditorFocusController from './controllers/ckeditor-focus.controller';
+import KeepCollapsedStateController from './controllers/keep-collapsed-state.controller';
declare global {
interface Window {
@@ -55,3 +56,4 @@ instance.register('keep-scroll-position', KeepScrollPositionController);
instance.register('pattern-input', PatternInputController);
instance.register('scroll-into-view', ScrollIntoViewController);
instance.register('ckeditor-focus', CkeditorFocusController);
+instance.register('keep-collapsed-state', KeepCollapsedStateController);
diff --git a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rb b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rb
index 225ea563318..46be0039fc3 100644
--- a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rb
+++ b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rb
@@ -191,9 +191,11 @@ module MeetingAgendaItems
def move_to_backlog_action_item(menu)
menu.with_item(label: I18n.t(:label_agenda_item_move_to_backlog),
- href: drop_meeting_agenda_item_path(@meeting_agenda_item.meeting, @meeting_agenda_item, type: :to_backlog),
- form_arguments: {
- method: :put, data: { "turbo-stream": true }
+ tag: :button,
+ content_arguments: { data: {
+ action: "click->keep-collapsed-state#interceptMoveTo",
+ href: drop_meeting_agenda_item_path(@meeting_agenda_item.meeting, @meeting_agenda_item, type: :to_backlog)
+ }
}) do |item|
item.with_leading_visual_icon(icon: "discussion-outdated")
end
@@ -201,9 +203,11 @@ module MeetingAgendaItems
def move_to_current_meeting_action_item(menu)
menu.with_item(label: I18n.t(:label_agenda_item_move_to_current_meeting),
- href: drop_meeting_agenda_item_path(@meeting_agenda_item.meeting, @meeting_agenda_item, type: :to_current),
- form_arguments: {
- method: :put, data: { "turbo-stream": true }
+ tag: :button,
+ content_arguments: { data: {
+ action: "click->keep-collapsed-state#interceptMoveTo",
+ href: drop_meeting_agenda_item_path(@meeting_agenda_item.meeting, @meeting_agenda_item, type: :to_current)
+ }
}) do |item|
item.with_leading_visual_icon(icon: "cross-reference")
end
diff --git a/modules/meeting/app/components/meeting_sections/backlogs/container_component.html.erb b/modules/meeting/app/components/meeting_sections/backlogs/container_component.html.erb
index f3dd4156b80..76f37b6b848 100644
--- a/modules/meeting/app/components/meeting_sections/backlogs/container_component.html.erb
+++ b/modules/meeting/app/components/meeting_sections/backlogs/container_component.html.erb
@@ -5,7 +5,8 @@
flex.with_row do
render(
MeetingSections::ShowComponent.new(
- meeting_section: @backlog
+ meeting_section: @backlog,
+ collapsed: @collapsed
)
)
end
diff --git a/modules/meeting/app/components/meeting_sections/backlogs/container_component.rb b/modules/meeting/app/components/meeting_sections/backlogs/container_component.rb
index d4eddd92d2e..8cce4d0ff7a 100644
--- a/modules/meeting/app/components/meeting_sections/backlogs/container_component.rb
+++ b/modules/meeting/app/components/meeting_sections/backlogs/container_component.rb
@@ -34,9 +34,10 @@ module MeetingSections
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- def initialize(meeting:)
+ def initialize(collapsed:, meeting:)
super
+ @collapsed = collapsed
@meeting = meeting
@backlog = meeting.backlog
end
diff --git a/modules/meeting/app/components/meeting_sections/backlogs/header_component.html.erb b/modules/meeting/app/components/meeting_sections/backlogs/header_component.html.erb
index 2515c418469..36542aab75e 100644
--- a/modules/meeting/app/components/meeting_sections/backlogs/header_component.html.erb
+++ b/modules/meeting/app/components/meeting_sections/backlogs/header_component.html.erb
@@ -3,7 +3,14 @@
if show?
flex_layout(align_items: :flex_start) do |flex|
flex.with_column(flex: 1, pt: 1) do
- render(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: I18n.t("label_agenda_backlog"), box: @box, description: I18n.t("text_agenda_backlog"), count: @backlog.agenda_items.count, collapsed: @collapsed))
+ render(
+ Primer::OpenProject::BorderBox::CollapsibleHeader.new(
+ title: I18n.t("label_agenda_backlog"), box: @box, description: I18n.t("text_agenda_backlog"), count: @backlog.agenda_items.count, collapsed: @collapsed, data: {
+ keep_collapsed_state_target: "section",
+ action: "click->keep-collapsed-state#rememberState"
+ }
+ )
+ )
end
flex.with_column(classes: "hide-when-print") do
diff --git a/modules/meeting/app/components/meeting_sections/backlogs/header_component.rb b/modules/meeting/app/components/meeting_sections/backlogs/header_component.rb
index 475ac9d9c5e..897f027f880 100644
--- a/modules/meeting/app/components/meeting_sections/backlogs/header_component.rb
+++ b/modules/meeting/app/components/meeting_sections/backlogs/header_component.rb
@@ -34,13 +34,13 @@ module MeetingSections
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- def initialize(backlog:, box: nil)
+ def initialize(backlog:, collapsed:, box: nil)
super
-
@backlog = backlog
@meeting = backlog.meeting
@box = box
- @collapsed = collapsed?
+ @collapsed = collapsed == "true" unless collapsed.nil?
+ @collapsed = default if @collapsed.nil?
end
private
@@ -49,7 +49,7 @@ module MeetingSections
end
- def collapsed?
+ def default
if @meeting.open?
false
elsif @meeting.in_progress?
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 6d4905611ec..680505a94fd 100644
--- a/modules/meeting/app/components/meeting_sections/show_component.html.erb
+++ b/modules/meeting/app/components/meeting_sections/show_component.html.erb
@@ -7,7 +7,7 @@
end
elsif OpenProject::FeatureDecisions.meeting_backlogs_active? && render_backlog? && [email protected]?
component.with_header do
- render(MeetingSections::Backlogs::HeaderComponent.new(backlog: @meeting_section, box: component))
+ render(MeetingSections::Backlogs::HeaderComponent.new(backlog: @meeting_section, box: component, collapsed: @collapsed))
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 146de096ddd..d4f4153df7b 100644
--- a/modules/meeting/app/components/meeting_sections/show_component.rb
+++ b/modules/meeting/app/components/meeting_sections/show_component.rb
@@ -37,7 +37,7 @@ module MeetingSections
with_collection_parameter :meeting_section
def initialize(meeting_section:, first_and_last: [], form_hidden: true, form_type: :simple, insert_target_modified: true,
- force_wrapper: false, state: :show, collapsed: false)
+ force_wrapper: false, state: :show, collapsed: nil)
super
@meeting = meeting_section.meeting
diff --git a/modules/meeting/app/components/meetings/show_component.html.erb b/modules/meeting/app/components/meetings/show_component.html.erb
index b0e707b8b64..3e5102d1f48 100644
--- a/modules/meeting/app/components/meetings/show_component.html.erb
+++ b/modules/meeting/app/components/meetings/show_component.html.erb
@@ -18,7 +18,7 @@
if OpenProject::FeatureDecisions.meeting_backlogs_active?
agenda.with_row do
- render(MeetingSections::Backlogs::ContainerComponent.new(meeting: @meeting))
+ render(MeetingSections::Backlogs::ContainerComponent.new(meeting: @meeting, collapsed: @collapsed))
end
end
diff --git a/modules/meeting/app/components/meetings/show_component.rb b/modules/meeting/app/components/meetings/show_component.rb
index 86889b333da..ffb049a8670 100644
--- a/modules/meeting/app/components/meetings/show_component.rb
+++ b/modules/meeting/app/components/meetings/show_component.rb
@@ -43,7 +43,7 @@ module Meetings
def wrapper_data_attributes
{
- controller: "generic-drag-and-drop",
+ controller: "generic-drag-and-drop keep-collapsed-state",
"application-target": "dynamic"
}
end
diff --git a/modules/meeting/app/components/meetings/update_flash_component.rb b/modules/meeting/app/components/meetings/update_flash_component.rb
index d218760ca51..e3d6202cf31 100644
--- a/modules/meeting/app/components/meetings/update_flash_component.rb
+++ b/modules/meeting/app/components/meetings/update_flash_component.rb
@@ -47,6 +47,7 @@ module Meetings
href: helpers.project_meeting_path(project, meeting),
size: :medium,
data: {
+
keep_scroll_position_target: "triggerButton"
}
) { I18n.t("label_meeting_reload") }
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 fabe5f96448..b50ef96ef4e 100644
--- a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb
+++ b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb
@@ -281,30 +281,41 @@ module Meetings
update_show_items_of_section_via_turbo_stream(meeting_section: meeting_agenda_item.meeting_section)
end
- def move_item_to_other_section_via_turbo_stream(old_section:, current_section:, meeting_agenda_item: @meeting_agenda_item)
+ # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
+ def move_item_to_other_section_via_turbo_stream(old_section:, current_section:, meeting_agenda_item: @meeting_agenda_item,
+ collapsed: nil)
move_item_via_turbo_stream(meeting_agenda_item:)
# Update the header for updated timestamp
update_header_component_via_turbo_stream
# update the old section
- update_section_header_via_turbo_stream(meeting_section: old_section)
-
- if old_section.agenda_items.empty?
- update_section_via_turbo_stream(meeting_section: old_section)
+ if old_section.backlog?
+ update_backlog_via_turbo_stream(collapsed:)
else
- update_show_items_of_section_via_turbo_stream(meeting_section: old_section)
+ update_section_header_via_turbo_stream(meeting_section: old_section)
+
+ if old_section.agenda_items.empty?
+ update_section_via_turbo_stream(meeting_section: old_section)
+ else
+ update_show_items_of_section_via_turbo_stream(meeting_section: old_section)
+ end
end
# update the new section
- update_section_header_via_turbo_stream(meeting_section: current_section)
-
- if current_section.agenda_items.count == 1
- update_section_via_turbo_stream(meeting_section: current_section)
+ if current_section.backlog?
+ update_backlog_via_turbo_stream(collapsed:)
else
- update_show_items_of_section_via_turbo_stream(meeting_section: current_section)
+ update_section_header_via_turbo_stream(meeting_section: current_section)
+
+ if current_section.agenda_items.count == 1
+ update_section_via_turbo_stream(meeting_section: current_section)
+ else
+ update_show_items_of_section_via_turbo_stream(meeting_section: current_section)
+ end
end
end
+ # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
def move_item_via_turbo_stream(meeting_agenda_item: @meeting_agenda_item)
# Note: The `remove_component` and the `component` are pointing to the same
@@ -350,11 +361,12 @@ module Meetings
)
end
- def update_backlog_via_turbo_stream(meeting: @meeting)
+ def update_backlog_via_turbo_stream(collapsed:, meeting: @meeting)
if OpenProject::FeatureDecisions.meeting_backlogs_active?
update_via_turbo_stream(
component: MeetingSections::Backlogs::ContainerComponent.new(
- meeting: meeting
+ meeting: meeting,
+ collapsed:
)
)
end
@@ -441,7 +453,7 @@ module Meetings
update_sidebar_component_via_turbo_stream
update_new_button_via_turbo_stream
update_list_via_turbo_stream
- update_backlog_via_turbo_stream
+ # update_backlog_via_turbo_stream
end
end
end
diff --git a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
index 7f634c155cf..f5612d2da53 100644
--- a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
+++ b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
@@ -88,7 +88,7 @@ class MeetingAgendaItemsController < ApplicationController
reset_meeting_from_agenda_item
# enable continue editing
add_item_via_turbo_stream(clear_slate: false)
- update_backlog_via_turbo_stream
+ update_backlog_via_turbo_stream(collapsed: nil)
update_header_component_via_turbo_stream
update_sidebar_details_component_via_turbo_stream
else
@@ -171,7 +171,8 @@ class MeetingAgendaItemsController < ApplicationController
if call.result[:section_changed]
move_item_to_other_section_via_turbo_stream(
old_section: call.result[:old_section],
- current_section: call.result[:current_section]
+ current_section: call.result[:current_section],
+ collapsed: params[:collapsed]
)
else
move_item_within_section_via_turbo_stream
diff --git a/modules/meeting/app/controllers/meeting_sections_controller.rb b/modules/meeting/app/controllers/meeting_sections_controller.rb
index 96ea1fe2fe4..b80fb8f4016 100644
--- a/modules/meeting/app/controllers/meeting_sections_controller.rb
+++ b/modules/meeting/app/controllers/meeting_sections_controller.rb
@@ -182,7 +182,7 @@ class MeetingSectionsController < ApplicationController
errors << call.errors unless call.success?
end
- update_backlog_via_turbo_stream
+ update_backlog_via_turbo_stream(collapsed: true.to_s)
render_error_flash_message_via_turbo_stream(message: t("text_backlog_clear_error")) if errors.any?
respond_with_turbo_streams
@@ -226,4 +226,8 @@ class MeetingSectionsController < ApplicationController
# show additional base error message
render_base_error_in_flash_message_via_turbo_stream(call.errors)
end
+
+ def toggle_params
+ @toggle_params ||= params.permit(:id, :collapsed)
+ end
end
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index 7e42f08ddfa..ff4bf7843b2 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -296,6 +296,7 @@ class MeetingsController < ApplicationController
update_sidebar_state_component_via_turbo_stream
else
update_all_via_turbo_stream
+ update_backlog_via_turbo_stream(collapsed: nil)
end
respond_with_turbo_streams