mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
refactor community list datasource
This commit is contained in:

committed by
Marie Verdonck

parent
8e0280cb5a
commit
79424ac108
@@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user