fetchData () {
this.resources = [];
- let select = {};
let where = {};
if (this.resourceId) {
return;
}
- if (this.multiday) {
- this.dateRangeLimiters.forEach((drl) => { select = {
- 'curr_rsrcs': {'end_time': {'>' : Moment.tz([drl.fromDate.year, drl.fromDate.month - 1, drl.fromDate.day],
- this.format.wsOrgTimezone).startOf('day').toISOString()},
- 'start_time': { '<': Moment.tz([drl.toDate.year, drl.toDate.month - 1, drl.toDate.day],
- this.format.wsOrgTimezone).endOf('day').toISOString() }}};
- });
- } else { 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', 'attr_maps'], 'bresv': ['usr']},
- select: select
+ flesh: 1,
+ flesh_fields: {'brsrc': ['attr_maps']},
}).subscribe(
r => {
this.resources.push(r);
let startTime = Moment();
let endTime = Moment();
+ let reservations = [];
+
if (this.multiday) {
this.dateRangeLimiters.forEach((drl) => {
startTime = Moment.tz([drl.fromDate.year, drl.fromDate.month - 1, drl.fromDate.day],
this.format.wsOrgTimezone);
});
}
- const currentTime = startTime;
- while (currentTime < endTime) {
- let idx: number;
- let existingRow: number;
- if (this.multiday) {
- existingRow = this.scheduleSource.data.findIndex(
- (row) => row['time'] === this.format.transform({value: currentTime, datatype: 'timestamp'}));
- idx = (existingRow > -1) ? existingRow :
- (this.scheduleSource.data.push(
- {'time': this.format.transform({value: currentTime, datatype: 'timestamp'})}) - 1);
- } else {
- existingRow = this.scheduleSource.data.findIndex((row) => row['time'] === currentTime.format('LT')) ;
- idx = (existingRow > -1) ? existingRow : (this.scheduleSource.data.push({'time': currentTime.format('LT')}) - 1);
- }
- r.curr_rsrcs().forEach((reservation) => {
- if ((Moment(reservation.start_time(), this.format.wsOrgTimezone) <
- (currentTime.clone().add(this.granularity, 'minutes'))) &&
- (Moment(reservation.end_time(), this.format.wsOrgTimezone) > currentTime)) {
- if (!this.scheduleSource.data[idx][r.barcode()]) { this.scheduleSource.data[idx][r.barcode()] = []; }
- this.scheduleSource.data[idx][r.barcode()].push(
- {'patronLabel': reservation.usr().usrname(), 'patronId': reservation.usr().id()});
+ this.pcrud.search('bresv', {
+ '-or': {'target_resource': r.id(), 'current_resource': r.id()},
+ 'end_time': {'>': startTime.toISOString()},
+ 'start_time': {'<': endTime.toISOString()},
+ 'return_time': null,
+ 'cancel_time': null },
+ {'flesh': 1, 'flesh_fields': {'bresv': ['usr']}})
+ .subscribe((res) => {reservations.push(res);},
+ (err) => {console.warn(err);},
+ () => {
+ const currentTime = startTime;
+ while (currentTime < endTime) {
+ let idx: number;
+ let existingRow: number;
+ if (this.multiday) {
+ existingRow = this.scheduleSource.data.findIndex(
+ (row) => row['time'] === this.format.transform({value: currentTime, datatype: 'timestamp'}));
+ idx = (existingRow > -1) ? existingRow :
+ (this.scheduleSource.data.push(
+ {'time': this.format.transform({value: currentTime, datatype: 'timestamp'})}) - 1);
+ } else {
+ existingRow = this.scheduleSource.data.findIndex((row) => row['time'] === currentTime.format('LT')) ;
+ idx = (existingRow > -1) ? existingRow : (this.scheduleSource.data.push({'time': currentTime.format('LT')}) - 1);
}
- });
- currentTime.add(this.granularity, 'minutes');
- }
+ reservations.forEach((reservation) => {
+ if ((Moment.tz(reservation.start_time(), this.format.wsOrgTimezone) <
+ (currentTime.clone().add(this.granularity, 'minutes'))) &&
+ (Moment.tz(reservation.end_time(), this.format.wsOrgTimezone) > currentTime)) {
+ if (!this.scheduleSource.data[idx][r.barcode()]) { this.scheduleSource.data[idx][r.barcode()] = []; }
+ this.scheduleSource.data[idx][r.barcode()].push(
+ {'patronLabel': reservation.usr().usrname(), 'patronId': reservation.usr().id()});
+ }
+ });
+ currentTime.add(this.granularity, 'minutes');
+ }
+ });
});
}
}
-