LP1816475: add a route to specific resource barcode
authorJane Sandberg <sandbej@linnbenton.edu>
Sat, 6 Apr 2019 18:05:47 +0000 (11:05 -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
Open-ILS/src/eg2/src/app/staff/booking/routing.module.ts

index b8d1e09..9e74df3 100644 (file)
@@ -51,7 +51,7 @@
       <div class="input-group-prepend">
         <label class="input-group-text" for="ideal-resource-barcode" i18n>Resource barcode</label>
       </div>
-      <input type="text" id="ideal-resource-barcode" class="form-control" i18n-placeholder placeholder="Resource barcode">
+      <input type="text" id="ideal-resource-barcode" class="form-control" i18n-placeholder placeholder="Resource barcode" [(ngModel)]="resourceBarcode" (change)="useCurrentResourceBarcode()">
     </div>
   </div>
   <div class="col">
index ef6682a..e3a6ac9 100644 (file)
@@ -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);
                 });
index a13375e..bc12e96 100644 (file)
@@ -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},