From ecd1d1b1b3939c016c00b9c8c8f0cb5a306d6d14 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Wed, 10 May 2023 12:25:06 -0400 Subject: [PATCH] hrmm Signed-off-by: Jason Etheridge --- .../src/eg2/src/app/share/tree/tree.component.ts | 1 + .../server/custom-org-unit-trees.component.ts | 77 ++++++++++++---------- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/tree/tree.component.ts b/Open-ILS/src/eg2/src/app/share/tree/tree.component.ts index 599dae4a85..44d3b24d61 100644 --- a/Open-ILS/src/eg2/src/app/share/tree/tree.component.ts +++ b/Open-ILS/src/eg2/src/app/share/tree/tree.component.ts @@ -59,6 +59,7 @@ export class TreeComponent { constructor() { this.nodeClicked = new EventEmitter(); + this.nodeChecked = new EventEmitter(); } displayNodes(): TreeNode[] { 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 511f866d32..7befd57478 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 @@ -1,5 +1,5 @@ import {Component, ViewChild, OnInit} from '@angular/core'; -import { firstValueFrom } from 'rxjs'; +import {catchError, firstValueFrom, of, take, defaultIfEmpty} from 'rxjs'; import {Tree, TreeNode} from '@eg/share/tree/tree'; //import {IdlService} from '@eg/core/idl.service'; import {IdlObject} from '@eg/core/idl.service'; @@ -40,6 +40,7 @@ export class CustomOrgUnitTreesComponent implements OnInit { ngOnInit() { this.loadAouTree(this.org.root().id()); this.loadCustomTree(); + console.log('component this', this); } async loadAouTree(selectNodeId?: number): Promise { @@ -63,40 +64,46 @@ export class CustomOrgUnitTreesComponent implements OnInit { } } - async loadCustomTree(): Promise { - - const flesh = ['children', 'org_unit']; - - let tree_type: IdlObject; - try { - tree_type = await firstValueFrom( - this.pcrud.search('aouct', { purpose: 'opac', }) - ); - } catch(E) { - console.warn('caught from pcrud (aouct)', E); - tree_type = null; - } - let tree_id: number; - if (tree_type) { - tree_id = tree_type.id(); - } else { - tree_id = null; - } - - let tree: IdlObject; - try { - tree = await firstValueFrom( - this.pcrud.search('aouctn', {tree: tree_id, parent_node : null, }, - {flesh : -1, flesh_fields : {aouctn : flesh}}, {authoritative: true} - )); - } catch(E) { - console.warn('phasefx: caught from pcrud (aouctn)', E); - tree = null; - } - - this.ingestCustomTree(tree); - return this.custom_tree; - } + async loadCustomTree(): Promise { + const flesh = ['children', 'org_unit']; + + let tree_type: IdlObject; + tree_type = await firstValueFrom( + this.pcrud.search('aouct', { purpose: 'opac' }) + .pipe( + take(1), + defaultIfEmpty(undefined), + catchError(err => { + console.warn('caught from pcrud (aouct): 1', err); + return of(undefined); + }) + ) + ); + + let tree_id: number; + if (tree_type) { + tree_id = tree_type.id(); + } else { + tree_id = null; + } + + 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; + } // Translate the org unt type tree into a structure EgTree can use. ingestAouTree(aouTree: IdlObject) { -- 2.11.0