LP1904036 Renew with due date
authorBill Erickson <berickxx@gmail.com>
Mon, 1 Mar 2021 16:19:07 +0000 (11:19 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:24 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/share/circ/due-date-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/circ/due-date-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/share/circ/grid.component.html
Open-ILS/src/eg2/src/app/staff/share/circ/grid.component.ts

index b991ef7..04b8709 100644 (file)
         </eg-datetime-select>
       </div>
     </div>
-
     <div class="row mt-3" *ngIf="!dueDateIso">
       <div class="col-lg-12 alert-danger" i18n>
         Selected due date is not valid.
       </div>
     </div>
-
-    <div class="row mt-3" *ngIf="numSucceeded > 0">
-      <div class="col-lg-12" i18n>
-        {{numSucceeded}} Due Date(s) Successfully Modified
-      </div>
-    </div>
-    <div class="row mt-3" *ngIf="numFailed > 0">
-      <div class="col-lg-12">
-        <div class="alert alert-warning">
-          {{numFailed}} Due Date(s) Failed to Modify
-        </div>
-      </div>
-    </div>
   </div>
   <div class="modal-footer">
     <button type="button" class="btn btn-success" [disabled]="!dueDateIso"
-      (click)="modifyBatch()" i18n>Modify</button>
+      (click)="close(dueDateIso)" i18n>Modify</button>
     <button type="button" class="btn btn-warning"
       (click)="close()" i18n>Cancel</button>
   </div>
index 60ced72..7ce8b91 100644 (file)
@@ -27,8 +27,6 @@ export class DueDateDialogComponent
 
     dueDateIsValid = false;
     dueDateIso: string;
-    numSucceeded: number;
-    numFailed: number;
     nowTime: number;
 
     constructor(
@@ -43,8 +41,6 @@ export class DueDateDialogComponent
 
     ngOnInit() {
         this.onOpen$.subscribe(_ => {
-            this.numSucceeded = 0;
-            this.numFailed = 0;
             this.dueDateIso = new Date().toISOString();
             this.nowTime = new Date().getTime();
         });
@@ -57,39 +53,4 @@ export class DueDateDialogComponent
             this.dueDateIso = null;
         }
     }
-
-    modifyBatch() {
-        if (!this.dueDateIso) { return; }
-
-        let promise = Promise.resolve();
-
-        this.circs.forEach(circ => {
-            promise = promise.then(_ => this.modifyOne(circ));
-        });
-
-        promise.then(_ => {
-            this.close();
-            this.circs = [];
-        });
-    }
-
-    modifyOne(circ: IdlObject): Promise<any> {
-        return this.net.request(
-            'open-ils.circ',
-            'open-ils.circ.circulation.due_date.update',
-            this.auth.token(), circ.id(), this.dueDateIso
-
-        ).toPromise().then(modCirc => {
-
-            const evt = this.evt.parse(modCirc);
-
-            if (evt) {
-                this.numFailed++;
-                console.error(evt);
-            } else {
-                this.numSucceeded++;
-                this.respond(modCirc);
-            }
-        });
-    }
 }
index ea95618..b89311a 100644 (file)
     i18n-label label="Renew All" (onClick)="renewAll()">
   </eg-grid-toolbar-action>
 
+  <eg-grid-toolbar-action group="Circulation" i18n-group 
+    i18n-label label="Renew With Specific Due Date"
+    (onClick)="renewWithDate($event)">
+  </eg-grid-toolbar-action>
+
   <eg-grid-column [index]="true" path="index" [hidden]="true"
     label="Row Index" i18n-label></eg-grid-column>
 
index dba0088..81e327e 100644 (file)
@@ -317,26 +317,35 @@ export class CircGridComponent implements OnInit {
     }
 
     editDueDate(rows: any) {
-        const circs = this.getCircs(rows);
-        if (circs.length === 0) { return; }
-
-        let refreshNeeded = false;
-        this.dueDateDialog.circs = circs;
-        this.dueDateDialog.open().subscribe(
-            circ => {
-                refreshNeeded = true;
-                const row = rows.filter(r => r.circ.id() === circ.id())[0];
-                row.circ.due_date(circ.due_date());
-                row.dueDate = circ.due_date();
-                delete row.overdue; // it will recalculate
-            },
-            err => console.error(err),
-            () => {
-                if (refreshNeeded) {
-                    this.reloadGrid();
+        const ids = this.getCircIds(rows);
+        if (ids.length === 0) { return; }
+
+        this.dueDateDialog.open().subscribe(isoDate => {
+            if (!isoDate) { return; } // canceled
+
+            const dialog = this.openProgressDialog(rows);
+
+            from(ids).pipe(concatMap(id => {
+                return this.net.request(
+                    'open-ils.circ',
+                    'open-ils.circ.circulation.due_date.update',
+                    this.auth.token(), id, isoDate
+                );
+            })).subscribe(
+                circ => {
+                    const row = rows.filter(r => r.circ.id() === circ.id())[0];
+                    row.circ.due_date(circ.due_date());
+                    row.dueDate = circ.due_date();
+                    delete row.overdue; // it will recalculate
+                    dialog.increment();
+                },
+                err  => console.log(err),
+                ()   => {
+                    dialog.close();
+                    this.emitReloadRequest();
                 }
-            }
-        );
+            );
+        });
     }
 
     circIsOverdue(row: CircGridEntry): boolean {
@@ -431,6 +440,34 @@ export class CircGridComponent implements OnInit {
         );
     }
 
+    renewWithDate(rows: any) {
+        const ids = this.getCopyIds(rows);
+        if (ids.length === 0) { return; }
+
+        this.dueDateDialog.open().subscribe(isoDate => {
+            if (!isoDate) { return; } // canceled
+
+            const dialog = this.openProgressDialog(rows);
+            const params: CheckoutParams = {due_date: isoDate};
+
+            let refreshNeeded = false;
+            this.circ.renewBatch(ids).subscribe(
+                resp => {
+                    if (resp.success) { refreshNeeded = true; }
+                    dialog.increment();
+                },
+                err => console.error(err),
+                () => {
+                    dialog.close();
+                    if (refreshNeeded) {
+                        this.emitReloadRequest();
+                    }
+                }
+            );
+        });
+    }
+
+
     // Same params will be used for each copy
     checkin(rows: CircGridEntry[], params?:
         CheckinParams, noReload?: boolean): Observable<CheckinResult> {