You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
61 lines
1.9 KiB
import {
|
|
CollectionViewer,
|
|
DataSource
|
|
} from '@angular/cdk/collections';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
|
import { of } from 'rxjs/observable/of';
|
|
|
|
import {
|
|
catchError,
|
|
finalize
|
|
} from 'rxjs/operators';
|
|
|
|
import { RegularSubsService } from './regularsubs.service';
|
|
|
|
import { RegularSub } from '../models/regularsub';
|
|
|
|
|
|
export class RegularSubsDataSource implements DataSource<RegularSub> {
|
|
private regularSubsSubject = new BehaviorSubject<RegularSub[]>([]);
|
|
private countSubject = new BehaviorSubject<number>(0);
|
|
private loadingSubject = new BehaviorSubject<boolean>(false);
|
|
|
|
public count$ = this.countSubject.asObservable();
|
|
public loading$ = this.loadingSubject.asObservable();
|
|
|
|
constructor(private regularSubsService: RegularSubsService) { }
|
|
|
|
loadRegularSubs(filter: string,
|
|
sortColumn: string,
|
|
sortDirection: string,
|
|
pageIndex: number,
|
|
pageSize: number) {
|
|
|
|
this.loadingSubject.next(true);
|
|
|
|
this.regularSubsService.findRegularSubs(filter, sortColumn, sortDirection,
|
|
pageIndex, pageSize)
|
|
.pipe(
|
|
catchError(() => of([])),
|
|
finalize(() => this.loadingSubject.next(false))
|
|
)
|
|
.subscribe(data => {
|
|
this.regularSubsSubject.next(data.regularSubs);
|
|
this.countSubject.next(data.totalCount);
|
|
});
|
|
}
|
|
|
|
connect(collectionViewer: CollectionViewer): Observable<RegularSub[]> {
|
|
console.log('Connecting data source');
|
|
return this.regularSubsSubject.asObservable();
|
|
}
|
|
|
|
disconnect(collectionViewer: CollectionViewer): void {
|
|
this.regularSubsSubject.complete();
|
|
this.countSubject.complete();
|
|
this.loadingSubject.complete();
|
|
}
|
|
}
|