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
When droppint on collapsed group, changing to propper position in view and back-end
Aleix Suauf443d1621db2
diff --git a/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts b/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.tsindex d04602e619e..8953f2171ca 100644--- a/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts+++ b/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts@@ -17,6 +17,8 @@ import {BrowserDetector} from "core-app/modules/common/browser/browser-detector.import {WorkPackagesListService} from "core-components/wp-list/wp-list.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {isInsideCollapsedGroup} from "core-components/wp-fast-table/helpers/wp-table-row-helpers";+import {collapsedGroupClass} from "core-components/wp-fast-table/helpers/wp-table-hierarchy-helpers";export class DragAndDropTransformer {@@ -67,13 +69,25 @@ export class DragAndDropTransformer {const workPackage = this.states.workPackages.get(wpId).value;return !!workPackage && this.actionService.canPickup(workPackage);},- onMoved: async (el:HTMLElement, target:HTMLElement, source:HTMLElement) => {+ onMoved: async (el:HTMLElement, target:HTMLElement, source:HTMLElement, sibling:HTMLElement|null) => {const wpId:string = el.dataset.workPackageId!;- const rowIndex = this.findRowIndex(el);+ let rowIndex;try {const workPackage = await this.apiV3Service.work_packages.id(wpId).get().toPromise();++ if (isInsideCollapsedGroup(sibling)) {+ const collapsedGroupCSSClass = Array.from(sibling!.classList).find(listClass => listClass.includes(collapsedGroupClass()))!;+ const collapsedGroupId = collapsedGroupCSSClass.replace(collapsedGroupClass(), '');+ const collapsedGroupElements = source.getElementsByClassName(collapsedGroupClass(collapsedGroupId));+ const collapsedGroupLastChild = collapsedGroupElements[collapsedGroupElements.length - 1];+ rowIndex = this.findRowIndex(collapsedGroupLastChild as HTMLElement);+ } else {+ rowIndex = this.findRowIndex(el);+ }+const newOrder = await this.wpTableOrder.move(this.currentOrder, wpId, rowIndex);+await this.actionService.handleDrop(workPackage, el);this.updateRenderedOrder(newOrder);this.actionService.onNewOrder(newOrder);diff --git a/frontend/src/app/components/wp-fast-table/helpers/wp-table-hierarchy-helpers.ts b/frontend/src/app/components/wp-fast-table/helpers/wp-table-hierarchy-helpers.tsindex 8bb7f80c5b1..fbe87c7055c 100644--- a/frontend/src/app/components/wp-fast-table/helpers/wp-table-hierarchy-helpers.ts+++ b/frontend/src/app/components/wp-fast-table/helpers/wp-table-hierarchy-helpers.ts@@ -1,7 +1,7 @@/*** Returns the collapsed group class for the given ancestor id*/-export function collapsedGroupClass(ancestorId:string):string {+export function collapsedGroupClass(ancestorId:string = ''):string {return `__collapsed-group-${ancestorId}`;}diff --git a/frontend/src/app/components/wp-fast-table/helpers/wp-table-row-helpers.ts b/frontend/src/app/components/wp-fast-table/helpers/wp-table-row-helpers.tsindex 80cf1361480..4e36dbb60ad 100644--- a/frontend/src/app/components/wp-fast-table/helpers/wp-table-row-helpers.ts+++ b/frontend/src/app/components/wp-fast-table/helpers/wp-table-row-helpers.ts@@ -1,7 +1,8 @@-/*** Return the row html id attribute for the given work package ID.*/+import {collapsedGroupClass} from "core-components/wp-fast-table/helpers/wp-table-hierarchy-helpers";+export function rowId(workPackageId:string):string {return `wp-row-${workPackageId}-table`;}@@ -18,6 +19,14 @@ export function locateTableRowByIdentifier(identifier:string) {return jQuery(`.${identifier}-table`);}+export function isInsideCollapsedGroup(el?:Element | null) {+ if (!el) {+ return false;+ }++ return Array.from(el.classList).find(listClass => listClass.includes(collapsedGroupClass())) != null;+}+export function locatePredecessorBySelector(el:HTMLElement, selector:string):HTMLElement|null {let previous = el.previousElementSibling;diff --git a/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts b/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.tsindex bd52d130aef..9ec29fee8b4 100644--- a/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts+++ b/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts@@ -6,7 +6,7 @@ import {hierarchyGroupClass,hierarchyRootClass} from "core-components/wp-fast-table/helpers/wp-table-hierarchy-helpers";-import {relationRowClass} from "core-components/wp-fast-table/helpers/wp-table-row-helpers";+import {relationRowClass, isInsideCollapsedGroup} from "core-components/wp-fast-table/helpers/wp-table-row-helpers";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@@ -37,15 +37,16 @@ export class HierarchyDragActionService extends TableDragActionService {* Find an applicable parent element from the hierarchy information in the table.* @param el*/- private determineParent(el:HTMLElement):Promise<string|null> {+ private determineParent(el:Element):Promise<string|null> {let previous = el.previousElementSibling;let next = el.nextElementSibling;let parent = null;- if (previous !== null && this.droppedIntoParentGroup(el, previous, next)) {+ if (previous !== null && this.droppedIntoGroup(el, previous, next)) {// If the previous element is a relation row,// skip it until we find the real previous siblingconst isRelationRow = previous.className.indexOf(relationRowClass()) >= 0;+ const droppedIntoCollapsedGroup = isInsideCollapsedGroup(next);if (isRelationRow) {let relationRoot = this.findRelationRowRoot(previous);@@ -58,6 +59,9 @@ export class HierarchyDragActionService extends TableDragActionService {let previousWpId = (previous as HTMLElement).dataset.workPackageId!;if (this.isHiearchyRoot(previous, previousWpId)) {+ if (droppedIntoCollapsedGroup) {+ return this.determineParent(previous);+ }// If the sibling is a hierarchy root, return that sibling as new parent.parent = previousWpId;} else {@@ -82,17 +86,19 @@ export class HierarchyDragActionService extends TableDragActionService {return null;}- private droppedIntoParentGroup(element:Element, previous:Element, next:Element | null):boolean {+ private droppedIntoGroup(element:Element, previous:Element, next:Element | null):boolean {const inGroup = previous.className.indexOf(hierarchyGroupClass('')) >= 0;const isRoot = previous.className.indexOf(hierarchyRootClass('')) >= 0;let skipDroppedIntoGroup;- if (inGroup) {- const elementGroup = Array.from(element.classList).find(listClass => listClass.includes('__hierarchy-group-'));- const previousGroup = Array.from(previous.classList).find(listClass => listClass.includes('__hierarchy-group-'));- const nextGroup = next && Array.from(next.classList).find(listClass => listClass.includes('__hierarchy-group-'));- const isLastElementOfGroup = previousGroup !== nextGroup;- const elementAlreadyBelongsToGroup = elementGroup === previousGroup;+ if (inGroup || isRoot) {+ const elementGroups = Array.from(element.classList).filter(listClass => listClass.includes('__hierarchy-group-')) || [];+ const previousGroups = Array.from(previous.classList).filter(listClass => listClass.includes('__hierarchy-group-')) || [];+ const nextGroups = next && Array.from(next.classList).filter(listClass => listClass.includes('__hierarchy-group-')) || [];+ const previousWpId = (previous as HTMLElement).dataset.workPackageId!;+ const isLastElementOfGroup = !nextGroups.some(nextGroup => previousGroups.includes(nextGroup)) && !nextGroups.includes(hierarchyGroupClass(previousWpId));+ const elementAlreadyBelongsToGroup = elementGroups.some(nextGroup => previousGroups.includes(nextGroup)) ||+ elementGroups.includes(hierarchyGroupClass(previousWpId));skipDroppedIntoGroup = isLastElementOfGroup && !elementAlreadyBelongsToGroup;}