mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
Merge branch 'master' into metadata-and-relationships-combined-in-submission
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
::ng-deep {
|
:host ::ng-deep {
|
||||||
.fa-chevron-right {
|
.fa-chevron-right {
|
||||||
padding-left: $spacer/2;
|
padding-left: $spacer/2;
|
||||||
font-size: 0.5rem;
|
font-size: 0.5rem;
|
||||||
|
@@ -204,15 +204,15 @@ describe('ItemBitstreamsComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when dropBitstream is called', () => {
|
describe('when dropBitstream is called', () => {
|
||||||
const event = {
|
beforeEach((done) => {
|
||||||
|
comp.dropBitstream(bundle, {
|
||||||
fromIndex: 0,
|
fromIndex: 0,
|
||||||
toIndex: 50,
|
toIndex: 50,
|
||||||
// tslint:disable-next-line:no-empty
|
// tslint:disable-next-line:no-empty
|
||||||
finish: () => {}
|
finish: () => {
|
||||||
};
|
done();
|
||||||
|
}
|
||||||
beforeEach(() => {
|
})
|
||||||
comp.dropBitstream(bundle, event);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send out a patch for the move operation', () => {
|
it('should send out a patch for the move operation', () => {
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import { NgZone } from '@angular/core';
|
||||||
|
import { FindListOptions } from '../core/data/request.models';
|
||||||
import { CommunityListService, FlatNode } from './community-list-service';
|
import { CommunityListService, FlatNode } from './community-list-service';
|
||||||
import { CollectionViewer, DataSource } from '@angular/cdk/typings/collections';
|
import { CollectionViewer, DataSource } from '@angular/cdk/typings/collections';
|
||||||
import { BehaviorSubject, Observable, } from 'rxjs';
|
import { BehaviorSubject, Observable, } from 'rxjs';
|
||||||
@@ -14,21 +16,23 @@ export class CommunityListDatasource implements DataSource<FlatNode> {
|
|||||||
private communityList$ = new BehaviorSubject<FlatNode[]>([]);
|
private communityList$ = new BehaviorSubject<FlatNode[]>([]);
|
||||||
public loading$ = new BehaviorSubject<boolean>(false);
|
public loading$ = new BehaviorSubject<boolean>(false);
|
||||||
|
|
||||||
constructor(private communityListService: CommunityListService) {
|
constructor(private communityListService: CommunityListService,
|
||||||
|
private zone: NgZone) {
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(collectionViewer: CollectionViewer): Observable<FlatNode[]> {
|
connect(collectionViewer: CollectionViewer): Observable<FlatNode[]> {
|
||||||
return this.communityList$.asObservable();
|
return this.communityList$.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCommunities(expandedNodes: FlatNode[]) {
|
loadCommunities(findOptions: FindListOptions, expandedNodes: FlatNode[]) {
|
||||||
this.loading$.next(true);
|
this.loading$.next(true);
|
||||||
|
this.zone.runOutsideAngular(() => {
|
||||||
this.communityListService.loadCommunities(expandedNodes).pipe(
|
this.communityListService.loadCommunities(findOptions, expandedNodes).pipe(
|
||||||
take(1),
|
take(1),
|
||||||
finalize(() => this.loading$.next(false)),
|
finalize(() => this.zone.run(() => this.loading$.next(false))),
|
||||||
).subscribe((flatNodes: FlatNode[]) => {
|
).subscribe((flatNodes: FlatNode[]) => {
|
||||||
this.communityList$.next(flatNodes);
|
this.zone.run(() => this.communityList$.next(flatNodes));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,21 +1,19 @@
|
|||||||
import { of as observableOf } from 'rxjs';
|
import { inject, TestBed } from '@angular/core/testing';
|
||||||
import { TestBed, inject, async } from '@angular/core/testing';
|
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { take } from 'rxjs/operators';
|
||||||
import { AppState } from '../app.reducer';
|
import { AppState } from '../app.reducer';
|
||||||
|
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
||||||
|
import { PaginatedList } from '../core/data/paginated-list';
|
||||||
|
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
|
||||||
import { StoreMock } from '../shared/testing/store.mock';
|
import { StoreMock } from '../shared/testing/store.mock';
|
||||||
import { CommunityListService, FlatNode, toFlatNode } from './community-list-service';
|
import { CommunityListService, FlatNode, toFlatNode } from './community-list-service';
|
||||||
import { CollectionDataService } from '../core/data/collection-data.service';
|
import { CollectionDataService } from '../core/data/collection-data.service';
|
||||||
import { PaginatedList } from '../core/data/paginated-list';
|
|
||||||
import { PageInfo } from '../core/shared/page-info.model';
|
|
||||||
import { CommunityDataService } from '../core/data/community-data.service';
|
import { CommunityDataService } from '../core/data/community-data.service';
|
||||||
import {
|
|
||||||
createFailedRemoteDataObject$,
|
|
||||||
createSuccessfulRemoteDataObject$
|
|
||||||
} from '../shared/remote-data.utils';
|
|
||||||
import { Community } from '../core/shared/community.model';
|
import { Community } from '../core/shared/community.model';
|
||||||
import { Collection } from '../core/shared/collection.model';
|
import { Collection } from '../core/shared/collection.model';
|
||||||
import { take } from 'rxjs/operators';
|
|
||||||
import { FindListOptions } from '../core/data/request.models';
|
import { FindListOptions } from '../core/data/request.models';
|
||||||
|
import { PageInfo } from '../core/shared/page-info.model';
|
||||||
|
|
||||||
describe('CommunityListService', () => {
|
describe('CommunityListService', () => {
|
||||||
let store: StoreMock<AppState>;
|
let store: StoreMock<AppState>;
|
||||||
@@ -210,13 +208,18 @@ describe('CommunityListService', () => {
|
|||||||
let flatNodeList;
|
let flatNodeList;
|
||||||
describe('None expanded: should return list containing only flatnodes of the test top communities page 1 and 2', () => {
|
describe('None expanded: should return list containing only flatnodes of the test top communities page 1 and 2', () => {
|
||||||
let findTopSpy;
|
let findTopSpy;
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
findTopSpy = spyOn(communityDataServiceStub, 'findTop').and.callThrough();
|
findTopSpy = spyOn(communityDataServiceStub, 'findTop').and.callThrough();
|
||||||
service.getNextPageTopCommunities();
|
|
||||||
|
|
||||||
const sub = service.loadCommunities(null)
|
service.loadCommunities({
|
||||||
.subscribe((value) => flatNodeList = value);
|
currentPage: 2,
|
||||||
sub.unsubscribe();
|
sort: new SortOptions('dc.title', SortDirection.ASC)
|
||||||
|
}, null)
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('flatnode list should contain just flatnodes of top community list page 1 and 2', () => {
|
it('flatnode list should contain just flatnodes of top community list page 1 and 2', () => {
|
||||||
expect(findTopSpy).toHaveBeenCalled();
|
expect(findTopSpy).toHaveBeenCalled();
|
||||||
@@ -236,10 +239,16 @@ describe('CommunityListService', () => {
|
|||||||
describe('should transform all communities in a list of flatnodes with possible subcoms and collections as subflatnodes if they\'re expanded', () => {
|
describe('should transform all communities in a list of flatnodes with possible subcoms and collections as subflatnodes if they\'re expanded', () => {
|
||||||
let flatNodeList;
|
let flatNodeList;
|
||||||
describe('None expanded: should return list containing only flatnodes of the test top communities', () => {
|
describe('None expanded: should return list containing only flatnodes of the test top communities', () => {
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const sub = service.loadCommunities(null)
|
service.loadCommunities({
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
currentPage: 1,
|
||||||
sub.unsubscribe();
|
sort: new SortOptions('dc.title', SortDirection.ASC)
|
||||||
|
}, null)
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be as big as top community list', () => {
|
it('length of flatnode list should be as big as top community list', () => {
|
||||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length);
|
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length);
|
||||||
@@ -256,7 +265,7 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('All top expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
describe('All top expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const expandedNodes = [];
|
const expandedNodes = [];
|
||||||
mockListOfTopCommunitiesPage1.map((community: Community) => {
|
mockListOfTopCommunitiesPage1.map((community: Community) => {
|
||||||
const communityFlatNode = toFlatNode(community, observableOf(true), 0, true, null);
|
const communityFlatNode = toFlatNode(community, observableOf(true), 0, true, null);
|
||||||
@@ -264,9 +273,15 @@ describe('CommunityListService', () => {
|
|||||||
communityFlatNode.currentCommunityPage = 1;
|
communityFlatNode.currentCommunityPage = 1;
|
||||||
expandedNodes.push(communityFlatNode);
|
expandedNodes.push(communityFlatNode);
|
||||||
});
|
});
|
||||||
const sub = service.loadCommunities(expandedNodes)
|
service.loadCommunities({
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
currentPage: 1,
|
||||||
sub.unsubscribe();
|
sort: new SortOptions('dc.title', SortDirection.ASC)
|
||||||
|
}, expandedNodes)
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be as big as top community list and size of its possible page-limited children', () => {
|
it('length of flatnode list should be as big as top community list and size of its possible page-limited children', () => {
|
||||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockSubcommunities1Page1.length + mockSubcommunities1Page1.length);
|
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockSubcommunities1Page1.length + mockSubcommunities1Page1.length);
|
||||||
@@ -281,14 +296,20 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Just first top comm expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
describe('Just first top comm expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const communityFlatNode = toFlatNode(mockListOfTopCommunitiesPage1[0], observableOf(true), 0, true, null);
|
const communityFlatNode = toFlatNode(mockListOfTopCommunitiesPage1[0], observableOf(true), 0, true, null);
|
||||||
communityFlatNode.currentCollectionPage = 1;
|
communityFlatNode.currentCollectionPage = 1;
|
||||||
communityFlatNode.currentCommunityPage = 1;
|
communityFlatNode.currentCommunityPage = 1;
|
||||||
const expandedNodes = [communityFlatNode];
|
const expandedNodes = [communityFlatNode];
|
||||||
const sub = service.loadCommunities(expandedNodes)
|
service.loadCommunities({
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
currentPage: 1,
|
||||||
sub.unsubscribe();
|
sort: new SortOptions('dc.title', SortDirection.ASC)
|
||||||
|
}, expandedNodes)
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be as big as top community list and size of page-limited children of first top community', () => {
|
it('length of flatnode list should be as big as top community list and size of page-limited children of first top community', () => {
|
||||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockSubcommunities1Page1.length);
|
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockSubcommunities1Page1.length);
|
||||||
@@ -300,14 +321,20 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Just second top comm expanded, collections at page 2: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
describe('Just second top comm expanded, collections at page 2: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const communityFlatNode = toFlatNode(mockListOfTopCommunitiesPage1[1], observableOf(true), 0, true, null);
|
const communityFlatNode = toFlatNode(mockListOfTopCommunitiesPage1[1], observableOf(true), 0, true, null);
|
||||||
communityFlatNode.currentCollectionPage = 2;
|
communityFlatNode.currentCollectionPage = 2;
|
||||||
communityFlatNode.currentCommunityPage = 1;
|
communityFlatNode.currentCommunityPage = 1;
|
||||||
const expandedNodes = [communityFlatNode];
|
const expandedNodes = [communityFlatNode];
|
||||||
const sub = service.loadCommunities(expandedNodes)
|
service.loadCommunities({
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
currentPage: 1,
|
||||||
sub.unsubscribe();
|
sort: new SortOptions('dc.title', SortDirection.ASC)
|
||||||
|
}, expandedNodes)
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be as big as top community list and size of page-limited children of second top community', () => {
|
it('length of flatnode list should be as big as top community list and size of page-limited children of second top community', () => {
|
||||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockCollectionsPage1.length + mockCollectionsPage2.length);
|
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockCollectionsPage1.length + mockCollectionsPage2.length);
|
||||||
@@ -333,10 +360,13 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
let flatNodeList;
|
let flatNodeList;
|
||||||
describe('None expanded: should return list containing only flatnodes of the communities in the test list', () => {
|
describe('None expanded: should return list containing only flatnodes of the communities in the test list', () => {
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const sub = service.transformListOfCommunities(new PaginatedList(new PageInfo(), listOfCommunities), 0, null, null)
|
service.transformListOfCommunities(new PaginatedList(new PageInfo(), listOfCommunities), 0, null, null)
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
.pipe(take(1))
|
||||||
sub.unsubscribe();
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be as big as community test list', () => {
|
it('length of flatnode list should be as big as community test list', () => {
|
||||||
expect(flatNodeList.length).toEqual(listOfCommunities.length);
|
expect(flatNodeList.length).toEqual(listOfCommunities.length);
|
||||||
@@ -353,7 +383,7 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('All top expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
describe('All top expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const expandedNodes = [];
|
const expandedNodes = [];
|
||||||
listOfCommunities.map((community: Community) => {
|
listOfCommunities.map((community: Community) => {
|
||||||
const communityFlatNode = toFlatNode(community, observableOf(true), 0, true, null);
|
const communityFlatNode = toFlatNode(community, observableOf(true), 0, true, null);
|
||||||
@@ -361,9 +391,12 @@ describe('CommunityListService', () => {
|
|||||||
communityFlatNode.currentCommunityPage = 1;
|
communityFlatNode.currentCommunityPage = 1;
|
||||||
expandedNodes.push(communityFlatNode);
|
expandedNodes.push(communityFlatNode);
|
||||||
});
|
});
|
||||||
const sub = service.transformListOfCommunities(new PaginatedList(new PageInfo(), listOfCommunities), 0, null, expandedNodes)
|
service.transformListOfCommunities(new PaginatedList(new PageInfo(), listOfCommunities), 0, null, expandedNodes)
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
.pipe(take(1))
|
||||||
sub.unsubscribe();
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be as big as community test list and size of its possible children', () => {
|
it('length of flatnode list should be as big as community test list and size of its possible children', () => {
|
||||||
expect(flatNodeList.length).toEqual(listOfCommunities.length + mockSubcommunities1Page1.length + mockSubcommunities1Page1.length);
|
expect(flatNodeList.length).toEqual(listOfCommunities.length + mockSubcommunities1Page1.length + mockSubcommunities1Page1.length);
|
||||||
@@ -397,10 +430,13 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
let flatNodeList;
|
let flatNodeList;
|
||||||
describe('should return list containing only flatnode corresponding to that community', () => {
|
describe('should return list containing only flatnode corresponding to that community', () => {
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const sub = service.transformCommunity(communityWithNoSubcomsOrColls, 0, null, null)
|
service.transformCommunity(communityWithNoSubcomsOrColls, 0, null, null)
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
.pipe(take(1))
|
||||||
sub.unsubscribe();
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be 1', () => {
|
it('length of flatnode list should be 1', () => {
|
||||||
expect(flatNodeList.length).toEqual(1);
|
expect(flatNodeList.length).toEqual(1);
|
||||||
@@ -426,10 +462,14 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
let flatNodeList;
|
let flatNodeList;
|
||||||
describe('should return list containing only flatnode corresponding to that community', () => {
|
describe('should return list containing only flatnode corresponding to that community', () => {
|
||||||
beforeAll(() => {
|
beforeAll((done) => {
|
||||||
const sub = service.transformCommunity(communityWithSubcoms, 0, null, null)
|
service.transformCommunity(communityWithSubcoms, 0, null, null)
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
.pipe(take(1))
|
||||||
sub.unsubscribe();
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
it('length of flatnode list should be 1', () => {
|
it('length of flatnode list should be 1', () => {
|
||||||
expect(flatNodeList.length).toEqual(1);
|
expect(flatNodeList.length).toEqual(1);
|
||||||
@@ -455,14 +495,17 @@ describe('CommunityListService', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
let flatNodeList;
|
let flatNodeList;
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
const communityFlatNode = toFlatNode(communityWithSubcoms, observableOf(true), 0, true, null);
|
const communityFlatNode = toFlatNode(communityWithSubcoms, observableOf(true), 0, true, null);
|
||||||
communityFlatNode.currentCollectionPage = 1;
|
communityFlatNode.currentCollectionPage = 1;
|
||||||
communityFlatNode.currentCommunityPage = 1;
|
communityFlatNode.currentCommunityPage = 1;
|
||||||
const expandedNodes = [communityFlatNode];
|
const expandedNodes = [communityFlatNode];
|
||||||
const sub = service.transformCommunity(communityWithSubcoms, 0, null, expandedNodes)
|
service.transformCommunity(communityWithSubcoms, 0, null, expandedNodes)
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
.pipe(take(1))
|
||||||
sub.unsubscribe();
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('list of flatnodes is length is 1 + nrOfSubcoms & first flatnode is of expanded test community', () => {
|
it('list of flatnodes is length is 1 + nrOfSubcoms & first flatnode is of expanded test community', () => {
|
||||||
expect(flatNodeList.length).toEqual(1 + mockSubcommunities1Page1.length);
|
expect(flatNodeList.length).toEqual(1 + mockSubcommunities1Page1.length);
|
||||||
@@ -485,7 +528,7 @@ describe('CommunityListService', () => {
|
|||||||
describe('should return list containing flatnodes of that community, its collections of the first two pages', () => {
|
describe('should return list containing flatnodes of that community, its collections of the first two pages', () => {
|
||||||
let communityWithCollections;
|
let communityWithCollections;
|
||||||
let flatNodeList;
|
let flatNodeList;
|
||||||
beforeEach(() => {
|
beforeEach((done) => {
|
||||||
communityWithCollections = Object.assign(new Community(), {
|
communityWithCollections = Object.assign(new Community(), {
|
||||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||||
@@ -500,9 +543,12 @@ describe('CommunityListService', () => {
|
|||||||
communityFlatNode.currentCollectionPage = 2;
|
communityFlatNode.currentCollectionPage = 2;
|
||||||
communityFlatNode.currentCommunityPage = 1;
|
communityFlatNode.currentCommunityPage = 1;
|
||||||
const expandedNodes = [communityFlatNode];
|
const expandedNodes = [communityFlatNode];
|
||||||
const sub = service.transformCommunity(communityWithCollections, 0, null, expandedNodes)
|
service.transformCommunity(communityWithCollections, 0, null, expandedNodes)
|
||||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
.pipe(take(1))
|
||||||
sub.unsubscribe();
|
.subscribe((value) => {
|
||||||
|
flatNodeList = value;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('list of flatnodes is length is 1 + nrOfCollections & first flatnode is of expanded test community', () => {
|
it('list of flatnodes is length is 1 + nrOfCollections & first flatnode is of expanded test community', () => {
|
||||||
expect(flatNodeList.length).toEqual(1 + mockCollectionsPage1.length + mockCollectionsPage2.length);
|
expect(flatNodeList.length).toEqual(1 + mockCollectionsPage1.length + mockCollectionsPage2.length);
|
||||||
@@ -533,7 +579,7 @@ describe('CommunityListService', () => {
|
|||||||
|
|
||||||
describe('getIsExpandable', () => {
|
describe('getIsExpandable', () => {
|
||||||
describe('should return true', () => {
|
describe('should return true', () => {
|
||||||
it('if community has subcommunities', () => {
|
it('if community has subcommunities', (done) => {
|
||||||
const communityWithSubcoms = Object.assign(new Community(), {
|
const communityWithSubcoms = Object.assign(new Community(), {
|
||||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||||
@@ -546,9 +592,10 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
service.getIsExpandable(communityWithSubcoms).pipe(take(1)).subscribe((result) => {
|
service.getIsExpandable(communityWithSubcoms).pipe(take(1)).subscribe((result) => {
|
||||||
expect(result).toEqual(true);
|
expect(result).toEqual(true);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('if community has collections', () => {
|
it('if community has collections', (done) => {
|
||||||
const communityWithCollections = Object.assign(new Community(), {
|
const communityWithCollections = Object.assign(new Community(), {
|
||||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||||
@@ -561,11 +608,12 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
service.getIsExpandable(communityWithCollections).pipe(take(1)).subscribe((result) => {
|
service.getIsExpandable(communityWithCollections).pipe(take(1)).subscribe((result) => {
|
||||||
expect(result).toEqual(true);
|
expect(result).toEqual(true);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('should return false', () => {
|
describe('should return false', () => {
|
||||||
it('if community has neither subcommunities nor collections', () => {
|
it('if community has neither subcommunities nor collections', (done) => {
|
||||||
const communityWithNoSubcomsOrColls = Object.assign(new Community(), {
|
const communityWithNoSubcomsOrColls = Object.assign(new Community(), {
|
||||||
id: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
id: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||||
uuid: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
uuid: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||||
@@ -578,6 +626,7 @@ describe('CommunityListService', () => {
|
|||||||
});
|
});
|
||||||
service.getIsExpandable(communityWithNoSubcomsOrColls).pipe(take(1)).subscribe((result) => {
|
service.getIsExpandable(communityWithNoSubcomsOrColls).pipe(take(1)).subscribe((result) => {
|
||||||
expect(result).toEqual(false);
|
expect(result).toEqual(false);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -4,11 +4,12 @@ import { combineLatest as observableCombineLatest } from 'rxjs/internal/observab
|
|||||||
import { Observable, of as observableOf } from 'rxjs';
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
import { AppState } from '../app.reducer';
|
import { AppState } from '../app.reducer';
|
||||||
import { CommunityDataService } from '../core/data/community-data.service';
|
import { CommunityDataService } from '../core/data/community-data.service';
|
||||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
import { FindListOptions } from '../core/data/request.models';
|
||||||
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
import { map, flatMap } from 'rxjs/operators';
|
||||||
import { catchError, filter, map, switchMap, take } from 'rxjs/operators';
|
|
||||||
import { Community } from '../core/shared/community.model';
|
import { Community } from '../core/shared/community.model';
|
||||||
import { Collection } from '../core/shared/collection.model';
|
import { Collection } from '../core/shared/collection.model';
|
||||||
|
import { getSucceededRemoteData } from '../core/shared/operators';
|
||||||
|
import { PageInfo } from '../core/shared/page-info.model';
|
||||||
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
||||||
import { RemoteData } from '../core/data/remote-data';
|
import { RemoteData } from '../core/data/remote-data';
|
||||||
import { PaginatedList } from '../core/data/paginated-list';
|
import { PaginatedList } from '../core/data/paginated-list';
|
||||||
@@ -46,8 +47,7 @@ export class ShowMoreFlatNode {
|
|||||||
// Helper method to combine an flatten an array of observables of flatNode arrays
|
// Helper method to combine an flatten an array of observables of flatNode arrays
|
||||||
export const combineAndFlatten = (obsList: Array<Observable<FlatNode[]>>): Observable<FlatNode[]> =>
|
export const combineAndFlatten = (obsList: Array<Observable<FlatNode[]>>): Observable<FlatNode[]> =>
|
||||||
observableCombineLatest(...obsList).pipe(
|
observableCombineLatest(...obsList).pipe(
|
||||||
map((matrix: FlatNode[][]) =>
|
map((matrix: any[][]) => [].concat(...matrix))
|
||||||
matrix.reduce((combinedList, currentList: FlatNode[]) => [...combinedList, ...currentList]))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,6 +99,8 @@ const communityListStateSelector = (state: AppState) => state.communityList;
|
|||||||
const expandedNodesSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.expandedNodes);
|
const expandedNodesSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.expandedNodes);
|
||||||
const loadingNodeSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.loadingNode);
|
const loadingNodeSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.loadingNode);
|
||||||
|
|
||||||
|
export const MAX_COMCOLS_PER_PAGE = 50;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service class for the community list, responsible for the creating of the flat list used by communityList dataSource
|
* Service class for the community list, responsible for the creating of the flat list used by communityList dataSource
|
||||||
* and connection to the store to retrieve and save the state of the community list
|
* and connection to the store to retrieve and save the state of the community list
|
||||||
@@ -107,26 +109,8 @@ const loadingNodeSelector = createSelector(communityListStateSelector, (communit
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommunityListService {
|
export class CommunityListService {
|
||||||
|
|
||||||
// page-limited list of top-level communities
|
|
||||||
payloads$: Array<Observable<PaginatedList<Community>>>;
|
|
||||||
|
|
||||||
topCommunitiesConfig: PaginationComponentOptions;
|
|
||||||
topCommunitiesSortConfig: SortOptions;
|
|
||||||
|
|
||||||
maxSubCommunitiesPerPage: number;
|
|
||||||
maxCollectionsPerPage: number;
|
|
||||||
|
|
||||||
constructor(private communityDataService: CommunityDataService, private collectionDataService: CollectionDataService,
|
constructor(private communityDataService: CommunityDataService, private collectionDataService: CollectionDataService,
|
||||||
private store: Store<any>) {
|
private store: Store<any>) {
|
||||||
this.topCommunitiesConfig = new PaginationComponentOptions();
|
|
||||||
this.topCommunitiesConfig.id = 'top-level-pagination';
|
|
||||||
this.topCommunitiesConfig.pageSize = 10;
|
|
||||||
this.topCommunitiesConfig.currentPage = 1;
|
|
||||||
this.topCommunitiesSortConfig = new SortOptions('dc.title', SortDirection.ASC);
|
|
||||||
this.initTopCommunityList();
|
|
||||||
|
|
||||||
this.maxSubCommunitiesPerPage = 3;
|
|
||||||
this.maxCollectionsPerPage = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCommunityListStateToStore(expandedNodes: FlatNode[], loadingNode: FlatNode): void {
|
saveCommunityListStateToStore(expandedNodes: FlatNode[], loadingNode: FlatNode): void {
|
||||||
@@ -141,57 +125,46 @@ export class CommunityListService {
|
|||||||
return this.store.select(loadingNodeSelector);
|
return this.store.select(loadingNodeSelector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Increases the payload so it contains the next page of top level communities
|
|
||||||
*/
|
|
||||||
getNextPageTopCommunities(): void {
|
|
||||||
this.topCommunitiesConfig.currentPage = this.topCommunitiesConfig.currentPage + 1;
|
|
||||||
this.payloads$ = [...this.payloads$, this.communityDataService.findTop({
|
|
||||||
currentPage: this.topCommunitiesConfig.currentPage,
|
|
||||||
elementsPerPage: this.topCommunitiesConfig.pageSize,
|
|
||||||
sort: {
|
|
||||||
field: this.topCommunitiesSortConfig.field,
|
|
||||||
direction: this.topCommunitiesSortConfig.direction
|
|
||||||
}
|
|
||||||
}).pipe(
|
|
||||||
take(1),
|
|
||||||
map((results) => results.payload),
|
|
||||||
)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all top communities, limited by page, and transforms this in a list of flatNodes.
|
* Gets all top communities, limited by page, and transforms this in a list of flatNodes.
|
||||||
* @param expandedNodes List of expanded nodes; if a node is not expanded its subCommunities and collections need
|
* @param expandedNodes List of expanded nodes; if a node is not expanded its subCommunities and collections need
|
||||||
* not be added to the list
|
* not be added to the list
|
||||||
*/
|
*/
|
||||||
loadCommunities(expandedNodes: FlatNode[]): Observable<FlatNode[]> {
|
loadCommunities(findOptions: FindListOptions, expandedNodes: FlatNode[]): Observable<FlatNode[]> {
|
||||||
const res = this.payloads$.map((payload) => {
|
const currentPage = findOptions.currentPage;
|
||||||
return payload.pipe(
|
const topCommunities = [];
|
||||||
take(1),
|
for (let i = 1; i <= currentPage; i++) {
|
||||||
switchMap((result: PaginatedList<Community>) => {
|
const pagination: FindListOptions = Object.assign({}, findOptions, { currentPage: i });
|
||||||
return this.transformListOfCommunities(result, 0, null, expandedNodes);
|
topCommunities.push(this.getTopCommunities(pagination));
|
||||||
}),
|
}
|
||||||
catchError(() => observableOf([])),
|
const topComs$ = observableCombineLatest(...topCommunities).pipe(
|
||||||
|
map((coms: Array<PaginatedList<Community>>) => {
|
||||||
|
const newPages: Community[][] = coms.map((unit: PaginatedList<Community>) => unit.page);
|
||||||
|
const newPage: Community[] = [].concat(...newPages);
|
||||||
|
let newPageInfo = new PageInfo();
|
||||||
|
if (coms && coms.length > 0) {
|
||||||
|
newPageInfo = Object.assign({}, coms[0].pageInfo, { currentPage })
|
||||||
|
}
|
||||||
|
return new PaginatedList(newPageInfo, newPage);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
});
|
return topComs$.pipe(flatMap((topComs: PaginatedList<Community>) => this.transformListOfCommunities(topComs, 0, null, expandedNodes)));
|
||||||
return combineAndFlatten(res);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts the initial top level communities in a list to be called upon
|
* Puts the initial top level communities in a list to be called upon
|
||||||
*/
|
*/
|
||||||
private initTopCommunityList(): void {
|
private getTopCommunities(options: FindListOptions): Observable<PaginatedList<Community>> {
|
||||||
this.payloads$ = [this.communityDataService.findTop({
|
return this.communityDataService.findTop({
|
||||||
currentPage: this.topCommunitiesConfig.currentPage,
|
currentPage: options.currentPage,
|
||||||
elementsPerPage: this.topCommunitiesConfig.pageSize,
|
elementsPerPage: MAX_COMCOLS_PER_PAGE,
|
||||||
sort: {
|
sort: {
|
||||||
field: this.topCommunitiesSortConfig.field,
|
field: options.sort.field,
|
||||||
direction: this.topCommunitiesSortConfig.direction
|
direction: options.sort.direction
|
||||||
}
|
}
|
||||||
}).pipe(
|
}).pipe(
|
||||||
take(1),
|
|
||||||
map((results) => results.payload),
|
map((results) => results.payload),
|
||||||
)];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,16 +179,15 @@ export class CommunityListService {
|
|||||||
parent: FlatNode,
|
parent: FlatNode,
|
||||||
expandedNodes: FlatNode[]): Observable<FlatNode[]> {
|
expandedNodes: FlatNode[]): Observable<FlatNode[]> {
|
||||||
if (isNotEmpty(listOfPaginatedCommunities.page)) {
|
if (isNotEmpty(listOfPaginatedCommunities.page)) {
|
||||||
let currentPage = this.topCommunitiesConfig.currentPage;
|
let currentPage = listOfPaginatedCommunities.currentPage;
|
||||||
if (isNotEmpty(parent)) {
|
if (isNotEmpty(parent)) {
|
||||||
currentPage = expandedNodes.find((node: FlatNode) => node.id === parent.id).currentCommunityPage;
|
currentPage = expandedNodes.find((node: FlatNode) => node.id === parent.id).currentCommunityPage;
|
||||||
}
|
}
|
||||||
const isNotAllCommunities = (listOfPaginatedCommunities.totalElements > (listOfPaginatedCommunities.elementsPerPage * currentPage));
|
|
||||||
let obsList = listOfPaginatedCommunities.page
|
let obsList = listOfPaginatedCommunities.page
|
||||||
.map((community: Community) => {
|
.map((community: Community) => {
|
||||||
return this.transformCommunity(community, level, parent, expandedNodes)
|
return this.transformCommunity(community, level, parent, expandedNodes)
|
||||||
});
|
});
|
||||||
if (isNotAllCommunities && listOfPaginatedCommunities.currentPage > currentPage) {
|
if (currentPage < listOfPaginatedCommunities.totalPages && currentPage === listOfPaginatedCommunities.currentPage) {
|
||||||
obsList = [...obsList, observableOf([showMoreFlatNode('community', level, parent)])];
|
obsList = [...obsList, observableOf([showMoreFlatNode('community', level, parent)])];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,13 +224,12 @@ export class CommunityListService {
|
|||||||
let subcoms = [];
|
let subcoms = [];
|
||||||
for (let i = 1; i <= currentCommunityPage; i++) {
|
for (let i = 1; i <= currentCommunityPage; i++) {
|
||||||
const nextSetOfSubcommunitiesPage = this.communityDataService.findByParent(community.uuid, {
|
const nextSetOfSubcommunitiesPage = this.communityDataService.findByParent(community.uuid, {
|
||||||
elementsPerPage: this.maxSubCommunitiesPerPage,
|
elementsPerPage: MAX_COMCOLS_PER_PAGE,
|
||||||
currentPage: i
|
currentPage: i
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((rd: RemoteData<PaginatedList<Community>>) => rd.hasSucceeded),
|
getSucceededRemoteData(),
|
||||||
take(1),
|
flatMap((rd: RemoteData<PaginatedList<Community>>) =>
|
||||||
switchMap((rd: RemoteData<PaginatedList<Community>>) =>
|
|
||||||
this.transformListOfCommunities(rd.payload, level + 1, communityFlatNode, expandedNodes))
|
this.transformListOfCommunities(rd.payload, level + 1, communityFlatNode, expandedNodes))
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -271,16 +242,15 @@ export class CommunityListService {
|
|||||||
let collections = [];
|
let collections = [];
|
||||||
for (let i = 1; i <= currentCollectionPage; i++) {
|
for (let i = 1; i <= currentCollectionPage; i++) {
|
||||||
const nextSetOfCollectionsPage = this.collectionDataService.findByParent(community.uuid, {
|
const nextSetOfCollectionsPage = this.collectionDataService.findByParent(community.uuid, {
|
||||||
elementsPerPage: this.maxCollectionsPerPage,
|
elementsPerPage: MAX_COMCOLS_PER_PAGE,
|
||||||
currentPage: i
|
currentPage: i
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((rd: RemoteData<PaginatedList<Collection>>) => rd.hasSucceeded),
|
getSucceededRemoteData(),
|
||||||
take(1),
|
|
||||||
map((rd: RemoteData<PaginatedList<Collection>>) => {
|
map((rd: RemoteData<PaginatedList<Collection>>) => {
|
||||||
let nodes = rd.payload.page
|
let nodes = rd.payload.page
|
||||||
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
|
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
|
||||||
if ((rd.payload.elementsPerPage * currentCollectionPage) < rd.payload.totalElements && rd.payload.currentPage > currentCollectionPage) {
|
if (currentCollectionPage < rd.payload.totalPages && currentCollectionPage === rd.payload.currentPage) {
|
||||||
nodes = [...nodes, showMoreFlatNode('collection', level + 1, communityFlatNode)];
|
nodes = [...nodes, showMoreFlatNode('collection', level + 1, communityFlatNode)];
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
@@ -305,21 +275,18 @@ export class CommunityListService {
|
|||||||
let hasColls$: Observable<boolean>;
|
let hasColls$: Observable<boolean>;
|
||||||
hasSubcoms$ = this.communityDataService.findByParent(community.uuid, { elementsPerPage: 1 })
|
hasSubcoms$ = this.communityDataService.findByParent(community.uuid, { elementsPerPage: 1 })
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((rd: RemoteData<PaginatedList<Community>>) => rd.hasSucceeded),
|
getSucceededRemoteData(),
|
||||||
take(1),
|
|
||||||
map((results) => results.payload.totalElements > 0),
|
map((results) => results.payload.totalElements > 0),
|
||||||
);
|
);
|
||||||
|
|
||||||
hasColls$ = this.collectionDataService.findByParent(community.uuid, { elementsPerPage: 1 })
|
hasColls$ = this.collectionDataService.findByParent(community.uuid, { elementsPerPage: 1 })
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((rd: RemoteData<PaginatedList<Collection>>) => rd.hasSucceeded),
|
getSucceededRemoteData(),
|
||||||
take(1),
|
|
||||||
map((results) => results.payload.totalElements > 0),
|
map((results) => results.payload.totalElements > 0),
|
||||||
);
|
);
|
||||||
|
|
||||||
let hasChildren$: Observable<boolean>;
|
let hasChildren$: Observable<boolean>;
|
||||||
hasChildren$ = observableCombineLatest(hasSubcoms$, hasColls$).pipe(
|
hasChildren$ = observableCombineLatest(hasSubcoms$, hasColls$).pipe(
|
||||||
take(1),
|
|
||||||
map(([hasSubcoms, hasColls]: [boolean, boolean]) => {
|
map(([hasSubcoms, hasColls]: [boolean, boolean]) => {
|
||||||
if (hasSubcoms || hasColls) {
|
if (hasSubcoms || hasColls) {
|
||||||
return true;
|
return true;
|
||||||
|
@@ -114,15 +114,9 @@ describe('CommunityListComponent', () => {
|
|||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
communityListServiceStub = {
|
communityListServiceStub = {
|
||||||
topPageSize: 2,
|
pageSize: 2,
|
||||||
topCurrentPage: 1,
|
|
||||||
collectionPageSize: 2,
|
|
||||||
subcommunityPageSize: 2,
|
|
||||||
expandedNodes: [],
|
expandedNodes: [],
|
||||||
loadingNode: null,
|
loadingNode: null,
|
||||||
getNextPageTopCommunities() {
|
|
||||||
this.topCurrentPage++;
|
|
||||||
},
|
|
||||||
getLoadingNodeFromStore() {
|
getLoadingNodeFromStore() {
|
||||||
return observableOf(this.loadingNode);
|
return observableOf(this.loadingNode);
|
||||||
},
|
},
|
||||||
@@ -133,12 +127,12 @@ describe('CommunityListComponent', () => {
|
|||||||
this.expandedNodes = expandedNodes;
|
this.expandedNodes = expandedNodes;
|
||||||
this.loadingNode = loadingNode;
|
this.loadingNode = loadingNode;
|
||||||
},
|
},
|
||||||
loadCommunities(expandedNodes) {
|
loadCommunities(options, expandedNodes) {
|
||||||
let flatnodes;
|
let flatnodes;
|
||||||
let showMoreTopComNode = false;
|
let showMoreTopComNode = false;
|
||||||
flatnodes = [...mockTopFlatnodesUnexpanded];
|
flatnodes = [...mockTopFlatnodesUnexpanded];
|
||||||
const currentPage = this.topCurrentPage;
|
const currentPage = options.currentPage;
|
||||||
const elementsPerPage = this.topPageSize;
|
const elementsPerPage = this.pageSize;
|
||||||
let endPageIndex = (currentPage * elementsPerPage);
|
let endPageIndex = (currentPage * elementsPerPage);
|
||||||
if (endPageIndex >= flatnodes.length) {
|
if (endPageIndex >= flatnodes.length) {
|
||||||
endPageIndex = flatnodes.length;
|
endPageIndex = flatnodes.length;
|
||||||
@@ -171,14 +165,14 @@ describe('CommunityListComponent', () => {
|
|||||||
collFlatnodes = [...collFlatnodes, toFlatNode(coll, observableOf(false), topNode.level + 1, false, topNode)];
|
collFlatnodes = [...collFlatnodes, toFlatNode(coll, observableOf(false), topNode.level + 1, false, topNode)];
|
||||||
});
|
});
|
||||||
if (isNotEmpty(subComFlatnodes)) {
|
if (isNotEmpty(subComFlatnodes)) {
|
||||||
const endSubComIndex = this.subcommunityPageSize * expandedParent.currentCommunityPage;
|
const endSubComIndex = this.pageSize * expandedParent.currentCommunityPage;
|
||||||
flatnodes = [...flatnodes, ...subComFlatnodes.slice(0, endSubComIndex)];
|
flatnodes = [...flatnodes, ...subComFlatnodes.slice(0, endSubComIndex)];
|
||||||
if (subComFlatnodes.length > endSubComIndex) {
|
if (subComFlatnodes.length > endSubComIndex) {
|
||||||
flatnodes = [...flatnodes, showMoreFlatNode('community', topNode.level + 1, expandedParent)];
|
flatnodes = [...flatnodes, showMoreFlatNode('community', topNode.level + 1, expandedParent)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isNotEmpty(collFlatnodes)) {
|
if (isNotEmpty(collFlatnodes)) {
|
||||||
const endColIndex = this.collectionPageSize * expandedParent.currentCollectionPage;
|
const endColIndex = this.pageSize * expandedParent.currentCollectionPage;
|
||||||
flatnodes = [...flatnodes, ...collFlatnodes.slice(0, endColIndex)];
|
flatnodes = [...flatnodes, ...collFlatnodes.slice(0, endColIndex)];
|
||||||
if (collFlatnodes.length > endColIndex) {
|
if (collFlatnodes.length > endColIndex) {
|
||||||
flatnodes = [...flatnodes, showMoreFlatNode('collection', topNode.level + 1, expandedParent)];
|
flatnodes = [...flatnodes, showMoreFlatNode('collection', topNode.level + 1, expandedParent)];
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { take } from 'rxjs/operators';
|
import { take } from 'rxjs/operators';
|
||||||
|
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||||
|
import { FindListOptions } from '../../core/data/request.models';
|
||||||
import { CommunityListService, FlatNode } from '../community-list-service';
|
import { CommunityListService, FlatNode } from '../community-list-service';
|
||||||
import { CommunityListDatasource } from '../community-list-datasource';
|
import { CommunityListDatasource } from '../community-list-datasource';
|
||||||
import { FlatTreeControl } from '@angular/cdk/tree';
|
import { FlatTreeControl } from '@angular/cdk/tree';
|
||||||
@@ -27,17 +29,24 @@ export class CommunityListComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
dataSource: CommunityListDatasource;
|
dataSource: CommunityListDatasource;
|
||||||
|
|
||||||
constructor(private communityListService: CommunityListService) {
|
paginationConfig: FindListOptions;
|
||||||
|
|
||||||
|
constructor(private communityListService: CommunityListService,
|
||||||
|
private zone: NgZone) {
|
||||||
|
this.paginationConfig = new FindListOptions();
|
||||||
|
this.paginationConfig.elementsPerPage = 2;
|
||||||
|
this.paginationConfig.currentPage = 1;
|
||||||
|
this.paginationConfig.sort = new SortOptions('dc.title', SortDirection.ASC);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.dataSource = new CommunityListDatasource(this.communityListService);
|
this.dataSource = new CommunityListDatasource(this.communityListService, this.zone);
|
||||||
this.communityListService.getLoadingNodeFromStore().pipe(take(1)).subscribe((result) => {
|
this.communityListService.getLoadingNodeFromStore().pipe(take(1)).subscribe((result) => {
|
||||||
this.loadingNode = result;
|
this.loadingNode = result;
|
||||||
});
|
});
|
||||||
this.communityListService.getExpandedNodesFromStore().pipe(take(1)).subscribe((result) => {
|
this.communityListService.getExpandedNodesFromStore().pipe(take(1)).subscribe((result) => {
|
||||||
this.expandedNodes = [...result];
|
this.expandedNodes = [...result];
|
||||||
this.dataSource.loadCommunities(this.expandedNodes);
|
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +83,7 @@ export class CommunityListComponent implements OnInit, OnDestroy {
|
|||||||
node.currentCommunityPage = 1;
|
node.currentCommunityPage = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.dataSource.loadCommunities(this.expandedNodes);
|
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,10 +103,10 @@ export class CommunityListComponent implements OnInit, OnDestroy {
|
|||||||
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
||||||
parentNodeInExpandedNodes.currentCommunityPage++;
|
parentNodeInExpandedNodes.currentCommunityPage++;
|
||||||
}
|
}
|
||||||
this.dataSource.loadCommunities(this.expandedNodes);
|
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
|
||||||
} else {
|
} else {
|
||||||
this.communityListService.getNextPageTopCommunities();
|
this.paginationConfig.currentPage++;
|
||||||
this.dataSource.loadCommunities(this.expandedNodes);
|
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -151,12 +151,7 @@ export class RemoteDataBuildService {
|
|||||||
filterSuccessfulResponses(),
|
filterSuccessfulResponses(),
|
||||||
map((response: DSOSuccessResponse) => {
|
map((response: DSOSuccessResponse) => {
|
||||||
if (hasValue((response as DSOSuccessResponse).pageInfo)) {
|
if (hasValue((response as DSOSuccessResponse).pageInfo)) {
|
||||||
const resPageInfo = (response as DSOSuccessResponse).pageInfo;
|
return (response as DSOSuccessResponse).pageInfo;
|
||||||
if (isNotEmpty(resPageInfo) && resPageInfo.currentPage >= 0) {
|
|
||||||
return Object.assign({}, resPageInfo, { currentPage: resPageInfo.currentPage + 1 });
|
|
||||||
} else {
|
|
||||||
return resPageInfo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@@ -11,7 +11,7 @@ export function getMockRequestService(requestEntry$: Observable<RequestEntry> =
|
|||||||
getByUUID: requestEntry$,
|
getByUUID: requestEntry$,
|
||||||
uriEncodeBody: jasmine.createSpy('uriEncodeBody'),
|
uriEncodeBody: jasmine.createSpy('uriEncodeBody'),
|
||||||
isCachedOrPending: false,
|
isCachedOrPending: false,
|
||||||
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring').and.returnValue(observableOf(true)),
|
removeByHrefSubstring: observableOf(true),
|
||||||
hasByHrefObservable: observableOf(false)
|
hasByHrefObservable: observableOf(false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user