refactor community list datasource

This commit is contained in:
Art Lowel
2019-10-11 14:52:41 +02:00
committed by Marie Verdonck
parent 8e0280cb5a
commit 79424ac108
7 changed files with 133 additions and 115 deletions

View File

@@ -1,16 +1,15 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {Observable, of} from 'rxjs';
import {CommunityDataService} from '../core/data/community-data.service';
import {PaginationComponentOptions} from '../shared/pagination/pagination-component-options.model';
import {SortDirection, SortOptions} from '../core/cache/models/sort-options.model';
import { map, take, tap } from 'rxjs/operators';
import {Community} from '../core/shared/community.model';
import {RemoteData} from '../core/data/remote-data';
import {PaginatedList} from '../core/data/paginated-list';
@Injectable()
export class CommunityListService {
communities: Community[];
communities$: Observable<Community[]>;
config: PaginationComponentOptions;
sortConfig: SortOptions;
@@ -18,17 +17,21 @@ export class CommunityListService {
constructor(private cds: CommunityDataService) {
this.config = new PaginationComponentOptions();
this.config.id = 'top-level-pagination';
this.config.pageSize = 100;
this.config.pageSize = 10;
this.config.currentPage = 1;
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
this.initTopCommunityList()
}
public getCommunityList(): Observable<RemoteData<PaginatedList<Community>>> {
return this.cds.findTop({
private initTopCommunityList(): void {
this.communities$ = this.cds.findTop({
currentPage: this.config.currentPage,
elementsPerPage: this.config.pageSize,
sort: { field: this.sortConfig.field, direction: this.sortConfig.direction }
});
}).pipe(
take(1),
map((results) => results.payload.page),
);
}
}