X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fanr-xapp%2Fanr-xapp.datasource.ts;h=bc04b6b04404a4e4f3212f1f5efcdd05a7993b6c;hb=80f26bbeef6caea8f9946e8a0e1a5e0319dacc38;hp=bca766c6545ef6680223911f9282a2212819ba2f;hpb=29ce34b03e4099786f14cd7fc5473305da8750d6;p=portal%2Fric-dashboard.git diff --git a/webapp-frontend/src/app/anr-xapp/anr-xapp.datasource.ts b/webapp-frontend/src/app/anr-xapp/anr-xapp.datasource.ts index bca766c6..bc04b6b0 100644 --- a/webapp-frontend/src/app/anr-xapp/anr-xapp.datasource.ts +++ b/webapp-frontend/src/app/anr-xapp/anr-xapp.datasource.ts @@ -18,11 +18,13 @@ * ========================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'; @@ -35,7 +37,7 @@ export class ANRXappDataSource extends DataSource { public loading$ = this.loadingSubject.asObservable(); - constructor(private anrXappService: ANRXappService) { + constructor(private anrXappService: ANRXappService, private sort: MatSort) { super(); } @@ -50,7 +52,13 @@ export class ANRXappDataSource extends DataSource { } connect(collectionViewer: CollectionViewer): Observable { - 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 { @@ -58,4 +66,27 @@ export class ANRXappDataSource extends DataSource { 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); }