boom
authorJason Etheridge <phasefx@gmail.com>
Mon, 15 May 2023 13:52:16 +0000 (09:52 -0400)
committerJason Etheridge <phasefx@gmail.com>
Thu, 25 May 2023 16:45:33 +0000 (12:45 -0400)
Signed-off-by: Jason Etheridge <phasefx@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/custom-org-unit-trees.component.ts

index a614679..ddd48c6 100644 (file)
@@ -1,11 +1,11 @@
 <eg-staff-banner bannerText="Custom Org Unit Trees" i18n-bannerText>
 </eg-staff-banner>
 
-<ng-template #editStrTmpl i18n>Update Succeeded</ng-template>
-<eg-string #editString [template]="editStrTmpl"></eg-string>
+<ng-template #successStrTmpl i18n>Update Succeeded</ng-template>
+<eg-string #successString [template]="successStrTmpl"></eg-string>
 
-<ng-template #errorStrTmpl i18n>Update Failed</ng-template>
-<eg-string #errorString [template]="errorStrTmpl"></eg-string>
+<ng-template #updateFailedStrTmpl i18n>Update Failed</ng-template>
+<eg-string #updateFailedString [template]="updateFailedStrTmpl"></eg-string>
 
 <eg-confirm-dialog #delConfirm
   i18n-dialogTitle i18n-dialogBody
index e4db7d4..52f05ab 100644 (file)
@@ -1,11 +1,11 @@
 import {Component, ViewChild, OnInit} from '@angular/core';
-import {catchError, firstValueFrom, of, take, defaultIfEmpty} from 'rxjs';
+import {catchError, firstValueFrom, lastValueFrom, 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';
 import {OrgService} from '@eg/core/org.service';
 import {PcrudService} from '@eg/core/pcrud.service';
-//import {ToastService} from '@eg/share/toast/toast.service';
+import {ToastService} from '@eg/share/toast/toast.service';
 import {StringComponent} from '@eg/share/string/string.component';
 //import {StringService} from '@eg/share/string/string.service';
 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
@@ -34,6 +34,8 @@ export class CustomOrgUnitTreesComponent implements OnInit {
 
     @ViewChild('editString', { static: true }) editString: StringComponent;
     @ViewChild('errorString', { static: true }) errorString: StringComponent;
+    @ViewChild('successString', { static: true }) successString: StringComponent;
+    @ViewChild('updateFailedString', { static: true }) updateFailedString: StringComponent;
     @ViewChild('delConfirm', { static: true }) delConfirm: ConfirmDialogComponent;
     @ViewChild('moveNodeElsewhereDialog', { static: true }) moveNodeElsewhereDialog: CustomOrgUnitTreesDialogComponent;
 
@@ -42,7 +44,7 @@ export class CustomOrgUnitTreesComponent implements OnInit {
         private org: OrgService,
         private pcrud: PcrudService,
         //private strings: StringService,
-        //private toast: ToastService
+        private toast: ToastService
     ) {}
 
 
@@ -95,11 +97,12 @@ export class CustomOrgUnitTreesComponent implements OnInit {
         let tree_id: number;
         if (this.tree_type) {
             tree_id = this.tree_type.id();
-            this.active = this.tree_type.active();
+            this.active = this.tree_type.active() === 't';
         } else {
             tree_id = null;
         }
 
+        this.aouctn_root = undefined;
         if (tree_id) {
             this.aouctn_root = await firstValueFrom(
                 this.pcrud.search('aouctn', {tree: tree_id, parent_node: null},
@@ -113,13 +116,16 @@ export class CustomOrgUnitTreesComponent implements OnInit {
                     })
                 )
             );
-            this.ingestCustomTree(this.aouctn_root); // sets this.custom_tree as a side-effect
         } else {
-            console.log('prior to clone: ' + this.tree, this.tree);
-            this.custom_tree = this.tree.clone();
             this.tree_type = this.idl.create('aouct');
             this.tree_type.isnew('t');
             this.tree_type.purpose('opac');
+            this.tree_type.active(this.active ? 't' : 'f');
+        }
+        if (this.aouctn_root) {
+            this.ingestCustomTree(this.aouctn_root); // sets this.custom_tree as a side-effect
+        } else {
+            this.custom_tree = this.tree.clone();
         }
         return this.custom_tree;
     }
@@ -404,8 +410,8 @@ export class CustomOrgUnitTreesComponent implements OnInit {
     }
 
        async applyChanges() {
-               if (this.active !== this.tree_type.active()) {
-                       this.tree_type.active(this.active);
+               if (this.active !== (this.tree_type.active() === 't')) {
+                       this.tree_type.active(this.active ? 't' : 'f');
                        this.tree_type.ischanged('t');
                }
                try {
@@ -415,17 +421,28 @@ export class CustomOrgUnitTreesComponent implements OnInit {
                                await firstValueFrom(this.pcrud.update(this.tree_type));
                        }
                        await this.createNewNodes(this.custom_tree.rootNode);
+            this.successString.current().then(str => this.toast.success(str));
+
                } catch (error) {
                        console.error('Error applying changes:', error);
+            this.updateFailedString.current().then(str => this.toast.danger(str));
                }
        }
 
        async createNewNodes(node: any, parent_id: number = null, order: number = 0) {
+        // delete the existing custom nodes for the custom tree
+        // TODO: this is what the dojo interface did, but do we really need so much churn?
+        // TODO: we may want to move this to an OpenSRF method so we can wrap the entire
+        //       delete and create into a single transaction
+        if (this.aouctn_root) {
+            await lastValueFrom(this.pcrud.remove(this.aouctn_root));
+            this.aouctn_root = null;
+        }
                let newNode = this.idl.create('aouctn');
                newNode.parent_node(parent_id);
                newNode.sibling_order(order);
-               newNode.org_unit = node.callerData.orgId;
-               newNode.tree = this.tree_type.id();
+               newNode.org_unit(node.callerData.orgId);
+               newNode.tree(this.tree_type.id());
 
                // Send the new node to the server and get back the updated node
                newNode = await firstValueFrom(this.pcrud.create(newNode));