Add Schedule DataSource.

This commit is contained in:
Alexis Lahouze 2017-09-21 22:54:19 +02:00
parent 6a93eac767
commit 048a2a7d08
2 changed files with 42 additions and 0 deletions

View File

@ -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<Schedule> {
private subject: BehaviorSubject<number> = new BehaviorSubject<number>(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<Schedule[]> {
return this.subject.asObservable().concatMap((accountId: number) => {
this.logger.log("In connect", accountId);
if(accountId) {
return this.scheduleService.query(accountId);
}
});
}
disconnect() {}
}

View File

@ -12,6 +12,7 @@ import { ToastrModule } from 'ngx-toastr';
import { TextMaskModule } from 'angular2-text-mask'; import { TextMaskModule } from 'angular2-text-mask';
import { ScheduleService } from './schedule.service'; import { ScheduleService } from './schedule.service';
import { ScheduleDataSource } from './schedule.dataSource';
import { ScheduleDeleteModalComponent } from './scheduleDeleteModal.component'; import { ScheduleDeleteModalComponent } from './scheduleDeleteModal.component';
import { ScheduleEditModalComponent } from './scheduleEditModal.component'; import { ScheduleEditModalComponent } from './scheduleEditModal.component';
import { ScheduleFormComponent } from './scheduleForm.component'; import { ScheduleFormComponent } from './scheduleForm.component';
@ -34,6 +35,7 @@ import { ScheduleListState } from './schedule.states';
], ],
providers: [ providers: [
ScheduleService, ScheduleService,
ScheduleDataSource,
], ],
declarations: [ declarations: [
ScheduleDeleteModalComponent, ScheduleDeleteModalComponent,