LP1956626 Copy editor loads all needed copy locations
authorBill Erickson <berickxx@gmail.com>
Tue, 19 Apr 2022 17:27:17 +0000 (13:27 -0400)
committerJane Sandberg <sandbergja@gmail.com>
Wed, 20 Apr 2022 05:01:16 +0000 (22:01 -0700)
The item-location-select component now allows the caller to pass in a
set of context org unit IDs (in lieu of just a single id) for loading
copy locations across different areas of the org unit tree (without
having to load *all* copy locations).

Changes applied to the Angular copy location editor to pass the needed
context org units to the item location select component.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts

index 4317500..9bbbc7a 100644 (file)
@@ -43,6 +43,20 @@ export class ItemLocationSelectComponent
         this.ngOnInit();
     }
 
+    get contextOrgId(): number {
+        return this._contextOrgId;
+    }
+
+    // Load locations for multiple context org units.
+    private _contextOrgIds = [];
+    @Input() set contextOrgIds(value: number[]) {
+        this._contextOrgIds = value;
+    }
+
+    get contextOrgIds(): number[] {
+        return this._contextOrgIds;
+    }
+
     @Input() orgUnitLabelField = 'shortname';
 
     // Emits an acpl object or null on combobox value change
@@ -163,11 +177,19 @@ export class ItemLocationSelectComponent
     }
 
     setFilterOrgs(): Promise<number[]> {
-        const org = this._contextOrgId || this.auth.user().ws_ou();
-        const contextOrgIds = this.org.ancestors(org, true);
+        let contextOrgIds: number[] = [];
+
+        if (this.contextOrgIds) {
+            contextOrgIds = this.contextOrgIds;
+        } else {
+            contextOrgIds = [this.contextOrgId || this.auth.user().ws_ou()];
+        }
+
+        let orgIds = [];
+        contextOrgIds.forEach(id => orgIds = orgIds.concat(this.org.ancestors(id, true)));
 
         if (!this.permFilter) {
-            return Promise.resolve(this.filterOrgs = contextOrgIds);
+            return Promise.resolve(this.filterOrgs = orgIds);
         }
 
         return this.perm.hasWorkPermAt([this.permFilter], true)
@@ -178,7 +200,7 @@ export class ItemLocationSelectComponent
             const permOrgIds = values[this.permFilter];
             const trimmedOrgIds = [];
             permOrgIds.forEach(orgId => {
-                if (contextOrgIds.includes(orgId)) {
+                if (orgIds.includes(orgId)) {
                     trimmedOrgIds.push(orgId);
                 }
             });
index ac1c123..dcee71d 100644 (file)
     <div *ngIf="displayAttr('location')">
       <ng-template #locationTemplate>
         <eg-item-location-select (valueChange)="values['location'] = $event"
+          [contextOrgIds]="affectedOrgIds()"
           domId='location-input' [required]="true" permFilter="UPDATE_COPY">
         </eg-item-location-select>
       </ng-template>
index 807d7ca..8b4c29b 100644 (file)
@@ -658,6 +658,11 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
         // click Apply for every one.
         this.batchAttrs.filter(attr => attr.editing).forEach(attr => attr.save());
     }
+
+    affectedOrgIds(): number[] {
+        if (!this.context) { return []; }
+        return this.context.orgNodes().map(n => n.target.id());
+    }
 }