LP1816475: Populating the Create grid with actual reservations
authorJane Sandberg <sandbej@linnbenton.edu>
Sun, 31 Mar 2019 23:04:53 +0000 (16:04 -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/create-reservation.component.html
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts

index 10fa30f..6a9777f 100644 (file)
   [dataSource]="scheduleSource"
   [rowFlairIsEnabled]="true"
   [rowFlairCallback]="resourceAvailabilityIcon"
-  disablePager="true"
-  disableSaveSettings="true"
+  [disablePager]="true"
+  [disableSaveSettings]="true"
   [cellClassCallback]="isBooked">
   <eg-grid-column path="time" [index]="true" ></eg-grid-column>
-  <eg-grid-column *ngFor="let resource of resources" path="{{resource.barcode()}}"></eg-grid-column>
+  <eg-grid-column *ngFor="let resource of resources" path="{{resource.barcode()}}" [cellTemplate]="reservationsTemplate"></eg-grid-column>
 </eg-grid>
 
 <eg-fm-record-editor #newDialog
   hiddenFields="id,xact_start,request_time,capture_time,pickup_time,return_time,capture_staff,xact_finish,cancel_time,booking_interval,target_resource,unrecovered,request_library,fine_interval,fine_amount,max_fine">
 </eg-fm-record-editor>
 
+<ng-template #reservationsTemplate let-row="row" let-col="col">
+  <ng-container *ngIf="row[col.name]">
+    <ul>
+      <li *ngFor="let reservation of row[col.name]">
+        <a href="staff/booking/manage_reservations/by_patron/{{reservation['patronId']}}">{{reservation['patronLabel']}}</a>
+      </li>
+    </ul>
+  </ng-container>
+</ng-template>
+
index 4aabdee..830d506 100644 (file)
@@ -107,33 +107,39 @@ export class CreateReservationComponent implements OnInit {
         } else if ('resource' === limiter) {
             where = {id: id};
         }
+        this.scheduleSource.data = [];
         this.pcrud.search('brsrc', where, {
             order_by: 'barcode ASC',
-            flesh: 1,
-            flesh_fields: {'brsrc': ['curr_rsrcs']},
-           select: {'curr_rsrcs': {'end_time': {'<' : '2019-04-01'}}} // TODO: make the time real using idlFormatDate; include all with an end time AFTER 12am AND start time BEFORE 11:59pm
+            flesh: 2,
+            flesh_fields: {'brsrc': ['curr_rsrcs'], 'bresv': ['usr']},
+           select: {'curr_rsrcs': {'end_time': {'>' : Moment([], 'Asia/Tokyo').startOf('day').toISOString()}, 'start_time': {'<': Moment([], 'Asia/Tokyo').add(1,'days').endOf('day').toISOString()}}}
         }).subscribe(
-            r => { this.resources.push(r); });
-
-        this.scheduleSource.data = [];
-        this.startTime = Moment(new Date(
-            this.dateLimiter.current.year,
-            this.dateLimiter.current.month - 1,
-            this.dateLimiter.current.day,
-            9, 0, 0), 'Asia/Tokyo');
-        this.endTime = Moment(new Date(
-            this.dateLimiter.current.year,
-            this.dateLimiter.current.month - 1,
-            this.dateLimiter.current.day,
-            17, 0, 0), 'Asia/Tokyo');
-        let currentTime = this.startTime;
-        while (currentTime < this.endTime) {
-            this.scheduleSource.data.push({
-                'time': currentTime.format('LT'),
-                'ROOM1231': 'Professor Pickle'
+            r => {
+                this.resources.push(r);
+
+                this.startTime = Moment(new Date(
+                    this.dateLimiter.current.year,
+                    this.dateLimiter.current.month - 1,
+                    this.dateLimiter.current.day,
+                    13, 0, 0), 'Asia/Tokyo');
+                this.endTime = Moment(new Date(
+                    this.dateLimiter.current.year,
+                    this.dateLimiter.current.month - 1,
+                    this.dateLimiter.current.day,
+                    17, 0, 0), 'Asia/Tokyo');
+                let currentTime = this.startTime;
+                while (currentTime < this.endTime) {
+                    const existingRow = this.scheduleSource.data.findIndex((row) => row['time'] === currentTime.format('LT')) ;
+                    const idx = (existingRow > -1) ? existingRow : (this.scheduleSource.data.push({'time': currentTime.format('LT')}) - 1);
+                    r.curr_rsrcs().forEach((reservation) => {
+                        if ((Moment(reservation.start_time(), 'Asia/Tokyo') < (currentTime + this.granularity)) && (Moment(reservation.end_time(), 'Asia/Tokyo') > currentTime)) {
+                            if (!this.scheduleSource.data[idx][r.barcode()]) { this.scheduleSource.data[idx][r.barcode()] = []; }
+                            this.scheduleSource.data[idx][r.barcode()].push({'patronLabel': reservation.usr().usrname(), 'patronId': reservation.usr().id()});
+                        }
+                    });
+                    currentTime.minute(currentTime.minute() + this.granularity);
+                }
             });
-            currentTime.minute(currentTime.minute() + this.granularity);
-        }
     }
 
 }