From 048a2a7d08563edae004996cceed2e6d828df953 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 21 Sep 2017 22:54:19 +0200 Subject: [PATCH] Add Schedule DataSource. --- src/scheduler/schedule.dataSource.ts | 40 ++++++++++++++++++++++++++++ src/scheduler/schedule.module.ts | 2 ++ 2 files changed, 42 insertions(+) create mode 100644 src/scheduler/schedule.dataSource.ts diff --git a/src/scheduler/schedule.dataSource.ts b/src/scheduler/schedule.dataSource.ts new file mode 100644 index 0000000..1947dea --- /dev/null +++ b/src/scheduler/schedule.dataSource.ts @@ -0,0 +1,40 @@ +// vim: set tw=80 ts=2 sw=2 sts=2: + +import { Injectable } from '@angular/core'; +import { DataSource } from '@angular/cdk/collections'; +import { Observable } from 'rxjs'; +import { BehaviorSubject } from 'rxjs'; + +import { Logger } from '@nsalaun/ng-logger'; + +import { Schedule } from './schedule'; +import { ScheduleService } from './schedule.service'; + +@Injectable() +export class ScheduleDataSource extends DataSource { + private subject: BehaviorSubject = new BehaviorSubject(null); + + constructor( + private scheduleService: ScheduleService, + private logger: Logger, + ) { + super(); + } + + load(accountId: number): void { + this.logger.log("In load", accountId); + this.subject.next(accountId); + } + + connect(): Observable { + return this.subject.asObservable().concatMap((accountId: number) => { + this.logger.log("In connect", accountId); + + if(accountId) { + return this.scheduleService.query(accountId); + } + }); + } + + disconnect() {} +} diff --git a/src/scheduler/schedule.module.ts b/src/scheduler/schedule.module.ts index a6b980f..c3d7656 100644 --- a/src/scheduler/schedule.module.ts +++ b/src/scheduler/schedule.module.ts @@ -12,6 +12,7 @@ import { ToastrModule } from 'ngx-toastr'; import { TextMaskModule } from 'angular2-text-mask'; import { ScheduleService } from './schedule.service'; +import { ScheduleDataSource } from './schedule.dataSource'; import { ScheduleDeleteModalComponent } from './scheduleDeleteModal.component'; import { ScheduleEditModalComponent } from './scheduleEditModal.component'; import { ScheduleFormComponent } from './scheduleForm.component'; @@ -34,6 +35,7 @@ import { ScheduleListState } from './schedule.states'; ], providers: [ ScheduleService, + ScheduleDataSource, ], declarations: [ ScheduleDeleteModalComponent,