LP1884950 Org service loads all ou types
authorBill Erickson <berickxx@gmail.com>
Wed, 6 Jul 2022 20:35:28 +0000 (16:35 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 25 Jul 2022 16:24:59 +0000 (12:24 -0400)
Explicitly load all org unit types at page startup so that we fetch org
types that may not have an org unit attached.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Dawn Dale <ddale@georgialibraries.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/eg2/src/app/core/org.service.ts

index bf98630..cc8e4cd 100644 (file)
@@ -175,17 +175,10 @@ export class OrgService {
         if (!node) {
             node = this.orgTree;
             this.orgMap = {};
-            this.orgList = [];
-            this.orgTypeMap = {};
         }
         this.orgMap[node.id()] = node;
         this.orgList.push(node);
 
-        this.orgTypeMap[node.ou_type().id()] = node.ou_type();
-        if (!this.orgTypeList.filter(t => t.id() === node.ou_type().id())[0]) {
-            this.orgTypeList.push(node.ou_type());
-        }
-
         node.children().forEach(c => this.absorbTree(c));
     }
 
@@ -194,10 +187,22 @@ export class OrgService {
      * various shapes, then returns an "all done" promise.
      */
     fetchOrgs(): Promise<void> {
-        return this.pcrud.search('aou', {parent_ou : null},
-            {flesh : -1, flesh_fields : {aou : ['children', 'ou_type']}},
-            {anonymous : true}
-        ).toPromise().then(tree => {
+
+        // Grab org types separately so we are guaranteed to fetch types
+        // that are not yet in use by an org unit.
+        return this.pcrud.retrieveAll(
+            'aout', {}, {anonymous: true, atomic: true}).toPromise()
+        .then(types => {
+            this.orgTypeList = types;
+            types.forEach(t => this.orgTypeMap[Number(t.id())] = t);
+
+            return this.pcrud.search('aou', {parent_ou : null},
+                {flesh : -1, flesh_fields : {aou : ['children', 'ou_type']}},
+                {anonymous : true}
+            ).toPromise()
+        })
+
+        .then(tree => {
             // ingest tree, etc.
             this.orgTree = tree;
             this.absorbTree();