<div class="input-group-prepend">
<label class="input-group-text" for="ideal-reservation-date" i18n>Reservation date</label>
</div>
- <eg-date-select *ngIf="!multiday" #dateLimiter domId="ideal-reservation-date" (onChangeAsDate)="handleDateChange($event)"></eg-date-select>
+ <eg-date-select *ngIf="!multiday" #dateLimiter domId="ideal-reservation-date" (onChangeAsDate)="handleDateChange($event)" [initialDate]="today"></eg-date-select>
<eg-daterange-select *ngIf="multiday" #dateRangeLimiter></eg-daterange-select>
</div>
</div>
<div class="input-group-prepend">
<label class="input-group-text" for="ideal-resource-type" i18n>Resource type</label>
</div>
- <eg-resource-type-combobox domId="ideal-resource-type" (typeChanged)="handleResourceTypeChange($event)"></eg-resource-type-combobox>
+ <eg-resource-type-combobox #rt domId="ideal-resource-type" (typeChanged)="handleResourceTypeChange($event)"></eg-resource-type-combobox>
</div>
</div>
</div>
<span class="input-group-prepend">
<label class="input-group-text" for="start-time" i18n>Start time</label>
</span>
- <ngb-timepicker [(ngModel)]="startOfDay"></ngb-timepicker>
+ <ngb-timepicker [(ngModel)]="startOfDay" (ngModelChange)="fetchData()" [meridian]="true"></ngb-timepicker>
</span>
</li>
<li class="list-group-item">
<span class="input-group-prepend">
<label class="input-group-text" for="end-time" i18n>End time</label>
</span>
- <ngb-timepicker [(ngModel)]="endOfDay"></ngb-timepicker>
+ <ngb-timepicker [(ngModel)]="endOfDay" (ngModelChange)="fetchData()" [meridian]="true"></ngb-timepicker>
</span>
</li>
<li class="list-group-item">
import {IdlObject} from '@eg/core/idl.service';
import {NetService} from '@eg/core/net.service';
import {PcrudService} from '@eg/core/pcrud.service';
+import {ResourceTypeComboboxComponent} from './resource-type-combobox.component';
import {ServerStoreService} from '@eg/core/server-store.service';
import {ToastService} from '@eg/share/toast/toast.service';
patronId: number;
resourceBarcode: string;
resourceId: number;
+ resourceTypeId: number;
startOfDay: NgbTimeStruct = {hour: 9, minute: 0, second: 0};
endOfDay: NgbTimeStruct = {hour: 17, minute: 0, second: 0};
@ViewChildren('dateRangeLimiter') dateRangeLimiters: QueryList<DateRangeSelectComponent>;
@ViewChildren('scheduleGrid') scheduleGrids: QueryList<GridComponent>;
@ViewChild('newDialog') newDialog: FmRecordEditorComponent;
+ @ViewChild('rt') rt: ResourceTypeComboboxComponent;
+
+ today = new Date();
constructor(
private auth: AuthService,
.pipe(single())
.subscribe((res) => {
this.resourceId = res.id();
- this.fetchData('resource', this.resourceId);
+ this.fetchData();
}, (err) => {
this.pcrud.search('acp',
{'barcode' : this.resourceBarcode}, {'limit': 1})
this.auth.token(), [item.id()])
.subscribe((response) => {
this.toast.info('Made this barcode bookable');
- this.resourceId = response['id'];
+ this.resourceId = response['brsrc'][0][0];
}, (error) => {
this.toast.danger('Cannot make this barcode bookable');
})
if (granularity != null) { this.granularity = granularity; }
});
}
- this.scheduleGrids.forEach((g) => g.reload());
+ this.fetchData();
};
this.handleDateChange = ($event: Date) => {
hour: ('00' === endArray[0]) ? 17 : +endArray[0],
minute: +endArray[1],
second: 0};
- this.scheduleGrids.forEach((g) => g.reload());
+ this.fetchData();
});
};
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.fetchData();
},
err => {}
);
}
- handleResourceTypeChange(event: ComboboxEntry) {
+ handleResourceTypeChange($event: ComboboxEntry) {
this.resourceBarcode = null;
this.resourceId = null;
+ this.resourceTypeId = $event.id;
this.attributes = [];
- if (event.id) {
- this.pcrud.search('bra', {resource_type : event.id}, {
+ if (this.resourceTypeId) {
+ this.pcrud.search('bra', {resource_type : this.resourceTypeId}, {
order_by: 'name ASC',
flesh: 1,
flesh_fields: {'bra' : ['valid_values']}
}, err => {
console.debug(err);
}, () => {
- this.fetchData('type', event.id);
+ this.fetchData();
});
}
}
- fetchData (limiter: 'resource' | 'type', id: number) {
+ fetchData () {
this.resources = [];
let where = {};
- if ('type' === limiter) {
- where = {type: id};
- } else if ('resource' === limiter) {
+ if (this.resourceId) {
where = {id: this.resourceId};
+ } else if (this.resourceTypeId) {
+ where = {type: this.resourceTypeId};
+ } else {
+ return;
}
this.scheduleSource.data = [];
this.pcrud.search('brsrc', where, {
}
+
-import { Component, EventEmitter, OnInit, Input, Output } from '@angular/core';
+import {Component, EventEmitter, OnInit, Input, Output, ViewChild} from '@angular/core';
import {PcrudService} from '@eg/core/pcrud.service';
+import {ComboboxComponent} from '@eg/share/combobox/combobox.component';
import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
@Component({
selector: 'eg-resource-type-combobox',
template: `<eg-combobox
+ #resourceTypeCombobox
[attr.id]="domId"
placeholder="Resource type" i18n-placeholder
[entries]="resourceTypes"
resourceTypes: ComboboxEntry[];
+ clear: () => void;
+
@Input() domId = '';
@Input() startId: number;
@Output() typeChanged: EventEmitter<ComboboxEntry>;
+ @ViewChild('resourceTypeCombobox') resourceTypeCombobox: ComboboxComponent;
+
constructor(private pcrud: PcrudService) {
this.typeChanged = new EventEmitter<ComboboxEntry>();
}
if (!this.resourceTypes) { this.resourceTypes = []; }
this.resourceTypes.push({id: type.id(), label: type.name()});
});
+ this.clear = () => {
+ this.resourceTypeCombobox.selected = {id: '', label: ''};
+ };
}
}
+