LP#1981095: fix deletion of item tags in Angular item attributes editor
authorGalen Charlton <gmc@equinoxOLI.org>
Fri, 8 Jul 2022 16:46:40 +0000 (12:46 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Jul 2022 14:21:36 +0000 (10:21 -0400)
This patch fixes several bugs that prevent item tags from
being correctly deleted by the Angular item attributes editor.

To test
-------
[1] Apply patch.
[2] Edit a single item in the Angular item attributes editor.
[3] Verify that tags can be added and deleted.
[4] In Holdings View, choose Add/Manage Item Tags for a single
    selected item.
[5] Verify that tags can be added and deleted;
[6] Repeat steps 4 and 5 for a different item after successfully
    deleting an item tag. Verify that tags can be added and deleted.
[7] In Holdings View, choose Add/Manage Item Tags for multiple
    selected items.
[8] Verify that ntoes can be added to the selected items

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/copy-tags-dialog.component.ts

index 41adfb5..51621ae 100644 (file)
@@ -442,14 +442,17 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
         this.copyTagsDialog.inPlaceCreateMode = true;
         this.copyTagsDialog.copyIds = this.context.copyList().map(c => c.id());
 
-        this.copyTagsDialog.open({size: 'lg'}).subscribe(newTags => {
-            if (!newTags || newTags.length === 0) { return; }
+        this.copyTagsDialog.open({size: 'lg'}).subscribe(changes => {
+            if ((!changes.newTags || changes.newTags.length === 0) &&
+                (!changes.deletedMaps || changes.deletedMaps.length === 0)) {
+                return;
+            }
 
-            newTags.forEach(tag => {
+            changes.newTags.forEach(tag => {
                 this.context.copyList().forEach(copy => {
 
                     if (copy.tags().filter(
-                        m => m.tag().id() === tag.id()).length > 0) {
+                        m => m.tag() === tag.id()).length > 0) {
                         return; // map already exists
                     }
 
@@ -462,6 +465,17 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
                     copy.ischanged(true);
                 });
             });
+
+            if (this.context.copyList().length === 1) {
+                const copy = this.context.copyList()[0];
+                changes.deletedMaps.forEach(tag => {
+                    const existing = copy.tags().filter(t => t.id() === tag.id())[0];
+                    if (existing) {
+                        existing.isdeleted(true);
+                        copy.ischanged(true);
+                    }
+                });
+            }
         });
     }
 
index 62fa86f..922cc1e 100644 (file)
@@ -956,8 +956,8 @@ export class HoldingsMaintenanceComponent implements OnInit {
 
         this.copyTagsDialog.copyIds = copyIds;
         this.copyTagsDialog.open({size: 'lg'}).subscribe(
-            modified => {
-                if (modified) {
+            changes => {
+                if (changes.newTags.length > 0 || changes.deletedMaps.length > 0) {
                     this.hardRefresh();
                 }
             }
index c62d28b..820691d 100644 (file)
@@ -17,6 +17,11 @@ import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
  * Dialog for managing copy tags.
  */
 
+export interface CopyTagChanges {
+    newTags: IdlObject[];
+    deletedMaps: IdlObject[];
+}
+
 @Component({
   selector: 'eg-copy-tags-dialog',
   templateUrl: 'copy-tags-dialog.component.html'
@@ -89,7 +94,7 @@ export class CopyTagsDialogComponent
 
     /**
      */
-    open(args: NgbModalOptions): Observable<IdlObject[]> {
+    open(args: NgbModalOptions): Observable<CopyTagChanges> {
         this.copy = null;
         this.copies = [];
         this.newTags = [];
@@ -101,8 +106,8 @@ export class CopyTagsDialogComponent
 
         // In manage mode, we can only manage a single copy.
         // But in create mode, we can add tags to multiple copies.
-
-        if (this.copyIds.length === 1 && !this.inPlaceCreateMode) {
+        // We can only manage copies that already exist in the database.
+        if (this.copyIds.length === 1 && this.copyIds[0] > 0) {
             this.mode = 'manage';
         } else {
             this.mode = 'create';
@@ -201,7 +206,7 @@ export class CopyTagsDialogComponent
     applyChanges() {
 
         if (this.inPlaceCreateMode) {
-            this.close(this.newTags);
+            this.close({ newTags: this.newTags, deletedMaps: this.deletedMaps });
             return;
         }
 
@@ -227,7 +232,7 @@ export class CopyTagsDialogComponent
 
         promise.then(_ => {
             this.successMsg.current().then(msg => this.toast.success(msg));
-            this.close(this.newTags.length > 0);
+            this.close({ newTags: this.newTags, deletedMaps: this.deletedMaps });
         });
     }
 }