LP1878079 Staffcat 'Edit' items / call numbers support
authorBill Erickson <berickxx@gmail.com>
Wed, 13 May 2020 16:17:19 +0000 (12:17 -0400)
committerJane Sandberg <sandbej@linnbenton.edu>
Mon, 27 Jul 2020 16:52:23 +0000 (09:52 -0700)
Adds support to the Angular staff catalog to properly handle requests
to Edit Items, Edit Call Numbers, and Edit Call Numbers and Items.
Prior to his change, these operations would behave more like Add
operations than Edit operations.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.html
Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.service.ts

index bed7a4e..4ba485c 100644 (file)
 
     <eg-grid-toolbar-action
       i18n-group group="Add" i18n-label label="Add Call Numbers"
-      (onClick)="openHoldingEdit($event, true, false)">
+      (onClick)="openHoldingAdd($event, true, false)">
     </eg-grid-toolbar-action>
 
     <eg-grid-toolbar-action
       i18n-group group="Add" i18n-label label="Add Items"
-      (onClick)="openHoldingEdit($event, false, true)">
+      (onClick)="openHoldingAdd($event, false, true)">
     </eg-grid-toolbar-action>
 
     <eg-grid-toolbar-action
       i18n-group group="Add" i18n-label label="Add Call Numbers and Items"
-      (onClick)="openHoldingEdit($event, true, true)">
+      (onClick)="openHoldingAdd($event, true, true)">
     </eg-grid-toolbar-action>
 
     <eg-grid-toolbar-action
 
     <eg-grid-toolbar-action
       i18n-group group="Edit" i18n-label label="Edit Call Numbers"
-      (onClick)="openHoldingEdit($event, true, false)">
+      (onClick)="openHoldingEdit($event, false, true)">
     </eg-grid-toolbar-action>
 
     <eg-grid-toolbar-action
       i18n-group group="Edit" i18n-label label="Edit Call Numbers And Items"
-      (onClick)="openHoldingEdit($event, true, true)">
+      (onClick)="openHoldingEdit($event, false, false)">
     </eg-grid-toolbar-action>
 
     <eg-grid-toolbar-action
       i18n-group group="Edit" i18n-label label="Edit Items"
-      (onClick)="openHoldingEdit($event, false, true)">
+      (onClick)="openHoldingEdit($event, true, false)">
     </eg-grid-toolbar-action>
     
     <eg-grid-toolbar-action
index cf20449..f96bb3a 100644 (file)
@@ -592,12 +592,22 @@ export class HoldingsMaintenanceComponent implements OnInit {
 
     // Which copies in the grid are selected.
     selectedCopyIds(rows: HoldingsEntry[], skipStatus?: number): number[] {
+        return this.selectedCopies(rows, skipStatus).map(c => Number(c.id()));
+    }
+
+    selectedVolIds(rows: HoldingsEntry[]): number[] {
+        return rows
+            .filter(r => Boolean(r.callNum))
+            .map(r => Number(r.callNum.id()));
+    }
+
+    selectedCopies(rows: HoldingsEntry[], skipStatus?: number): IdlObject[] {
         let copyRows = rows.filter(r => Boolean(r.copy)).map(r => r.copy);
         if (skipStatus) {
             copyRows = copyRows.filter(
                 c => Number(c.status().id()) !== Number(skipStatus));
         }
-        return copyRows.map(c => Number(c.id()));
+        return copyRows;
     }
 
     selectedCallNumIds(rows: HoldingsEntry[]): number[] {
@@ -725,7 +735,32 @@ export class HoldingsMaintenanceComponent implements OnInit {
         .then(key => this.openAngJsWindow(`cat/printlabels/${key}`));
     }
 
-    openHoldingEdit(rows: HoldingsEntry[], addCallNums: boolean, addCopies: boolean) {
+    openHoldingEdit(rows: HoldingsEntry[], hideVols: boolean, hideCopies: boolean) {
+
+        // Avoid adding call number edit entries for call numbers
+        // that are already represented by selected items.
+
+        const copies = this.selectedCopies(rows);
+        const copyVols = copies.map(c => Number(c.call_number()));
+
+        const volIds = [];
+        this.selectedVolIds(rows).forEach(id => {
+            if (!copyVols.includes(id)) {
+                volIds.push(id);
+            }
+        });
+
+        this.holdings.spawnAddHoldingsUi(
+            this.recordId,
+            volIds,
+            null,
+            copies.map(c => Number(c.id())),
+            hideCopies,
+            hideVols
+        );
+    }
+
+    openHoldingAdd(rows: HoldingsEntry[], addCallNums: boolean, addCopies: boolean) {
 
         // The user may select a set of call numbers by selecting call
         // number and/or item rows.  Owning libs for new call numbers may
@@ -740,7 +775,10 @@ export class HoldingsMaintenanceComponent implements OnInit {
                 callNums.push(r.treeNode.parentNode.target);
 
             } else if (r.treeNode.nodeType === 'org') {
-                orgs[r.treeNode.target.id()] = true;
+                const org = r.treeNode.target;
+                if (org.ou_type().can_have_vols() === 't') {
+                    orgs[org.id()] = true;
+                }
             }
         });
 
@@ -767,7 +805,7 @@ export class HoldingsMaintenanceComponent implements OnInit {
             }
 
             this.holdings.spawnAddHoldingsUi(
-                this.recordId, null, entries, !addCopies);
+                this.recordId, null, entries, null, !addCopies);
         }
     }
 
index 3c703e6..bb11b1f 100644 (file)
@@ -24,26 +24,28 @@ export class HoldingsService {
 
     // Open the holdings editor UI in a new browser window/tab.
     spawnAddHoldingsUi(
-        recordId: number,               // Bib record ID
-        addToCallNums?: number[],           // Add copies to / modify existing CNs
-        callNumData?: NewCallNumData[],   // Creating new call numbers
-        hideCopies?: boolean) {         // Hide the copy edit pane
+        recordId: number,                  // Bib record ID
+        editExistingCallNums?: number[],   // Add copies to / modify existing CNs
+        newCallNumData?: NewCallNumData[], // Creating new call numbers
+        editCopyIds?: number[],            // Edit existing items
+        hideCopies?: boolean,              // Hide the copy edit pane
+        hideVols?: boolean) {
 
         const raw: any[] = [];
 
-        if (addToCallNums) {
-            addToCallNums.forEach(callNumId => raw.push({callnumber: callNumId}));
-        } else if (callNumData) {
-            callNumData.forEach(data => raw.push(data));
+        if (editExistingCallNums) {
+            editExistingCallNums.forEach(
+                callNumId => raw.push({callnumber: callNumId}));
+        } else if (newCallNumData) {
+            newCallNumData.forEach(data => raw.push(data));
         }
 
-        if (raw.length === 0) { raw.push({}); }
-
         this.anonCache.setItem(null, 'edit-these-copies', {
             record_id: recordId,
             raw: raw,
-            hide_vols : false,
-            hide_copies : hideCopies ? true : false
+            copies: editCopyIds,
+            hide_vols : hideVols === true,
+            hide_copies : hideCopies === true
         }).then(key => {
             if (!key) {
                 console.error('Could not create holds cache key!');