From a2a501ee37a1741a0200d32dbc3894a539feafc3 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Sun, 7 Apr 2019 23:08:51 -0700 Subject: [PATCH] LP1816475: handle narrow by attribute Signed-off-by: Jane Sandberg --- .../booking/create-reservation.component.html | 3 +- .../staff/booking/create-reservation.component.ts | 40 ++++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.html b/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.html index 575baf76c7..642022f5a7 100644 --- a/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.html +++ b/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.html @@ -143,7 +143,7 @@ + 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"> @@ -201,4 +201,3 @@ - diff --git a/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts b/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts index 9c58a3af33..2bd472db07 100644 --- a/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts @@ -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 => { -- 2.11.0