Adding a working, sortable grid to current reservations
authorJane Sandberg <sandbej@linnbenton.edu>
Mon, 10 Dec 2018 20:27:32 +0000 (12:27 -0800)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 23 Jan 2019 23:08:13 +0000 (15:08 -0800)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/booking/current-reservations.component.html
Open-ILS/src/eg2/src/app/staff/booking/current-reservations.component.ts

index 10f7453..8c61c50 100644 (file)
@@ -1,9 +1,14 @@
-<p>
-  current-reservations works!
-</p>
-<eg-grid #grid idlClass="bresv"
-[sortable]="true" persistKey="booking.current-reservations-grid">
-<eg-grid-column path="usr"></eg-grid-column>
-<eg-grid-column path="capture_time"></eg-grid-column>
-<eg-grid-column path="return_time"></eg-grid-column>
+{{gridSource | json }}
+<eg-staff-banner bannerText="Current Reservations" i18n-bannerText>
+</eg-staff-banner>
+
+<eg-grid [dataSource]="gridSource"
+  [sortable]="true" persistKey="booking.current_reservations" >
+  <eg-grid-column name="id" [hidden]="true" [index]="true" i18n-label label="ID" path="id"></eg-grid-column>
+  <eg-grid-column i18n-label path="usr"></eg-grid-column>
+  <eg-grid-column name="start_time" label="Start Time" i18n-label path="start_time"></eg-grid-column>
+  <eg-grid-column name="end_time" label="End Time" i18n-label path="end_time"></eg-grid-column>
+  <eg-grid-column name="capture_time" label="Capture Time" i18n-label path="capture_time"></eg-grid-column>
+
 </eg-grid>
+
index d6c9503..563125d 100644 (file)
@@ -1,4 +1,8 @@
 import { Component, OnInit } from '@angular/core';
+import { GridDataSource } from '@eg/share/grid/grid';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {Pager} from '@eg/share/util/pager';
+import { Router, ActivatedRoute, ParamMap } from '@angular/router';
 
 @Component({
   selector: 'eg-current-reservations',
@@ -6,9 +10,34 @@ import { Component, OnInit } from '@angular/core';
 })
 export class CurrentReservationsComponent implements OnInit {
 
-  constructor() { }
+  gridSource: GridDataSource;
+  patronId: number;
+
+  constructor(
+    private route: ActivatedRoute,
+    private pcrud: PcrudService
+  ){
+    this.gridSource = new GridDataSource();
+
+    this.gridSource.getRows = (pager: Pager, sort: any[]) => {
+      const orderBy: any = {};
+      if (sort.length) {
+         orderBy.bresv = sort[0].name + ' ' + sort[0].dir;
+      }
+      return this.pcrud.search('bresv', {"usr" : (this.patronId ? this.patronId : {">" : 1})}, {   
+        order_by: orderBy,
+        limit: pager.limit,
+        offset: pager.offset
+      });
+    }
+  }
 
   ngOnInit() {
+    this.route.paramMap.subscribe((params: ParamMap) => {
+      this.patronId = +params.get('patron_id');
+    });
   }
 
+
 }
+