LP1816475: Make those org selects work
authorJane Sandberg <sandbej@linnbenton.edu>
Mon, 8 Apr 2019 21:31:32 +0000 (14:31 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 17 Apr 2019 20:41:53 +0000 (13:41 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/booking/booking.module.ts
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.html
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts
Open-ILS/src/eg2/src/app/staff/booking/manage-reservations.component.html
Open-ILS/src/eg2/src/app/staff/booking/manage-reservations.component.ts
Open-ILS/src/eg2/src/app/staff/booking/org-select-with-descendants.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.ts

index 079a190..b50654c 100644 (file)
@@ -3,6 +3,7 @@ import {StaffCommonModule} from '@eg/staff/common.module';
 import {BookingRoutingModule} from './routing.module';
 import {CreateReservationComponent} from './create-reservation.component';
 import {ManageReservationsComponent} from './manage-reservations.component';
+import {OrgSelectWithDescendantsComponent} from './org-select-with-descendants.component';
 import {ReservationsGridComponent} from './reservations-grid.component';
 import {PickupComponent} from './pickup.component';
 import {PullListComponent} from './pull-list.component';
@@ -22,6 +23,7 @@ import {PatronService} from '@eg/staff/share/patron.service';
         CreateReservationComponent,
         ManageReservationsComponent,
         NoTimezoneSetComponent,
+        OrgSelectWithDescendantsComponent,
         PickupComponent,
         PullListComponent,
         ReservationsGridComponent,
index ce0d0bc..bcb3726 100644 (file)
@@ -4,19 +4,8 @@
 
 <div class="row">
   <div class="col">
-    <div class="input-group">
-      <div class="input-group-prepend">
-        <label for="pickup-library" i18n class="input-group-text">Owning library</label>
-      </div>
-      <eg-org-select domId="owning-library">
-      </eg-org-select>
-    </div>
-  </div>
-  <div class="col">
-    <div class="form-check">
-      <input type="checkbox" class="form-check-input" id="include-descendants">
-      <label class="form-check-label" for="include-descendants" i18n>+ Descendants</label>
-    </div>
+    <eg-org-select-with-descendants labelText="Owning library" i18n-labelText (ouChange)="handleOwnerChange($event)">
+    </eg-org-select-with-descendants>
   </div>
   <div class="col">
     <div class="input-group">
index c3f821f..4454b7f 100644 (file)
@@ -35,8 +35,11 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
     selectedAttributes: number[] = [];
     multiday = false;
     handleDateChange: ($event: Date) => void;
+    handleOwnerChange: ($event: number[]) => void;
     resourceAvailabilityIcon: (row: any) => GridRowFlairEntry;
 
+    owningLibraries: number[] = [];
+
     patronBarcode: string;
     patronId: number;
     resourceBarcode: string;
@@ -109,6 +112,8 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
 
 
     ngOnInit() {
+        this.owningLibraries = [this.auth.user().ws_ou()];
+
         this.defaultTimes = {
             'start_time': Moment.tz([], this.format.wsOrgTimezone),
             'end_time': Moment.tz([], this.format.wsOrgTimezone).add(this.granularity, 'minutes')
@@ -186,6 +191,10 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
                 this.fetchData();
             });
         };
+        this.handleOwnerChange = ($event: number[]) => {
+            this.owningLibraries = $event;
+            this.fetchData();
+        }
 
         this.handleMultiDayReservation = () => {
             this.multiday = true;
@@ -343,12 +352,12 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
 
     fetchData () {
         this.resources = [];
-        let where = {};
+        let where = {'owner': this.owningLibraries};
 
         if (this.resourceId) {
-            where = {id: this.resourceId};
+            where['id'] = this.resourceId;
         } else if (this.resourceTypeId) {
-            where = {type: this.resourceTypeId};
+            where['type'] = this.resourceTypeId;
         } else {
             return;
         }
index 42ec2ca..9926147 100644 (file)
@@ -4,25 +4,10 @@
 
 <div class="card-body row">
   <div class="col-sm-3">
-    <div class="input-group">
-      <div class="input-group-prepend">
-        <label for="pickup-library" i18n class="input-group-text">Pickup library</label>
-      </div>
-      <eg-org-select domId="pickup-library">
-      </eg-org-select>
-    </div>
-  </div>
-  <div class="col-sm-3">
-    <div class="form-check">
-      <input type="checkbox" class="form-check-input" id="include-ancestors">
-      <label class="form-check-label" for="include-ancestors" i18n>+ Ancestors</label>
-    </div>
-    <div class="form-check">
-      <input type="checkbox" class="form-check-input" id="include-descendants">
-      <label class="form-check-label" for="include-descendants" i18n>+ Descendants</label>
-    </div>
+    <eg-org-select-with-descendants labelText="Pickup library" i18n-labelText (ouChange)="handlePickupLibChange($event)">
+    </eg-org-select-with-descendants>
   </div>
-  <div class="col-sm-6">
+  <div class="col-sm-6 offset-sm-3">
     <div class="card">
       <h2 class="card-header" i18n>Filter reservations</h2>
       <ngb-tabset #filters [activeId]="selectedFilter" (tabChange)="setStickyFilter($event)" class="mt-1">
@@ -84,5 +69,5 @@
     </div>
   </div>
 </div>
-<eg-reservations-grid #reservationsGrid [patron]="patronId" [resource]="resourceId" [resourceType]="resourceTypeId" persistSuffix="manage"></eg-reservations-grid>
+<eg-reservations-grid #reservationsGrid [patron]="patronId" [resource]="resourceId" [resourceType]="resourceTypeId" [pickupLibIds]="pickupLibIds" persistSuffix="manage"></eg-reservations-grid>
 
index da39573..5d225eb 100644 (file)
@@ -16,6 +16,7 @@ import {ToastService} from '@eg/share/toast/toast.service';
 })
 export class ManageReservationsComponent implements OnInit {
 
+    pickupLibIds: number[];
     patronBarcode: string;
     patronId: number;
     resourceBarcode: string;
@@ -25,6 +26,7 @@ export class ManageReservationsComponent implements OnInit {
 
     @ViewChild('reservationsGrid') reservationsGrid: ReservationsGridComponent;
 
+    handlePickupLibChange: ($event: number[]) => void;
     filterByCurrentPatronBarcode: () => void;
     filterByCurrentResourceBarcode: () => void;
     filterByResourceType: (selected: ComboboxEntry) => void;
@@ -84,6 +86,10 @@ export class ManageReservationsComponent implements OnInit {
             }
         });
 
+       this.handlePickupLibChange = ($event: number[]) => {
+            this.pickupLibIds = $event;
+            this.reservationsGrid.reloadGrid();
+        };
 
         this.setStickyFilter = ($event: NgbTabChangeEvent) => {
             this.store.setItem('eg.booking.manage.filter', $event.nextId);
diff --git a/Open-ILS/src/eg2/src/app/staff/booking/org-select-with-descendants.component.ts b/Open-ILS/src/eg2/src/app/staff/booking/org-select-with-descendants.component.ts
new file mode 100644 (file)
index 0000000..ffb2d39
--- /dev/null
@@ -0,0 +1,61 @@
+// TODO: Combine with the OU Selector from AdminPage to create a reusable component
+import {Component, EventEmitter, OnInit, Input, Output, ViewChild} from '@angular/core';
+import {AuthService} from '@eg/core/auth.service';
+import {IdlObject} from '@eg/core/idl.service';
+import {OrgService} from '@eg/core/org.service';
+
+@Component({
+    selector: 'eg-org-select-with-descendants',
+    template: ` <div class="input-group">
+      <div class="input-group-prepend">
+        <label [for]="domId" class="input-group-text">{{labelText}}</label>
+      </div>
+      <eg-org-select [domId]="domId" (onChange)="orgOnChange($event)"
+        [initialOrgId]="selectedOrg">
+      </eg-org-select>
+    </div>
+    <div class="form-check">
+      <input type="checkbox" class="form-check-input" id="{{domId}}-include-descendants"
+        (click)="emitArray()" [(ngModel)]="includeOrgDescendants">
+      <label class="form-check-label" for="{{domId}}-include-descendants" i18n>+ Descendants</label>
+    </div>`
+})
+export class OrgSelectWithDescendantsComponent implements OnInit {
+
+    @Input() labelText = 'Library';
+    @Output() ouChange: EventEmitter<number[]>;
+    domId: string;
+
+    selectedOrg: number;
+    includeOrgDescendants = true;
+
+    orgOnChange: ($event: IdlObject) => void;
+    emitArray: () => void;
+
+    constructor(
+        private auth: AuthService,
+        private org: OrgService
+    ) {
+        this.ouChange = new EventEmitter<number[]>();
+    }
+
+    ngOnInit() {
+        this.domId = 'org-select-' + Math.floor(Math.random() * 100000);
+        this.selectedOrg = this.auth.user().ws_ou();
+
+        this.orgOnChange = ($event: IdlObject) => {
+            this.selectedOrg = $event.id();
+            this.emitArray();
+        }
+
+        this.emitArray = () => {
+            if (this.includeOrgDescendants) {
+                this.ouChange.emit(this.org.descendants(this.selectedOrg, true));
+            } else {
+                this.ouChange.emit([this.selectedOrg]);
+            }
+        }
+    }
+
+}
+
index 0efad5d..28a30da 100644 (file)
@@ -30,6 +30,7 @@ export class ReservationsGridComponent implements OnInit {
     @Input() patron: number;
     @Input() resource: number;
     @Input() resourceType: number;
+    @Input() pickupLibIds: number[];
     @Input() status: 'pickupReady' | 'pickedUp' | 'returnReady' | 'returnedToday';
     @Input() persistSuffix: string;
     @Input() onlyCaptured = false;
@@ -105,6 +106,9 @@ export class ReservationsGridComponent implements OnInit {
             if (this.resource) {
                 where['current_resource'] = this.resource;
             }
+            if (this.pickupLibIds) {
+                where['pickup_lib'] = this.pickupLibIds;
+            }
             if (this.onlyCaptured) {
                 where['capture_time'] = {'!=': null};
             }