From 8d61829a5d437be66b0a2b28264f80347ebb1111 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 14 Sep 2021 11:04:10 -0400 Subject: [PATCH] LP1919465 Pull List Mark Discard/Weed Action Includes general purpose discard/weed dialog. Signed-off-by: Bill Erickson Signed-off-by: Jennifer Weston Signed-off-by: Chris Sharp --- .../app/staff/share/holdings/holdings.module.ts | 3 + .../holdings/mark-discard-dialog.component.html | 44 ++++++++++++ .../holdings/mark-discard-dialog.component.ts | 79 ++++++++++++++++++++++ .../src/app/staff/share/holds/grid.component.html | 6 ++ .../src/app/staff/share/holds/grid.component.ts | 19 ++++++ 5 files changed, 151 insertions(+) create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts index d8272ba3cf..5845cb6d45 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts @@ -3,6 +3,7 @@ import {StaffCommonModule} from '@eg/staff/common.module'; import {HoldingsService} from './holdings.service'; import {MarkDamagedDialogComponent} from './mark-damaged-dialog.component'; import {MarkMissingDialogComponent} from './mark-missing-dialog.component'; +import {MarkDiscardDialogComponent} from './mark-discard-dialog.component'; import {CopyAlertsDialogComponent} from './copy-alerts-dialog.component'; import {CopyTagsDialogComponent} from './copy-tags-dialog.component'; import {CopyNotesDialogComponent} from './copy-notes-dialog.component'; @@ -17,6 +18,7 @@ import {BatchItemAttrComponent} from './batch-item-attr.component'; declarations: [ MarkDamagedDialogComponent, MarkMissingDialogComponent, + MarkDiscardDialogComponent, CopyAlertsDialogComponent, CopyTagsDialogComponent, CopyNotesDialogComponent, @@ -33,6 +35,7 @@ import {BatchItemAttrComponent} from './batch-item-attr.component'; exports: [ MarkDamagedDialogComponent, MarkMissingDialogComponent, + MarkDiscardDialogComponent, CopyAlertsDialogComponent, CopyTagsDialogComponent, CopyNotesDialogComponent, diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.html new file mode 100644 index 0000000000..b93dfebe1b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.html @@ -0,0 +1,44 @@ + + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.ts new file mode 100644 index 0000000000..588be12f3b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.ts @@ -0,0 +1,79 @@ +import {Component, OnInit, Input, ViewChild} from '@angular/core'; +import {from, Observable, throwError} from 'rxjs'; +import {tap, concatMap} from 'rxjs/operators'; +import {NetService} from '@eg/core/net.service'; +import {EventService} from '@eg/core/event.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {AuthService} from '@eg/core/auth.service'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap'; +import {StringComponent} from '@eg/share/string/string.component'; + + +/** + * Dialog for marking items discard. + */ + +@Component({ + selector: 'eg-mark-discard-dialog', + templateUrl: 'mark-discard-dialog.component.html' +}) + +export class MarkDiscardDialogComponent + extends DialogComponent implements OnInit { + + @Input() copyIds: number[]; + + numSucceeded: number; + numFailed: number; + + @ViewChild('successMsg') private successMsg: StringComponent; + @ViewChild('errorMsg') private errorMsg: StringComponent; + + constructor( + private modal: NgbModal, // required for passing to parent + private toast: ToastService, + private net: NetService, + private evt: EventService, + private auth: AuthService) { + super(modal); // required for subclassing + } + + ngOnInit() {} + + open(args: NgbModalOptions): Observable { + this.numSucceeded = 0; + this.numFailed = 0; + return super.open(args); + } + + markOneItemDiscard(id: number): Observable { + + return this.net.request( + 'open-ils.circ', + 'open-ils.circ.mark_item_discard', + this.auth.token(), id + ).pipe(tap(result => { + if (Number(result) === 1) { + this.numSucceeded++; + this.successMsg.current().then(str => this.toast.success(str)); + } else { + this.numFailed++; + console.error('Mark discard failed ', this.evt.parse(result)); + this.errorMsg.current().then(str => this.toast.warning(str)); + } + })); + } + + markItemsDiscard(): Promise { + this.numSucceeded = 0; + this.numFailed = 0; + + return from(this.copyIds) + .pipe(concatMap(copyId => this.markOneItemDiscard(copyId))) + .toPromise().then(_ => this.close(this.numSucceeded > 0)); + } +} + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html index 69a807663b..3b553f1b75 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html @@ -5,6 +5,7 @@ + @@ -110,6 +111,11 @@ + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts index 3ee5ca456e..630f3638b9 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts @@ -13,6 +13,8 @@ import {MarkDamagedDialogComponent } from '@eg/staff/share/holdings/mark-damaged-dialog.component'; import {MarkMissingDialogComponent } from '@eg/staff/share/holdings/mark-missing-dialog.component'; +import {MarkDiscardDialogComponent + } from '@eg/staff/share/holdings/mark-discard-dialog.component'; import {HoldRetargetDialogComponent } from '@eg/staff/share/holds/retarget-dialog.component'; import {HoldTransferDialogComponent} from './transfer-dialog.component'; @@ -82,6 +84,8 @@ export class HoldsGridComponent implements OnInit { private markDamagedDialog: MarkDamagedDialogComponent; @ViewChild('markMissingDialog', { static: true }) private markMissingDialog: MarkMissingDialogComponent; + @ViewChild('markDiscardDialog') + private markDiscardDialog: MarkDiscardDialogComponent; @ViewChild('retargetDialog', { static: true }) private retargetDialog: HoldRetargetDialogComponent; @ViewChild('cancelDialog', { static: true }) @@ -527,6 +531,21 @@ export class HoldsGridComponent implements OnInit { } } + showMarkDiscardDialog(rows: any[]) { + const copyIds = rows.map(r => r.cp_id).filter(id => Boolean(id)); + if (copyIds.length > 0) { + this.markDiscardDialog.copyIds = copyIds; + this.markDiscardDialog.open({}).subscribe( + rowsModified => { + if (rowsModified) { + this.holdsGrid.reload(); + } + } + ); + } + } + + showRetargetDialog(rows: any[]) { const holdIds = rows.map(r => r.id).filter(id => Boolean(id)); if (holdIds.length > 0) { -- 2.11.0