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';
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;
resources: IdlObject[] = [];
limitByAttr: (attributeId: number, $event: ComboboxEntry) => void;
+ useCurrentResourceBarcode: () => void;
setGranularity: () => void;
handleMultiDayReservation: () => void;
private auth: AuthService,
private format: FormatService,
private pcrud: PcrudService,
+ private route: ActivatedRoute,
+ private router: Router,
private store: ServerStoreService,
private toast: ToastService,
) {
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])) {
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;
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() {
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}, {
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);
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);
});
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},
{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},