X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy-control%2Fpolicy-type.datasource.ts;h=61ecc4ab767d4a2f9dbd8e008a14771180952b95;hb=36be929b28929a1f52d7e3653ab04dff953842e8;hp=983fc968dca703b7efb1ae78e84844c012b1e9d4;hpb=2e425bc51a5e8cb865db1e35e11ebe9240f72397;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy-control/policy-type.datasource.ts b/webapp-frontend/src/app/policy-control/policy-type.datasource.ts index 983fc96..61ecc4a 100644 --- a/webapp-frontend/src/app/policy-control/policy-type.datasource.ts +++ b/webapp-frontend/src/app/policy-control/policy-type.datasource.ts @@ -20,16 +20,20 @@ import { CollectionViewer, DataSource } from '@angular/cdk/collections'; import { HttpErrorResponse } from '@angular/common/http'; -import { MatSort } from '@angular/material'; -import { Observable } from 'rxjs/Observable'; +import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; -import { merge } from 'rxjs'; import { of } from 'rxjs/observable/of'; import { catchError, finalize, map } from 'rxjs/operators'; +import { Observable } from 'rxjs/Observable'; + import { PolicyType } from '../interfaces/policy.types'; import { PolicyService } from '../services/policy/policy.service'; import { NotificationService } from '../services/ui/notification.service'; +@Injectable({ + providedIn: 'root' +}) + export class PolicyTypeDataSource extends DataSource { private policyTypeSubject = new BehaviorSubject([]); @@ -41,7 +45,6 @@ export class PolicyTypeDataSource extends DataSource { public rowCount = 1; // hide footer during intial load constructor(private policySvc: PolicyService, - private sort: MatSort, private notificationService: NotificationService) { super(); } @@ -72,35 +75,11 @@ export class PolicyTypeDataSource extends DataSource { } connect(collectionViewer: CollectionViewer): Observable { - const dataMutations = [ - this.policyTypeSubject.asObservable(), - this.sort.sortChange - ]; - return merge(...dataMutations).pipe(map(() => { - return this.getSortedData([...this.policyTypeSubject.getValue()]); - })); + return of(this.policyTypeSubject.getValue()); } disconnect(collectionViewer: CollectionViewer): void { this.policyTypeSubject.complete(); this.loadingSubject.complete(); } - - private getSortedData(data: PolicyType[]) { - 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 'name': return compare(a.name, b.name, isAsc); - default: return 0; - } - }); - } -} - -function compare(a: any, b: any, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); }