|
|
@ -13,15 +13,13 @@ import {
|
|
|
|
finalize
|
|
|
|
finalize
|
|
|
|
} from 'rxjs/operators';
|
|
|
|
} from 'rxjs/operators';
|
|
|
|
|
|
|
|
|
|
|
|
import { GetDateTimePipe } from '../pipes/getdatetime.pipe';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { ScheduleService } from './schedule.service';
|
|
|
|
import { ScheduleService } from './schedule.service';
|
|
|
|
|
|
|
|
|
|
|
|
import { Slot } from '../models/slot';
|
|
|
|
import { Event } from '../models/event';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class ScheduleDataSource implements DataSource<Slot> {
|
|
|
|
export class ScheduleDataSource implements DataSource<Event> {
|
|
|
|
private scheduleSubject = new BehaviorSubject<Slot[]>([]);
|
|
|
|
private scheduleSubject = new BehaviorSubject<Event[]>([]);
|
|
|
|
private loadingSubject = new BehaviorSubject<boolean>(false);
|
|
|
|
private loadingSubject = new BehaviorSubject<boolean>(false);
|
|
|
|
private countdownSubject = new BehaviorSubject<number>(undefined);
|
|
|
|
private countdownSubject = new BehaviorSubject<number>(undefined);
|
|
|
|
|
|
|
|
|
|
|
@ -32,17 +30,15 @@ export class ScheduleDataSource implements DataSource<Slot> {
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private scheduleService: ScheduleService) { }
|
|
|
|
constructor(private scheduleService: ScheduleService) { }
|
|
|
|
|
|
|
|
|
|
|
|
loadSchedule(disabled: boolean) {
|
|
|
|
loadSchedule() {
|
|
|
|
this.loadingSubject.next(true);
|
|
|
|
this.loadingSubject.next(true);
|
|
|
|
|
|
|
|
|
|
|
|
this.scheduleService.getSchedule(disabled)
|
|
|
|
this.scheduleService.findEvents()
|
|
|
|
.pipe(
|
|
|
|
.pipe(
|
|
|
|
catchError(() => of([])),
|
|
|
|
catchError(() => of([])),
|
|
|
|
finalize(() => this.loadingSubject.next(false))
|
|
|
|
finalize(() => this.loadingSubject.next(false))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.subscribe((schedule: Slot[]) => {
|
|
|
|
.subscribe((schedule: Event[]) => {
|
|
|
|
schedule = this.sorted(schedule);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.scheduleSubject.next(schedule);
|
|
|
|
this.scheduleSubject.next(schedule);
|
|
|
|
|
|
|
|
|
|
|
|
timer(0, 1000).subscribe(() => {
|
|
|
|
timer(0, 1000).subscribe(() => {
|
|
|
@ -50,18 +46,7 @@ export class ScheduleDataSource implements DataSource<Slot> {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let nearest = (new GetDateTimePipe()).transform(schedule[0]);
|
|
|
|
let nearest = new Date(schedule[0].start + 'Z');
|
|
|
|
|
|
|
|
|
|
|
|
if (schedule.length > 1) {
|
|
|
|
|
|
|
|
let nearest2 = (new GetDateTimePipe()).transform(schedule[1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nearest.getTime() > nearest2.getTime()) {
|
|
|
|
|
|
|
|
schedule = this.sorted(schedule);
|
|
|
|
|
|
|
|
this.scheduleSubject.next(schedule);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let countdown = nearest.getTime() - Date.now();
|
|
|
|
let countdown = nearest.getTime() - Date.now();
|
|
|
|
let h = countdown - this.lastCountdown;
|
|
|
|
let h = countdown - this.lastCountdown;
|
|
|
|
|
|
|
|
|
|
|
@ -76,17 +61,7 @@ export class ScheduleDataSource implements DataSource<Slot> {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private sorted(schedule) {
|
|
|
|
connect(collectionViewer: CollectionViewer): Observable<Event[]> {
|
|
|
|
schedule.sort(function(a, b) {
|
|
|
|
|
|
|
|
a = (new GetDateTimePipe()).transform(a);
|
|
|
|
|
|
|
|
b = (new GetDateTimePipe()).transform(b);
|
|
|
|
|
|
|
|
return a.getTime() - b.getTime();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return schedule;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(collectionViewer: CollectionViewer): Observable<Slot[]> {
|
|
|
|
|
|
|
|
console.log('Connecting data source');
|
|
|
|
console.log('Connecting data source');
|
|
|
|
return this.scheduleSubject.asObservable();
|
|
|
|
return this.scheduleSubject.asObservable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|