Includes general purpose discard/weed dialog.
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jennifer Weston <jennifer.weston@equinoxOLI.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
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';
declarations: [
MarkDamagedDialogComponent,
MarkMissingDialogComponent,
+ MarkDiscardDialogComponent,
CopyAlertsDialogComponent,
CopyTagsDialogComponent,
CopyNotesDialogComponent,
exports: [
MarkDamagedDialogComponent,
MarkMissingDialogComponent,
+ MarkDiscardDialogComponent,
CopyAlertsDialogComponent,
CopyTagsDialogComponent,
CopyNotesDialogComponent,
--- /dev/null
+
+
+<eg-string #successMsg
+ text="Successfully Marked Item Discard" i18n-text></eg-string>
+<eg-string #errorMsg
+ text="Failed To Mark Item Discard" i18n-text></eg-string>
+
+<ng-template #dialogContent>
+ <div class="modal-header bg-info">
+ <h4 class="modal-title">
+ <span i18n>Mark Item Discard</span>
+ </h4>
+ <button type="button" class="close"
+ i18n-aria-label aria-label="Close" (click)="close()">
+ <span aria-hidden="true">×</span>
+ </button>
+ </div>
+ <div class="modal-body">
+ <div class="row d-flex justify-content-center">
+ <h5>Mark {{copyIds.length}} Item(s) Discard?</h5>
+ </div>
+ <div class="row" *ngIf="numSucceeded > 0">
+ <div class="col-lg-12" i18n>
+ {{numSucceeded}} Items(s) Successfully Marked Discard
+ </div>
+ </div>
+ <div class="row" *ngIf="numFailed > 0">
+ <div class="col-lg-12">
+ <div class="alert alert-warning">
+ {{numFailed}} Items(s) Failed to be Marked Discard
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="modal-footer">
+ <ng-container *ngIf="!chargeResponse">
+ <button type="button" class="btn btn-warning"
+ (click)="close()" i18n>Cancel</button>
+ <button type="button" class="btn btn-success"
+ (click)="markItemsDiscard()" i18n>Mark Discard</button>
+ </ng-container>
+ </div>
+ </ng-template>
+
--- /dev/null
+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<boolean> {
+ this.numSucceeded = 0;
+ this.numFailed = 0;
+ return super.open(args);
+ }
+
+ markOneItemDiscard(id: number): Observable<any> {
+
+ 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<any> {
+ this.numSucceeded = 0;
+ this.numFailed = 0;
+
+ return from(this.copyIds)
+ .pipe(concatMap(copyId => this.markOneItemDiscard(copyId)))
+ .toPromise().then(_ => this.close(this.numSucceeded > 0));
+ }
+}
+
+
+
<eg-hold-transfer-dialog #transferDialog></eg-hold-transfer-dialog>
<eg-mark-damaged-dialog #markDamagedDialog></eg-mark-damaged-dialog>
<eg-mark-missing-dialog #markMissingDialog></eg-mark-missing-dialog>
+<eg-mark-discard-dialog #markDiscardDialog></eg-mark-discard-dialog>
<eg-hold-retarget-dialog #retargetDialog></eg-hold-retarget-dialog>
<eg-hold-cancel-dialog #cancelDialog></eg-hold-cancel-dialog>
<eg-hold-manage-dialog #manageDialog></eg-hold-manage-dialog>
</eg-grid-toolbar-action>
<eg-grid-toolbar-action
+ i18n-group group="Item" i18n-label label="Mark Item Discard/Weed"
+ (onClick)="showMarkDiscardDialog($event)">
+ </eg-grid-toolbar-action>
+
+ <eg-grid-toolbar-action
i18n-group group="Hold" i18n-label label="Find Another Target"
(onClick)="showRetargetDialog($event)"></eg-grid-toolbar-action>
} 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';
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 })
}
}
+ 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) {