LP1888723 Item attributes editor can now clear stat cats
authorBill Erickson <berickxx@gmail.com>
Thu, 10 Sep 2020 21:38:10 +0000 (17:38 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Sun, 15 Aug 2021 23:55:17 +0000 (19:55 -0400)
Correctly implement stat cat copy map deletion in the Angular holdings
editor.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts

index 8284840..25a7b0d 100644 (file)
@@ -364,7 +364,7 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
 
         const entryId = this.statCatValues[catId];
 
-        if (!entryId || !this.volcopy.statCatEntryMap[entryId]) {
+        if (!clear && (!entryId || !this.volcopy.statCatEntryMap[entryId])) {
             console.warn(
                 `Attempt to apply stat cat value which does not exist.
                 This is likely the result of a stale copy template.
@@ -378,21 +378,34 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
             let entry = copy.stat_cat_entries()
                 .filter(e => e.stat_cat() === catId)[0];
 
-            if (entry) {
-                if (entry.id() === entryId) {
-                    // Requested mapping already exists.
-                    return;
+            if (clear) {
+
+                if (entry) {
+                    // Removing the entry map (and setting copy.ishanged) is
+                    // enough to tell the API to delete it.
+
+                    copy.stat_cat_entries(copy.stat_cat_entries()
+                        .filter(e => e.stat_cat() !== catId));
                 }
+
             } else {
 
-                // Copy has no entry for this stat cat yet.
-                entry = this.idl.create('asce');
-                entry.stat_cat(catId);
-                copy.stat_cat_entries().push(entry);
-            }
+                if (entry) {
+                    if (entry.id() === entryId) {
+                        // Requested mapping already exists.
+                        return;
+                    }
+                } else {
 
-            entry.id(entryId);
-            entry.value(this.volcopy.statCatEntryMap[entryId].value());
+                    // Copy has no entry for this stat cat yet.
+                    entry = this.idl.create('asce');
+                    entry.stat_cat(catId);
+                    copy.stat_cat_entries().push(entry);
+                }
+
+                entry.id(entryId);
+                entry.value(this.volcopy.statCatEntryMap[entryId].value());
+            }
 
             copy.ischanged(true);
         });