* ========================LICENSE_END===================================
*/
-import { CollectionViewer, DataSource} from '@angular/cdk/collections';
+import { CollectionViewer, DataSource } from '@angular/cdk/collections';
+import { MatSort } from '@angular/material';
+import { merge } from 'rxjs';
+import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
-import { catchError, finalize } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';
-import { BehaviorSubject } from 'rxjs/BehaviorSubject';
+import { catchError, finalize, map } from 'rxjs/operators';
import { ANRNeighborCellRelation } from '../interfaces/anr-xapp.types';
import { ANRXappService } from '../services/anr-xapp/anr-xapp.service';
public loading$ = this.loadingSubject.asObservable();
- constructor(private anrXappService: ANRXappService) {
+ constructor(private anrXappService: ANRXappService, private sort: MatSort) {
super();
}
}
connect(collectionViewer: CollectionViewer): Observable<ANRNeighborCellRelation[]> {
- return this.relationsSubject.asObservable();
+ const dataMutations = [
+ this.relationsSubject.asObservable(),
+ this.sort.sortChange
+ ];
+ return merge(...dataMutations).pipe(map(() => {
+ return this.getSortedData([...this.relationsSubject.getValue()]);
+ }));
}
disconnect(collectionViewer: CollectionViewer): void {
this.loadingSubject.complete();
}
+ private getSortedData(data: ANRNeighborCellRelation[]) {
+ if (!this.sort.active || this.sort.direction === '') {
+ return data;
+ }
+
+ return data.sort((a, b) => {
+ const isAsc = this.sort.direction === 'asc';
+ switch (this.sort.active) {
+ case 'cellIdentifierNrcgi': return compare(a.servingCellNrcgi, b.servingCellNrcgi, isAsc);
+ case 'neighborCellNrpci': return compare(a.neighborCellNrpci, b.neighborCellNrpci, isAsc);
+ case 'neighborCellNrcgi': return compare(a.neighborCellNrcgi, b.neighborCellNrcgi, isAsc);
+ case 'flagNoHo': return compare(a.flagNoHo, b.flagNoHo, isAsc);
+ case 'flagNoXn': return compare(a.flagNoXn, b.flagNoXn, isAsc);
+ case 'flagNoRemove': return compare(a.flagNoRemove, b.flagNoRemove, isAsc);
+ default: return 0;
+ }
+ });
+ }
+
+}
+
+function compare(a, b, isAsc) {
+ return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}