From 074a1c134c72e729d629aee8f4b836f8cb144f63 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Thu, 18 May 2023 10:34:41 -0400 Subject: [PATCH] forgot to commit the Move dialog --- .../custom-org-unit-trees-dialog.component.html | 28 ++++++++ .../custom-org-unit-trees-dialog.component.ts | 79 ++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.html new file mode 100644 index 0000000000..1ad38df67b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.html @@ -0,0 +1,28 @@ + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.ts new file mode 100644 index 0000000000..bb7ce95d0b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees-dialog.component.ts @@ -0,0 +1,79 @@ +import {Component, Input, OnChanges, SimpleChanges} from '@angular/core'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {Tree} from '@eg/share/tree/tree'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; + +@Component({ + selector: 'eg-custom-org-unit-trees-dialog', + templateUrl: './custom-org-unit-trees-dialog.component.html' +}) + +export class CustomOrgUnitTreesDialogComponent + extends DialogComponent implements OnChanges { + + @Input() customTree: Tree; + selectionTree: Tree; + + moveNodeHereDisabled: boolean = false; + + constructor( + private modal: NgbModal + ) { + super(modal); + if (this.modal) {} // de-lint + } + + ngOnChanges(changes: SimpleChanges) { + if (changes.customTree && changes.customTree.currentValue) { + this.selectionTree = changes.customTree.currentValue?.clone(); + this.moveNodeHereDisabled = !this.isMoveNodeHereAllowed(); + } + } + + custom_nodeClicked($event: any) { + console.log('custom: custom_nodeClicked',typeof $event); + this.moveNodeHereDisabled = !this.isMoveNodeHereAllowed(); + } + + isMoveNodeHereAllowed(): boolean { + const selectedNodes = this.customTree.selectedNodes(); + return selectedNodes.length === 1 && selectedNodes[0] !== this.customTree.rootNode; + } + moveNodeHere() { + const targetNodeInSelectionTree = this.selectionTree.selectedNode(); + const selectedNode = this.customTree.selectedNode(); + this.moveNodeHereDisabled = !this.isMoveNodeHereAllowed(); + if (this.moveNodeHereDisabled) { + return; + } + if (targetNodeInSelectionTree) { + try { + // Find the equivalent node in customTree + const targetNodeInCustomTree = this.customTree.findNodesByFieldAndValue('label',targetNodeInSelectionTree.label)[0]; + + // Prevent a node from becoming its own parent. + if (selectedNode === targetNodeInCustomTree || this.customTree.findParentNode(targetNodeInCustomTree) === selectedNode) { + return; + } + + // Remove the selected node from its current parent's children. + let parentNode = this.customTree.findParentNode(selectedNode); + if (parentNode) { + let index = parentNode.children.indexOf(selectedNode); + if (index !== -1) { + parentNode.children.splice(index, 1); + } + } + + // Add the selected node as the last child of the target node in customTree. + if(targetNodeInCustomTree) { + targetNodeInCustomTree.children.push(selectedNode); + } + this.close(true); + } catch(E) { + console.error('moveNodeHere',E); + } + } + } + +} -- 2.11.0