- connect(): Observable<EIJob[]> {
- const dataMutations = [
- this.eiJobSubject.asObservable(),
- this.sort.sortChange
- ];
- return merge(...dataMutations).pipe(map(() => {
- return this.getSortedData([...this.eiJobSubject.getValue()]);
- }));
- }
-
- disconnect(): void {
- this.eiJobSubject.complete();
- this.loadingSubject.complete();
- }
-
- private getSortedData(data: EIJob[]) {
- 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_job_identity': return compare(a.ei_job_identity, b.ei_job_identity, isAsc);
- case 'owner': return compare(a.owner, b.owner, isAsc);
- case 'ei_type_identity': return compare(a.ei_type_identity, b.ei_type_identity, isAsc);
- default: return 0;
- }
- });
- }
-}
-
-function compare(a: string, b: string, isAsc: boolean) {
- return (a < b ? -1 : 1) * (isAsc ? 1 : -1);