) {}
- 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<any> {
{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);
}
}
- async loadCustomTree(): Promise<any> {
+ async loadCustomTree(purpose: string): Promise<any> {
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),
}
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.