From cc9c27b8647b39c44a1270b74b65bbe1a044739a Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 8 Jul 2022 12:46:40 -0400 Subject: [PATCH] LP#1981095: fix deletion of item tags in Angular item attributes editor 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 Signed-off-by: Bill Erickson --- .../app/staff/cat/volcopy/copy-attrs.component.ts | 22 ++++++++++++++++++---- .../app/staff/catalog/record/holdings.component.ts | 4 ++-- .../share/holdings/copy-tags-dialog.component.ts | 15 ++++++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts index 41adfb5c36..51621aed39 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts @@ -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); + } + }); + } }); } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts index 62fa86f237..922cc1ef6f 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts @@ -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(); } } diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-tags-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-tags-dialog.component.ts index c62d28be86..820691de3b 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-tags-dialog.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-tags-dialog.component.ts @@ -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 { + open(args: NgbModalOptions): Observable { 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 }); }); } } -- 2.11.0