hrmm
authorJason Etheridge <jason@EquinoxOLI.org>
Wed, 10 May 2023 16:25:06 +0000 (12:25 -0400)
committerJason Etheridge <phasefx@gmail.com>
Thu, 25 May 2023 16:45:32 +0000 (12:45 -0400)
Signed-off-by: Jason Etheridge <jason@EquinoxOLI.org>
Open-ILS/src/eg2/src/app/share/tree/tree.component.ts
Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees.component.ts

index 599dae4..44d3b24 100644 (file)
@@ -59,6 +59,7 @@ export class TreeComponent {
 
     constructor() {
         this.nodeClicked = new EventEmitter<TreeNode>();
+        this.nodeChecked = new EventEmitter<TreeNode>();
     }
 
     displayNodes(): TreeNode[] {
index 511f866..7befd57 100644 (file)
@@ -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<any> {
@@ -63,40 +64,46 @@ export class CustomOrgUnitTreesComponent implements OnInit {
         }
     }
 
-    async loadCustomTree(): Promise<any> {
-
-        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<any> {
+               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) {