LP1830432 Uniqify reported org IDs / sandbox tweaks
authorBill Erickson <berickxx@gmail.com>
Fri, 5 Jul 2019 15:18:59 +0000 (11:18 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 10 Jul 2019 17:55:46 +0000 (13:55 -0400)
Err on the side of caution and ensure the org family selector always
reports a unique list of org unit IDs.

Sandbox language tweaks.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts

index 6fd1790..3e1e6e8 100644 (file)
@@ -110,14 +110,18 @@ export class OrgFamilySelectComponent implements ControlValueAccessor, OnInit {
             }
 
             if (this.includeDescendants.value) {
-                // can result in duplicate workstation org IDs... meh
                 this.options.orgIds = this.options.orgIds.concat(
                     this.org.descendants(this.options.primaryOrgId, true));
             }
 
+            // Using ancestors() and descendants() can result in
+            // duplicate org ID's.  Be nice and uniqify.
+            const hash: any = {};
+            this.options.orgIds.forEach(id => hash[id] = true);
+            this.options.orgIds = Object.keys(hash).map(id => Number(id));
+
             this.propagateChange(this.options);
         };
-
     }
 
     writeValue(value: OrgFamily) {
index fa58e90..38908ae 100644 (file)
       <div class="card-text">
         <eg-org-family-select
           formControlName="badOrgSelector"
-          labelText="Choose the worst libraries">
+          labelText="Choose the fanciest libraries">
         </eg-org-family-select>
-       <div *ngIf="!badOrgForm.valid" class="alert alert-danger">
+        <div *ngIf="!badOrgForm.valid" class="alert alert-danger">
           <span class="material-icons">error</span>
-          <span i18n>Too many bad libraries!</span>
+          <span i18n>Too many fancy libraries!</span>
         </div>
       </div>
     </div>
index 17c6e6d..52931a0 100644 (file)
@@ -94,7 +94,7 @@ export class SandboxComponent implements OnInit {
                 {'id': 4, 'includeAncestors': false, 'includeDescendants': true}, (c: FormControl) => {
                     // An Angular custom validator
                     if (c.value.orgIds && c.value.orgIds.length > 5) {
-                        return { tooMany: 'That\'s too many bad libraries!' };
+                        return { tooMany: 'That\'s too many fancy libraries!' };
                     } else {
                         return null;
                     }
@@ -102,7 +102,7 @@ export class SandboxComponent implements OnInit {
         });
 
         this.badOrgForm.get('badOrgSelector').valueChanges.subscribe(bad => {
-            this.toast.danger('The worst libraries are: ' + JSON.stringify(bad.orgIds));
+            this.toast.danger('The fanciest libraries are: ' + JSON.stringify(bad.orgIds));
         });
 
         this.gridDataSource.data = [