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';
ngOnInit() {
this.loadAouTree(this.org.root().id());
this.loadCustomTree();
+ console.log('component this', this);
}
async loadAouTree(selectNodeId?: number): Promise<any> {
}
}
- 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) {