LP1919465 Pull List Mark Discard/Weed Action
authorBill Erickson <berickxx@gmail.com>
Tue, 14 Sep 2021 15:04:10 +0000 (11:04 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Fri, 24 Sep 2021 19:21:13 +0000 (15:21 -0400)
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>
Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/share/holdings/mark-discard-dialog.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts

index d8272ba..5845cb6 100644 (file)
@@ -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 (file)
index 0000000..b93dfeb
--- /dev/null
@@ -0,0 +1,44 @@
+
+
+<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">&times;</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>
+  
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 (file)
index 0000000..588be12
--- /dev/null
@@ -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<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));
+    }
+}
+
+
+
index 69a8076..3b553f1 100644 (file)
@@ -5,6 +5,7 @@
 <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>
 
index 3ee5ca4..630f363 100644 (file)
@@ -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) {