mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
65528: Renaming/Moving according to feedback; style and links added; chevrons fixed
This commit is contained in:
33
src/app/community-list-page/community-list-datasource.ts
Normal file
33
src/app/community-list-page/community-list-datasource.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import {CommunityListAdapter, FlatNode} from './community-list-adapter';
|
||||
import {CollectionViewer, DataSource} from '@angular/cdk/typings/collections';
|
||||
import {BehaviorSubject, Observable,} from 'rxjs';
|
||||
import {finalize, take,} from 'rxjs/operators';
|
||||
|
||||
export class CommunityListDatasource implements DataSource<FlatNode> {
|
||||
|
||||
private communityList$ = new BehaviorSubject<FlatNode[]>([]);
|
||||
private loading$ = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor(private communityListService: CommunityListAdapter) {
|
||||
}
|
||||
|
||||
connect(collectionViewer: CollectionViewer): Observable<FlatNode[]> {
|
||||
this.loadCommunities(null);
|
||||
return this.communityList$.asObservable();
|
||||
}
|
||||
|
||||
loadCommunities(expandedNodes: FlatNode[]) {
|
||||
this.loading$.next(true);
|
||||
|
||||
this.communityListService.loadCommunities(expandedNodes).pipe(
|
||||
take(1),
|
||||
finalize(() => this.loading$.next(false)),
|
||||
).subscribe((flatNodes: FlatNode[]) => this.communityList$.next(flatNodes));
|
||||
}
|
||||
|
||||
disconnect(collectionViewer: CollectionViewer): void {
|
||||
this.communityList$.complete();
|
||||
this.loading$.complete();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user