|
|
@ -6,11 +6,14 @@ import { |
|
|
|
hierarchyGroupClass, |
|
|
|
hierarchyGroupClass, |
|
|
|
hierarchyRootClass |
|
|
|
hierarchyRootClass |
|
|
|
} from "core-components/wp-fast-table/helpers/wp-table-hierarchy-helpers"; |
|
|
|
} from "core-components/wp-fast-table/helpers/wp-table-hierarchy-helpers"; |
|
|
|
|
|
|
|
import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service"; |
|
|
|
|
|
|
|
import {relationRowClass} from "core-components/wp-fast-table/helpers/wp-table-row-helpers"; |
|
|
|
|
|
|
|
|
|
|
|
export class HierarchyDragActionService extends TableDragActionService { |
|
|
|
export class HierarchyDragActionService extends TableDragActionService { |
|
|
|
|
|
|
|
|
|
|
|
private wpTableHierarchies = this.injector.get(WorkPackageViewHierarchiesService); |
|
|
|
private wpTableHierarchies = this.injector.get(WorkPackageViewHierarchiesService); |
|
|
|
private relationHierarchyService = this.injector.get(WorkPackageRelationsHierarchyService); |
|
|
|
private relationHierarchyService = this.injector.get(WorkPackageRelationsHierarchyService); |
|
|
|
|
|
|
|
private wpCacheService = this.injector.get(WorkPackageCacheService); |
|
|
|
|
|
|
|
|
|
|
|
public get applies() { |
|
|
|
public get applies() { |
|
|
|
return this.wpTableHierarchies.isEnabled; |
|
|
|
return this.wpTableHierarchies.isEnabled; |
|
|
@ -24,36 +27,73 @@ export class HierarchyDragActionService extends TableDragActionService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public handleDrop(workPackage:WorkPackageResource, el:HTMLElement):Promise<unknown> { |
|
|
|
public handleDrop(workPackage:WorkPackageResource, el:HTMLElement):Promise<unknown> { |
|
|
|
const parentObject = this.determineParent(el); |
|
|
|
return this.determineParent(el).then((parentId:string|null) => { |
|
|
|
const newParent = parentObject ? parentObject.id : null; |
|
|
|
return this.relationHierarchyService.changeParent(workPackage, parentId); |
|
|
|
return this.relationHierarchyService.changeParent(workPackage, newParent); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Find an applicable parent element from the hierarchy information in the table. |
|
|
|
* Find an applicable parent element from the hierarchy information in the table. |
|
|
|
* @param el |
|
|
|
* @param el |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private determineParent(el:HTMLElement):{el:Element, id:string}|null { |
|
|
|
private determineParent(el:HTMLElement):Promise<string|null> { |
|
|
|
let previous = el.previousElementSibling; |
|
|
|
let previous = el.previousElementSibling; |
|
|
|
|
|
|
|
var parent = null; |
|
|
|
|
|
|
|
|
|
|
|
while (previous !== null) { |
|
|
|
if (previous !== null && !this.isFlatList(previous)) { |
|
|
|
// When there is no hierarchy group at all, we're at a flat list
|
|
|
|
// If the previous element is a relation row,
|
|
|
|
const inGroup = previous.className.indexOf(hierarchyGroupClass('')) >= 0; |
|
|
|
// skip it until we find the real previous sibling
|
|
|
|
const isRoot = previous.className.indexOf(hierarchyRootClass('')) >= 0; |
|
|
|
const isRelationRow = previous.className.indexOf(relationRowClass()) >= 0; |
|
|
|
if (!(inGroup || isRoot)) { |
|
|
|
if (isRelationRow) { |
|
|
|
return null; |
|
|
|
let relationRoot = this.findRelationRowRoot(previous); |
|
|
|
|
|
|
|
if (relationRoot == null) { |
|
|
|
|
|
|
|
return Promise.resolve(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
previous = relationRoot; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If the sibling is a hierarchy root, return this one
|
|
|
|
let previousWpId = (previous as HTMLElement).dataset.workPackageId!; |
|
|
|
let wpId = (previous as HTMLElement).dataset.workPackageId!; |
|
|
|
if (this.isHiearchyRoot(previous, previousWpId)) { |
|
|
|
if (previous.classList.contains(hierarchyRootClass(wpId))) { |
|
|
|
// If the sibling is a hierarchy root, return that sibling as new parent.
|
|
|
|
return {el: previous, id: wpId}; |
|
|
|
parent = previousWpId; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
// If the sibling is no hierarchy root, return it's parent.
|
|
|
|
|
|
|
|
// Thus, the dropped element will get the same hierarchy level as the sibling
|
|
|
|
|
|
|
|
parent = this.loadParentOfWP(previousWpId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Promise.resolve(parent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private findRelationRowRoot(el:Element):Element|null { |
|
|
|
|
|
|
|
let previous = el.previousElementSibling; |
|
|
|
|
|
|
|
while (previous !== null) { |
|
|
|
|
|
|
|
if (previous.className.indexOf(relationRowClass()) < 0) { |
|
|
|
|
|
|
|
return previous; |
|
|
|
|
|
|
|
} |
|
|
|
previous = previous.previousElementSibling; |
|
|
|
previous = previous.previousElementSibling; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private isFlatList(previous:Element):boolean { |
|
|
|
|
|
|
|
const inGroup = previous.className.indexOf(hierarchyGroupClass('')) >= 0; |
|
|
|
|
|
|
|
const isRoot = previous.className.indexOf(hierarchyRootClass('')) >= 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return !(inGroup || isRoot); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private isHiearchyRoot(previous:Element, previousWpId:string):boolean { |
|
|
|
|
|
|
|
return previous.classList.contains(hierarchyRootClass(previousWpId)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private loadParentOfWP(wpId:string):Promise<string|null> { |
|
|
|
|
|
|
|
return this.wpCacheService.require(wpId) |
|
|
|
|
|
|
|
.then((wp:WorkPackageResource) => { |
|
|
|
|
|
|
|
return Promise.resolve(wp.parent.id); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|