From: Jason Etheridge Date: Mon, 15 May 2023 03:19:50 +0000 (-0400) Subject: cloning X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1c9f0c8728c070e2e104dbab184bae0e99ac46c1;p=working%2FEvergreen.git cloning Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/eg2/src/app/share/tree/tree.ts b/Open-ILS/src/eg2/src/app/share/tree/tree.ts index fd76d82b3d..2eedee9c13 100644 --- a/Open-ILS/src/eg2/src/app/share/tree/tree.ts +++ b/Open-ILS/src/eg2/src/app/share/tree/tree.ts @@ -39,6 +39,18 @@ export class TreeNode { toggleExpand() { this.expanded = !this.expanded; } + + clone(): TreeNode { + const clonedNode = new TreeNode({ + id: this.id, + label: this.label, + expanded: this.expanded, + callerData: this.callerData, // NOTE: shallow copy + }); + + clonedNode.children = this.children.map(child => child.clone()); + return clonedNode; + } } export class Tree { @@ -176,5 +188,9 @@ export class Tree { }); } + clone(): Tree { + const clonedTree = new Tree(this.rootNode.clone()); + return clonedTree; + } } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees.component.ts index 95d5958a58..10fa01d2de 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees.component.ts @@ -37,10 +37,14 @@ export class CustomOrgUnitTreesComponent implements OnInit { ) {} - ngOnInit() { - this.loadAouTree(this.org.root().id()); - this.loadCustomTree(); - console.log('component this', this); + async ngOnInit() { + try { + await this.loadAouTree(this.org.root().id()); + await this.loadCustomTree('opac'); + console.log('component this', this); + } catch(E) { + console.error('caught during ngOnInit',E); + } } async loadAouTree(selectNodeId?: number): Promise { @@ -51,7 +55,7 @@ export class CustomOrgUnitTreesComponent implements OnInit { {flesh : -1, flesh_fields : {aou : flesh}}, {authoritative: true} )); - this.ingestAouTree(tree); + this.ingestAouTree(tree); // sets this.tree as a side-effect if (!selectNodeId) { selectNodeId = this.org.root().id(); } const node = this.tree.findNode(selectNodeId); @@ -64,12 +68,12 @@ export class CustomOrgUnitTreesComponent implements OnInit { } } - async loadCustomTree(): Promise { + async loadCustomTree(purpose: string): Promise { const flesh = ['children', 'org_unit']; let tree_type: IdlObject; tree_type = await firstValueFrom( - this.pcrud.search('aouct', { purpose: 'opac' }) + this.pcrud.search('aouct', { purpose: purpose }) .pipe( take(1), defaultIfEmpty(undefined), @@ -88,21 +92,24 @@ export class CustomOrgUnitTreesComponent implements OnInit { } let tree: IdlObject; - tree = await firstValueFrom( - this.pcrud.search('aouctn', {tree: tree_id, parent_node: null}, - {flesh: -1, flesh_fields: {aouctn: flesh}}, {authoritative: true}) - .pipe( - take(1), - defaultIfEmpty(undefined), - catchError(err => { - console.warn('phasefx: caught from pcrud (aouctn): 2', err); - return of(undefined); - }) - ) - ); - - this.ingestCustomTree(tree); - return this.custom_tree; + if (tree_id) { + tree = await firstValueFrom( + this.pcrud.search('aouctn', {tree: tree_id, parent_node: null}, + {flesh: -1, flesh_fields: {aouctn: flesh}}, {authoritative: true}) + .pipe( + take(1), + defaultIfEmpty(undefined), + catchError(err => { + console.warn('phasefx: caught from pcrud (aouctn): 2', err); + return of(undefined); + }) + ) + ); + this.ingestCustomTree(tree); // sets this.custom_tree as a side-effect + } else { + this.custom_tree = this.tree.clone(); // need to remember to create the aouct if needed upon saving + } + return this.custom_tree; } // Translate the org unt type tree into a structure EgTree can use.