From d95bd1df4c2b1f4a8c239bce9ce2459b0e24281b Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Sat, 6 Apr 2019 11:05:47 -0700 Subject: [PATCH] LP1816475: add a route to specific resource barcode Signed-off-by: Jane Sandberg --- .../booking/create-reservation.component.html | 2 +- .../staff/booking/create-reservation.component.ts | 60 +++++++++++++++++----- .../eg2/src/app/staff/booking/routing.module.ts | 9 ++-- 3 files changed, 54 insertions(+), 17 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 b8d1e095c5..9e74df388a 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 @@ -51,7 +51,7 @@
- +
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 ef6682a331..e3a6ac95aa 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,4 +1,6 @@ import { Component, Input, OnInit, AfterViewInit, QueryList, ViewChildren, ViewChild } from '@angular/core'; +import {Router, ActivatedRoute, ParamMap} from '@angular/router'; +import {single} from 'rxjs/operators'; import { NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap'; import { AuthService } from '@eg/core/auth.service'; import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; @@ -29,6 +31,10 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { isBooked: (col: any, row: any) => string; resourceAvailabilityIcon: (row: any) => GridRowFlairEntry; + patronId: number; + resourceBarcode: string; + resourceId: number; + startOfDay: NgbTimeStruct = {hour: 9, minute: 0, second: 0}; endOfDay: NgbTimeStruct = {hour: 17, minute: 0, second: 0}; startTime: Moment; @@ -39,6 +45,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { resources: IdlObject[] = []; limitByAttr: (attributeId: number, $event: ComboboxEntry) => void; + useCurrentResourceBarcode: () => void; setGranularity: () => void; handleMultiDayReservation: () => void; @@ -54,6 +61,8 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { private auth: AuthService, private format: FormatService, private pcrud: PcrudService, + private route: ActivatedRoute, + private router: Router, private store: ServerStoreService, private toast: ToastService, ) { @@ -72,6 +81,23 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { ngOnInit() { + this.route.paramMap.subscribe((params: ParamMap) => { + this.patronId = +params.get('patron_id'); + this.resourceBarcode = params.get('resource_barcode'); + + if (this.resourceBarcode) { + this.pcrud.search('brsrc', + {'barcode' : this.resourceBarcode}, {'limit': 1}) + .pipe(single()) + .subscribe((res) => { + this.resourceId = res.id(); + this.fetchData('resource', this.resourceId); + }, (err) => { + this.resourceId = -1; + this.toast.danger('No resource found with this barcode'); + }); + } + }); this.isBooked = (row: any, col: any) => { if ((col.name !== 'time') && (row[col.name])) { @@ -93,25 +119,25 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { if (granularity != null) { this.granularity = granularity; } }); } - this.scheduleGrids.forEach((g) => g.reload()); + this.scheduleGrids.forEach((g) => g.reload()); }; - this.handleDateChange = ($event: Date) => { + this.handleDateChange = ($event: Date) => { this.pcrud.retrieve('aouhoo', this.auth.user().ws_ou()) .subscribe(hours => { const startArray = hours['dow_' + ($event.getDay() + 6) % 7 + '_open']().split(':'); const endArray = hours['dow_' + ($event.getDay() + 6) % 7 + '_close']().split(':'); this.startOfDay = { - hour: ('00' == startArray[0]) ? 9 : +startArray[0], + hour: ('00' === startArray[0]) ? 9 : +startArray[0], minute: +startArray[1], second: 0}; this.endOfDay = { - hour: ('00' == endArray[0]) ? 17 : +endArray[0], + hour: ('00' === endArray[0]) ? 17 : +endArray[0], minute: +endArray[1], second: 0}; this.scheduleGrids.forEach((g) => g.reload()); }); - } + }; this.handleMultiDayReservation = () => { this.multiday = true; @@ -128,6 +154,13 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { this.store.setItem('eg.booking.create.granularity', $event.id); }; + this.useCurrentResourceBarcode = () => { + if (this.resourceBarcode) { + this.router.navigate(['/staff', 'booking', 'create_reservation', 'for_resource', this.resourceBarcode]); + } + }; + + } ngAfterViewInit() { @@ -139,13 +172,14 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { return this.newDialog.open({size: 'lg'}).then( ok => { this.toast.success('Reservation successfully created'); // TODO: needs i18n, pluralization - this.scheduleGrids.forEach((g) => g.reload()); + this.scheduleGrids.forEach((g) => g.reload()); }, err => {} ); } handleResourceTypeChange(event: ComboboxEntry) { - // TODO: unset resource barcode + this.resourceBarcode = null; + this.resourceId = null; this.attributes = []; if (event.id) { this.pcrud.search('bra', {resource_type : event.id}, { @@ -168,15 +202,15 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { if ('type' === limiter) { where = {type: id}; } else if ('resource' === limiter) { - where = {id: id}; + where = {id: this.resourceId}; } this.scheduleSource.data = []; this.pcrud.search('brsrc', where, { order_by: 'barcode ASC', flesh: 2, flesh_fields: {'brsrc': ['curr_rsrcs'], 'bresv': ['usr']}, - select: {'curr_rsrcs': {'end_time': {'>' : Moment([], this.format.wsOrgTimezone).startOf('day').toISOString()}, - 'start_time': {'<': Moment([], this.format.wsOrgTimezone).add(1,'days').endOf('day').toISOString()}}} + select: {'curr_rsrcs': {'end_time': {'>' : Moment([], this.format.wsOrgTimezone).startOf('day').toISOString()}, + 'start_time': { '<': Moment([], this.format.wsOrgTimezone).add(1, 'days').endOf('day').toISOString() }}} }).subscribe( r => { this.resources.push(r); @@ -185,15 +219,15 @@ export class CreateReservationComponent implements OnInit, AfterViewInit { this.startTime = Moment.tz([ dl.current.year, dl.current.month - 1, - dl.current.day, + dl.current.day, this.startOfDay.hour, this.startOfDay.minute], this.format.wsOrgTimezone); this.endTime = Moment.tz([ dl.current.year, dl.current.month - 1, - dl.current.day, - this.endOfDay.hour, + dl.current.day, + this.endOfDay.hour, this.endOfDay.minute], this.format.wsOrgTimezone); }); diff --git a/Open-ILS/src/eg2/src/app/staff/booking/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/booking/routing.module.ts index a13375e31c..bc12e96a45 100644 --- a/Open-ILS/src/eg2/src/app/staff/booking/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/booking/routing.module.ts @@ -7,6 +7,12 @@ import {PullListComponent} from './pull-list.component'; import {ReturnComponent} from './return.component'; const routes: Routes = [{ + path: 'create_reservation', + children: [ + {path: '', component: CreateReservationComponent}, + {path: 'for_patron/:patron_id', component: CreateReservationComponent}, + {path: 'for_resource/:resource_barcode', component: CreateReservationComponent}, + ]}, { path: 'manage_reservations', children: [ {path: '', component: ManageReservationsComponent}, @@ -14,9 +20,6 @@ const routes: Routes = [{ {path: 'by_resource/:resource_barcode', component: ManageReservationsComponent}, {path: 'by_resource_type/:resource_type_id', component: ManageReservationsComponent}, ]}, { - path: 'create_reservation', - component: CreateReservationComponent - }, { path: 'pickup', children: [ {path: '', component: PickupComponent}, -- 2.11.0