-
- connect(): Observable<EIProducer[]> {
- const dataMutations = [
- this.producerSubject.asObservable(),
- this.sort.sortChange
- ];
- return merge(...dataMutations).pipe(map(() => {
- return this.getSortedData([...this.producerSubject.getValue()]);
- }));
- }
-
- disconnect(): void {
- this.producerSubject.complete();
- this.loadingSubject.complete();
- }
-
- private getSortedData(data: EIProducer[]) {
- if (!this.sort || !this.sort.active || this.sort.direction === '') {
- return data;
- }
-
- return data.sort((a, b) => {
- const isAsc = this.sort.direction === 'asc';
- switch (this.sort.active) {
- case 'ei_producer_id': return compare(a.ei_producer_id, b.ei_producer_id, isAsc);
- default: return 0;
- }
- });
- }
-}
-
-function compare(a: string, b: string, isAsc: boolean) {
- return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
-}