|
|
|
@ -1,4 +1,6 @@ |
|
|
|
import { |
|
|
|
ChangeDetectionStrategy, |
|
|
|
ChangeDetectorRef, |
|
|
|
Component, |
|
|
|
ContentChild, |
|
|
|
EventEmitter, |
|
|
|
@ -26,6 +28,7 @@ export type DropEvent = NzFormatEmitEvent & { pos: number }; |
|
|
|
styleUrls: ['tree.component.scss'], |
|
|
|
encapsulation: ViewEncapsulation.None, |
|
|
|
providers: [SubscriptionService], |
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
|
|
}) |
|
|
|
export class TreeComponent implements OnInit { |
|
|
|
dropPosition: number; |
|
|
|
@ -38,6 +41,7 @@ export class TreeComponent implements OnInit { |
|
|
|
@Optional() |
|
|
|
@Inject(DISABLE_TREE_STYLE_LOADING_TOKEN) |
|
|
|
private disableTreeStyleLoading: boolean | undefined, |
|
|
|
private cdr: ChangeDetectorRef, |
|
|
|
) {} |
|
|
|
|
|
|
|
@ContentChild('menu') menu: TemplateRef<any>; |
|
|
|
@ -77,6 +81,21 @@ export class TreeComponent implements OnInit { |
|
|
|
this.subscriptionService.addOne(loaded$); |
|
|
|
} |
|
|
|
|
|
|
|
private findNode(target: any, nodes: any[]) { |
|
|
|
for (const node of nodes) { |
|
|
|
if (node.key === target.id) { |
|
|
|
return node; |
|
|
|
} |
|
|
|
if (node.children) { |
|
|
|
let res = this.findNode(target, node.children); |
|
|
|
if (res) { |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
onSelectedNodeChange(node: NzTreeNode) { |
|
|
|
this.selectedNode = node.origin.entity; |
|
|
|
if (this.changeCheckboxWithNode) { |
|
|
|
@ -116,4 +135,10 @@ export class TreeComponent implements OnInit { |
|
|
|
initDropdown(key: string, dropdown: NgbDropdown) { |
|
|
|
this.dropdowns[key] = dropdown; |
|
|
|
} |
|
|
|
|
|
|
|
setSelectedNode(node: any) { |
|
|
|
let newSelectedNode = this.findNode(node, this.nodes); |
|
|
|
this.selectedNode = { ...newSelectedNode }; |
|
|
|
this.cdr.markForCheck(); |
|
|
|
} |
|
|
|
} |
|
|
|
|