LP1816475: Fixing the return screens
authorJane Sandberg <sandbej@linnbenton.edu>
Mon, 1 Apr 2019 17:03:05 +0000 (10:03 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 17 Apr 2019 20:32:12 +0000 (13:32 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.html
Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.ts
Open-ILS/src/eg2/src/app/staff/booking/return.component.html
Open-ILS/src/eg2/src/app/staff/booking/return.component.ts

index 9fd3187..93288f7 100644 (file)
@@ -40,7 +40,7 @@
   idlClass="bresv"
   datetimeFields="start_time,end_time"
   hiddenFields="xact_finish,cancel_time,booking_interval"
-  [fieldOptions]="{start_time:{validator:startTimeShouldBeFuture}}"
+  [fieldOptions]="{start_time:{validator:startTimeShouldBeFuture},end_time:{validator:endTimeShouldBeAfterStartTime}}"
   [readonlyFields]="listReadOnlyFields()">
 </eg-fm-record-editor>
 <eg-confirm-dialog #confirmCancelReservationDialog
index 8590cc0..2954430 100644 (file)
@@ -58,6 +58,7 @@ export class ReservationsGridComponent implements OnInit {
     listReadOnlyFields: () => string;
 
     startTimeShouldBeFuture: (fieldName: string, value: Moment, record: IdlObject) => string;
+    endTimeShouldBeAfterStartTime: (fieldName: string, value: Moment, record: IdlObject) => string;
 
     handleRowActivate: (row: IdlObject) => void;
 
@@ -247,6 +248,12 @@ export class ReservationsGridComponent implements OnInit {
             }
             return '';
         };
+        this.endTimeShouldBeAfterStartTime = (fieldName: string, value: Moment, record: IdlObject) => {
+            if (Moment(value) <= Moment(record['start_time'])) {
+                return 'End time must be after start time';
+            }
+            return '';
+        };
 
         this.handleRowActivate = (row: IdlObject) => {
             if (this.status) {
index 1cb7e68..eb903be 100644 (file)
@@ -2,7 +2,6 @@
 </eg-staff-banner>
 <eg-title i18n-prefix i18n-suffix prefix="Booking" suffix="Return"></eg-title>
 
-<!-- TODO: DRY This out: there has to be a good way to reuse the template -->
 <ngb-tabset (tabChange)="handleTabChange($event)" [activeId]="selectedTab">
   <ngb-tab title="By patron" i18n-title id="patron">
     <ng-template ngbTabContent>
       </div>
       <div *ngIf="patronId">
         <h2 class="text-center" i18n>Ready for return</h2>
-        <eg-reservations-grid #patronReady [patron]="patronId" status="returnReady" persistSuffix="return.patron.picked_up"></eg-reservations-grid>
+        <eg-reservations-grid #readyGrid [patron]="patronId" status="returnReady" (onReturn)="this.returnedGrid.reloadGrid()" persistSuffix="return.patron.picked_up"></eg-reservations-grid>
 
         <h2 class="text-center" i18n>Returned today</h2>
-        <eg-reservations-grid #patronReturned [patron]="patronId" status="returnedToday" persistSuffix="return.patron.returned"></eg-reservations-grid>
+        <eg-reservations-grid #returnedGrid [patron]="patronId" status="returnedToday" persistSuffix="return.patron.returned"></eg-reservations-grid>
       </div>
     </ng-template>
   </ngb-tab>
       </div>
       <div *ngIf="patronId">
         <h2 class="text-center" i18n>Ready for return</h2>
-        <eg-reservations-grid #resourceReady [resource]="patronId" status="returnReady" persistSuffix="return.resource.picked_up"></eg-reservations-grid>
+        <eg-reservations-grid #readyGrid [patron]="patronId" status="returnReady" (onReturn)="this.returnedGrid.reloadGrid()" persistSuffix="return.resource.picked_up"></eg-reservations-grid>
 
         <h2 class="text-center" i18n>Returned today</h2>
-        <eg-reservations-grid #resourceReturned [patron]="patronId" status="returnedToday" persistSuffix="return.resource.returned"></eg-reservations-grid>
+        <eg-reservations-grid #returnedGrid [patron]="patronId" status="returnedToday" persistSuffix="return.resource.returned"></eg-reservations-grid>
       </div>
     </ng-template>
   </ngb-tab>
 </ngb-tabset>
+
index b00a672..51054e2 100644 (file)
@@ -1,4 +1,4 @@
-import { Component, Input, OnInit, ViewChild } from '@angular/core';
+import { Component, Input, OnInit, QueryList, ViewChildren } from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
 import { NgbTabChangeEvent } from '@ng-bootstrap/ng-bootstrap';
 import {Observable} from 'rxjs';
@@ -29,10 +29,8 @@ export class ReturnComponent implements OnInit {
 
     noSelectedRows: (rows: IdlObject[]) => boolean;
     handleTabChange: ($event: NgbTabChangeEvent) => void;
-    @ViewChild('patronReady') patronReady: ReservationsGridComponent;
-    @ViewChild('patronReturned') patronReturned: ReservationsGridComponent;
-    @ViewChild('resourceReady') resourceReady: ReservationsGridComponent;
-    @ViewChild('resourceReturned') resourceReturned: ReservationsGridComponent;
+    @ViewChildren('readyGrid') readyGrids: QueryList<ReservationsGridComponent>;
+    @ViewChildren('returnedGrid') returnedGrids: QueryList<ReservationsGridComponent>;
 
     constructor(
         private auth: AuthService,
@@ -60,8 +58,8 @@ export class ReturnComponent implements OnInit {
                 }).subscribe(
                     (resp) => {
                         this.patronBarcode = resp.card().barcode();
-                        this.patronReady.reloadGrid();
-                        this.patronReturned.reloadGrid();
+                        this.readyGrids.forEach (readyGrid => readyGrid.reloadGrid());
+                        this.returnedGrids.forEach (returnedGrid => returnedGrid.reloadGrid());
                     }, (err) => { console.debug(err); }
                 );
             } else {
@@ -91,8 +89,8 @@ export class ReturnComponent implements OnInit {
                 }).subscribe((resp) => {
                     if (resp.curr_rsrcs()[0].usr()) {
                         this.patronId = resp.curr_rsrcs()[0].usr();
-                        this.resourceReady.reloadGrid();
-                        this.resourceReturned.reloadGrid();
+                        this.readyGrids.forEach (readyGrid => readyGrid.reloadGrid());
+                        this.returnedGrids.forEach (returnedGrid => returnedGrid.reloadGrid());
                     }
                 });
             }
@@ -100,12 +98,15 @@ export class ReturnComponent implements OnInit {
         this.noSelectedRows = (rows: IdlObject[]) => (rows.length === 0);
 
         this.handleTabChange = ($event) => {
-            this.store.setItem('eg.booking.return.tab', $event.nextId);
-            this.router.navigate(['/staff', 'booking', 'return']);
-            this.resourceBarcode = null;
-            this.patronBarcode = null;
-            this.patronId = null;
+            this.store.setItem('eg.booking.return.tab', $event.nextId)
+            .then(() => {
+                this.router.navigate(['/staff', 'booking', 'return']);
+                this.resourceBarcode = null;
+                this.patronBarcode = null;
+                this.patronId = null;
+            });
         };
 
     }
 }
+