LP1816475: handle narrow by attribute
authorJane Sandberg <sandbej@linnbenton.edu>
Mon, 8 Apr 2019 06:08:51 +0000 (23:08 -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/create-reservation.component.html
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts

index 575baf7..642022f 100644 (file)
 <eg-fm-record-editor #newDialog
   idlClass="bresv"
   [fieldOptions]="{usr:{customTemplate:{template:patronTemplate}},start_time:{customTemplate:{template:datetimeWithDefaults}},end_time:{customTemplate:{template:datetimeWithDefaults}},pickup_lib:{customTemplate:{template:pickupLibrary}},target_resource:{customTemplate:{template:targetResource}}}"
-  hiddenFields="id,xact_start,request_time,capture_time,pickup_time,return_time,capture_staff,xact_finish,cancel_time,booking_interval,target_resource,unrecovered,request_lib,fine_interval,fine_amount,max_fine,target_resource,target_resource_type">
+  hiddenFields="id,xact_start,request_time,capture_time,pickup_time,return_time,capture_staff,xact_finish,cancel_time,booking_interval,unrecovered,request_lib,fine_interval,fine_amount,max_fine,current_resource,target_resource_type">
 </eg-fm-record-editor>
 
 <ng-template #reservationsTemplate let-row="row" let-col="col">
     </eg-combobox>
   </ng-container>
 </ng-template>
-
index 9c58a3a..2bd472d 100644 (file)
@@ -1,5 +1,6 @@
 import {Component, Input, OnInit, AfterViewInit, QueryList, ViewChildren, ViewChild} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {forkJoin} from 'rxjs';
 import {single} from 'rxjs/operators';
 import {NgbDateStruct, NgbTimeStruct} from '@ng-bootstrap/ng-bootstrap';
 import {AuthService} from '@eg/core/auth.service';
@@ -10,7 +11,7 @@ import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
 import {FormatService} from '@eg/core/format.service';
 import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource,  GridRowFlairEntry} from '@eg/share/grid/grid';
-import {IdlObject} from '@eg/core/idl.service';
+import {IdlObject, IdlService} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {OrgService} from '@eg/core/org.service';
 import {PatronService} from '@eg/staff/share/patron.service';
@@ -30,6 +31,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
 
     advancedCollapsed = true;
     attributes: IdlObject[] = [];
+    selectedAttributes: number[] = [];
     multiday = false;
     handleDateChange: ($event: Date) => void;
     resourceAvailabilityIcon: (row: any) => GridRowFlairEntry;
@@ -80,6 +82,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
     constructor(
         private auth: AuthService,
         private format: FormatService,
+        private idl: IdlService,
         private net: NetService,
         private org: OrgService,
         private patron: PatronService,
@@ -147,9 +150,8 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
         });
 
         this.limitByAttr = (attributeId: number, $event: ComboboxEntry) => {
-            console.log('LIMIT');
-            console.log('id: ' + attributeId);
-            console.log('event: ' + JSON.stringify($event));
+            this.selectedAttributes[attributeId] = $event.id;
+            this.fetchData();
         };
 
         this.setGranularity = () => {
@@ -271,7 +273,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
             } else {
                 if (this.multiday) { this.defaultTimes['end_time'] = this.defaultTimes['start_time'].clone().add(1, 'days'); }
             }
-            if (this.resourceId) {
+            if (this.resourceId && !this.resourceTypeId) {
                 this.pcrud.search('brsrc', {id: this.resourceId}, {
                     flesh: 1,
                     limit: 1,
@@ -286,10 +288,24 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
                 this.pcrud.search('brt', {id: this.resourceTypeId}, {
                 }).subscribe( t => {
                     this.transferable = t.transferable();
-                    this.openTheDialog(rows).then(
-                        newId => { this.net.request('open-ils.storage', 'open-ils.storage.booking.reservation.resource_targeter', [newId]); }
-                    );
-                });
+                    this.openTheDialog(rows).then(newId => {
+                        if (this.selectedAttributes.length) {
+                            let creates$ = [];
+                            this.selectedAttributes.forEach(attrValue => {
+                                if (attrValue) {
+                                    const bravm = this.idl.create('bravm');
+                                    bravm.attr_value(attrValue);
+                                    bravm.reservation(newId);
+                                    creates$.push(this.pcrud.create(bravm));
+                                }
+                            });
+                            forkJoin(...creates$).subscribe(() => {
+                            this.net.request('open-ils.storage', 'open-ils.storage.booking.reservation.resource_targeter', [newId]); });
+                        } else {
+                            this.net.request('open-ils.storage', 'open-ils.storage.booking.reservation.resource_targeter', [newId]);
+                        }
+                    });
+                })
             }
         }
     }
@@ -298,6 +314,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
         this.resourceId = null;
         this.resourceTypeId = $event.id;
         this.attributes = [];
+        this.selectedAttributes = [];
         if (this.resourceTypeId) {
             this.pcrud.search('bra', {resource_type : this.resourceTypeId}, {
                 order_by: 'name ASC',
@@ -335,11 +352,14 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
             select = {'curr_rsrcs': {'end_time': {'>' : Moment.tz([this.idealDate.getFullYear(), this.idealDate.getMonth(), this.idealDate.getDate()], this.format.wsOrgTimezone).startOf('day').toISOString()},
                 'start_time': { '<': Moment.tz([this.idealDate.getFullYear(), this.idealDate.getMonth(), this.idealDate.getDate()], this.format.wsOrgTimezone).add(1, 'days').endOf('day').toISOString() }}}
         }
+        if (this.selectedAttributes.length) {
+            where['id'] = {"in": {"from": "bram", "select": {"bram": ["resource"]}, "where": {"value":  this.selectedAttributes.filter((a) => (a !== null))}}};
+        }
         this.scheduleSource.data = [];
         this.pcrud.search('brsrc', where, {
             order_by: 'barcode ASC',
             flesh: 2,
-            flesh_fields: {'brsrc': ['curr_rsrcs'], 'bresv': ['usr']},
+            flesh_fields: {'brsrc': ['curr_rsrcs', 'attr_maps'], 'bresv': ['usr']},
             select: select
         }).subscribe(
             r => {