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 drag and drop actions

Mir Bhatiaf9c109e5dbf5
diff --git a/frontend/src/stimulus/controllers/dynamic/generic-drag-and-drop.controller.ts b/frontend/src/stimulus/controllers/dynamic/generic-drag-and-drop.controller.ts
index 35e1b306a75..1ba36d77dbf 100644
--- a/frontend/src/stimulus/controllers/dynamic/generic-drag-and-drop.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/generic-drag-and-drop.controller.ts
@@ -39,7 +39,7 @@ interface TargetConfig {
targetId:string|null;
}
-export default class extends Controller {
+export default class GenericDragAndDropController extends Controller {
drake:Drake|undefined;
targetConfigs:TargetConfig[];
@@ -148,25 +148,7 @@ export default class extends Controller {
async drop(el:Element, target:Element, _source:Element|null, _sibling:Element|null) {
const dropUrl = el.getAttribute('data-drop-url');
-
- let targetPosition = Array.from(target.children).indexOf(el);
- if (target.children.length > 0 && target.children[0].getAttribute('data-empty-list-item') === 'true') {
- // if the target container is empty, a list item showing an empty message might be shown
- // this should not be counted as a list item
- // thus we need to subtract 1 from the target position
- targetPosition -= 1;
- }
-
- const targetConfig = this.targetConfigs.find((config) => config.container === target);
- const targetId = targetConfig?.targetId as string|undefined;
-
- const data = new FormData();
-
- data.append('position', (targetPosition + 1).toString());
-
- if (targetId) {
- data.append('target_id', targetId.toString());
- }
+ const data = this.buildData(el, target);
if (dropUrl) {
const response = await fetch(dropUrl, {
@@ -200,4 +182,27 @@ export default class extends Controller {
this.drake.destroy();
}
}
+
+ protected buildData(el:Element, target:Element):FormData {
+ let targetPosition = Array.from(target.children).indexOf(el);
+ if (target.children.length > 0 && target.children[0].getAttribute('data-empty-list-item') === 'true') {
+ // if the target container is empty, a list item showing an empty message might be shown
+ // this should not be counted as a list item
+ // thus we need to subtract 1 from the target position
+ targetPosition -= 1;
+ }
+
+ const data = new FormData();
+
+ data.append('position', (targetPosition + 1).toString());
+
+ const targetConfig = this.targetConfigs.find((config) => config.container === target);
+ const targetId = targetConfig?.targetId as string|undefined;
+
+ if (targetId) {
+ data.append('target_id', targetId.toString());
+ }
+
+ return data;
+ }
}
diff --git a/frontend/src/stimulus/controllers/dynamic/meeting-agenda-item-drag-and-drop.controller.ts b/frontend/src/stimulus/controllers/dynamic/meeting-agenda-item-drag-and-drop.controller.ts
deleted file mode 100644
index 2ec7f63e2ab..00000000000
--- a/frontend/src/stimulus/controllers/dynamic/meeting-agenda-item-drag-and-drop.controller.ts
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * -- 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 * as Turbo from '@hotwired/turbo';
-import { Controller } from '@hotwired/stimulus';
-import { Drake } from 'dragula';
-import { debugLog } from 'core-app/shared/helpers/debug_output';
-
-export default class extends Controller {
- drake:Drake|undefined;
-
- autoScroll() {
- // options copied from generic-drag-and-drop.controller for consistency
- void window.OpenProject.getPluginContext().then((pluginContext) => {
- // eslint-disable-next-line no-new
- new pluginContext.classes.DomAutoscrollService(
- [
- document.getElementById('content-body') as HTMLElement,
- ],
- {
- margin: 25,
- maxSpeed: 10,
- scrollWhenOutside: true,
- autoScroll: () => this.drake?.dragging,
- },
- );
- });
- }
-
- connect() {
- this.drake = dragula(
- [this.containerTarget],
- { moves: (_el, _source, handle, _sibling) => !!handle?.classList.contains('octicon-grabber') },
- )
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- .on('drop', this.drop.bind(this));
-
- this.autoScroll();
- }
-
- get containerTarget():HTMLElement {
- const targetTag = this.data.get('target-tag');
- return this.element.querySelector(targetTag || 'ul') as HTMLElement;
- }
-
- async drop(el:Element, _target:Element|null, _source:Element|null, _sibling:Element|null) {
- const id = el.getAttribute('data-id');
- const url = el.getAttribute('data-drop-url');
- const data = new FormData();
- const newIndex = Array.from(this.containerTarget.children).indexOf(el);
-
- if (id && url) {
- data.append('position', (newIndex + 1).toString());
-
- const response = await fetch(url, {
- method: 'PUT',
- body: data,
- headers: {
- 'X-CSRF-Token': (document.querySelector('meta[name="csrf-token"]') as HTMLMetaElement).content,
- Accept: 'text/vnd.turbo-stream.html',
- },
- credentials: 'same-origin',
- });
-
- if (!response.ok) {
- debugLog('Failed to sort item');
- } else {
- const text = await response.text();
- Turbo.renderStreamMessage(text);
- }
- }
-
- if (this.drake) {
- this.drake.cancel(true); // necessary to prevent "copying" behaviour
- }
- }
-
- disconnect() {
- if (this.drake) {
- this.drake.destroy();
- }
- }
-}
diff --git a/frontend/src/stimulus/controllers/dynamic/meetings-drag-and-drop.controller.ts b/frontend/src/stimulus/controllers/dynamic/meetings-drag-and-drop.controller.ts
new file mode 100644
index 00000000000..c513bf8322c
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/meetings-drag-and-drop.controller.ts
@@ -0,0 +1,45 @@
+/*
+ * -- 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 GenericDragAndDropController from './generic-drag-and-drop.controller';
+
+export default class MeetingsDragAndDropController extends GenericDragAndDropController {
+ protected override buildData(el:Element, target:Element):FormData {
+ const header = document.querySelector('.CollapsibleHeader');
+ const data = super.buildData(el, target);
+
+ if (header) {
+ const collapsed = header.classList.contains('CollapsibleHeader--collapsed');
+ data.append('collapsed', collapsed.toString());
+ }
+
+ return data;
+ }
+}
diff --git a/modules/meeting/app/components/meetings/show_component.rb b/modules/meeting/app/components/meetings/show_component.rb
index ffb049a8670..eade7b8a981 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 keep-collapsed-state",
+ controller: "meetings-drag-and-drop keep-collapsed-state",
"application-target": "dynamic"
}
end