Skip to content

Commit 0f1b9bb

Browse files
authored
Merge pull request DSpace#1803 from mark-cooper/browse-comm-lists-configurable
Make no. of communities per pagination / expansion configurable
2 parents 31167a3 + 086bd47 commit 0f1b9bb

10 files changed

Lines changed: 87 additions & 39 deletions

config/config.example.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ browseBy:
175175
# The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items)
176176
defaultLowerLimit: 1900
177177

178+
communityList:
179+
# No. of communities to list per expansion (show more)
180+
pageSize: 20
181+
182+
homePage:
183+
recentSubmissions:
184+
# The number of item showing in recent submission components
185+
pageSize: 5
186+
# Sort record of recent submission
187+
sortField: 'dc.date.accessioned'
188+
topLevelCommunityList:
189+
# No. of communities to list per page on the home page
190+
# This will always round to the nearest number from the list of page sizes. e.g. if you set it to 7 it'll use 10
191+
pageSize: 5
192+
178193
# Item Config
179194
item:
180195
edit:
@@ -264,10 +279,3 @@ mediaViewer:
264279
info:
265280
enableEndUserAgreement: true
266281
enablePrivacyStatement: true
267-
# Home Page
268-
homePage:
269-
recentSubmissions:
270-
# The number of item showing in recent submission components
271-
pageSize: 5
272-
# Sort record of recent submission
273-
sortField: 'dc.date.accessioned'

src/app/community-list-page/community-list-service.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { Collection } from '../core/shared/collection.model';
1515
import { PageInfo } from '../core/shared/page-info.model';
1616
import { FlatNode } from './flat-node.model';
1717
import { FindListOptions } from '../core/data/find-list-options.model';
18+
import { APP_CONFIG } from 'src/config/app-config.interface';
19+
import { environment } from 'src/environments/environment.test';
1820

1921
describe('CommunityListService', () => {
2022
let store: StoreMock<AppState>;
@@ -191,13 +193,14 @@ describe('CommunityListService', () => {
191193
};
192194
TestBed.configureTestingModule({
193195
providers: [CommunityListService,
196+
{ provide: APP_CONFIG, useValue: environment },
194197
{ provide: CollectionDataService, useValue: collectionDataServiceStub },
195198
{ provide: CommunityDataService, useValue: communityDataServiceStub },
196199
{ provide: Store, useValue: StoreMock },
197200
],
198201
});
199202
store = TestBed.inject(Store as any);
200-
service = new CommunityListService(communityDataServiceStub, collectionDataServiceStub, store);
203+
service = new CommunityListService(environment, communityDataServiceStub, collectionDataServiceStub, store);
201204
});
202205

203206
it('should create', inject([CommunityListService], (serviceIn: CommunityListService) => {

src/app/community-list-page/community-list-service.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-classes-per-file */
2-
import { Injectable } from '@angular/core';
2+
import { Inject, Injectable } from '@angular/core';
33
import { createSelector, Store } from '@ngrx/store';
44

55
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
@@ -23,6 +23,7 @@ import { followLink } from '../shared/utils/follow-link-config.model';
2323
import { FlatNode } from './flat-node.model';
2424
import { ShowMoreFlatNode } from './show-more-flat-node.model';
2525
import { FindListOptions } from '../core/data/find-list-options.model';
26+
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
2627

2728
// Helper method to combine an flatten an array of observables of flatNode arrays
2829
export const combineAndFlatten = (obsList: Observable<FlatNode[]>[]): Observable<FlatNode[]> =>
@@ -80,17 +81,22 @@ const communityListStateSelector = (state: AppState) => state.communityList;
8081
const expandedNodesSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.expandedNodes);
8182
const loadingNodeSelector = createSelector(communityListStateSelector, (communityList: CommunityListState) => communityList.loadingNode);
8283

83-
export const MAX_COMCOLS_PER_PAGE = 20;
84-
8584
/**
8685
* Service class for the community list, responsible for the creating of the flat list used by communityList dataSource
8786
* and connection to the store to retrieve and save the state of the community list
8887
*/
8988
@Injectable()
9089
export class CommunityListService {
9190

92-
constructor(private communityDataService: CommunityDataService, private collectionDataService: CollectionDataService,
93-
private store: Store<any>) {
91+
private pageSize: number;
92+
93+
constructor(
94+
@Inject(APP_CONFIG) protected appConfig: AppConfig,
95+
private communityDataService: CommunityDataService,
96+
private collectionDataService: CollectionDataService,
97+
private store: Store<any>
98+
) {
99+
this.pageSize = appConfig.communityList.pageSize;
94100
}
95101

96102
private configOnePage: FindListOptions = Object.assign(new FindListOptions(), {
@@ -145,7 +151,7 @@ export class CommunityListService {
145151
private getTopCommunities(options: FindListOptions): Observable<PaginatedList<Community>> {
146152
return this.communityDataService.findTop({
147153
currentPage: options.currentPage,
148-
elementsPerPage: MAX_COMCOLS_PER_PAGE,
154+
elementsPerPage: this.pageSize,
149155
sort: {
150156
field: options.sort.field,
151157
direction: options.sort.direction
@@ -216,7 +222,7 @@ export class CommunityListService {
216222
let subcoms = [];
217223
for (let i = 1; i <= currentCommunityPage; i++) {
218224
const nextSetOfSubcommunitiesPage = this.communityDataService.findByParent(community.uuid, {
219-
elementsPerPage: MAX_COMCOLS_PER_PAGE,
225+
elementsPerPage: this.pageSize,
220226
currentPage: i
221227
},
222228
followLink('subcommunities', { findListOptions: this.configOnePage }),
@@ -241,7 +247,7 @@ export class CommunityListService {
241247
let collections = [];
242248
for (let i = 1; i <= currentCollectionPage; i++) {
243249
const nextSetOfCollectionsPage = this.collectionDataService.findByParent(community.uuid, {
244-
elementsPerPage: MAX_COMCOLS_PER_PAGE,
250+
elementsPerPage: this.pageSize,
245251
currentPage: i
246252
})
247253
.pipe(

src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import { SearchConfigurationService } from '../../core/shared/search/search-conf
3232
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
3333
import { createPaginatedList } from '../../shared/testing/utils.test';
3434
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service.stub';
35+
import { APP_CONFIG } from 'src/config/app-config.interface';
36+
import { environment } from 'src/environments/environment.test';
3537

3638
describe('TopLevelCommunityList Component', () => {
3739
let comp: TopLevelCommunityListComponent;
@@ -151,6 +153,7 @@ describe('TopLevelCommunityList Component', () => {
151153
],
152154
declarations: [TopLevelCommunityListComponent],
153155
providers: [
156+
{ provide: APP_CONFIG, useValue: environment },
154157
{ provide: CommunityDataService, useValue: communityDataServiceStub },
155158
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
156159
{ provide: PaginationService, useValue: paginationService },

src/app/home-page/top-level-community-list/top-level-community-list.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, OnInit, OnDestroy } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, OnInit, OnDestroy, Inject } from '@angular/core';
22

33
import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription } from 'rxjs';
44

@@ -12,6 +12,7 @@ import { PaginationComponentOptions } from '../../shared/pagination/pagination-c
1212
import { hasValue } from '../../shared/empty.util';
1313
import { switchMap } from 'rxjs/operators';
1414
import { PaginationService } from '../../core/pagination/pagination.service';
15+
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
1516

1617
/**
1718
* this component renders the Top-Level Community list
@@ -50,11 +51,14 @@ export class TopLevelCommunityListComponent implements OnInit, OnDestroy {
5051
*/
5152
currentPageSubscription: Subscription;
5253

53-
constructor(private cds: CommunityDataService,
54-
private paginationService: PaginationService) {
54+
constructor(
55+
@Inject(APP_CONFIG) protected appConfig: AppConfig,
56+
private cds: CommunityDataService,
57+
private paginationService: PaginationService
58+
) {
5559
this.config = new PaginationComponentOptions();
5660
this.config.id = this.pageId;
57-
this.config.pageSize = 5;
61+
this.config.pageSize = appConfig.homePage.topLevelCommunityList.pageSize;
5862
this.config.currentPage = 1;
5963
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
6064
}

src/config/app-config.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { BrowseByConfig } from './browse-by-config.interface';
1717
import { BundleConfig } from './bundle-config.interface';
1818
import { ActuatorsConfig } from './actuators.config';
1919
import { InfoConfig } from './info-config.interface';
20+
import { CommunityListConfig } from './community-list-config.interface';
2021
import { HomeConfig } from './homepage-config.interface';
22+
2123
interface AppConfig extends Config {
2224
ui: UIServerConfig;
2325
rest: ServerConfig;
@@ -31,14 +33,15 @@ interface AppConfig extends Config {
3133
defaultLanguage: string;
3234
languages: LangConfig[];
3335
browseBy: BrowseByConfig;
36+
communityList: CommunityListConfig;
37+
homePage: HomeConfig;
3438
item: ItemConfig;
3539
collection: CollectionPageConfig;
3640
themes: ThemeConfig[];
3741
mediaViewer: MediaViewerConfig;
3842
bundle: BundleConfig;
3943
actuators: ActuatorsConfig
4044
info: InfoConfig;
41-
homePage: HomeConfig;
4245
}
4346

4447
/**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Config } from './config.interface';
2+
3+
export interface CommunityListConfig extends Config {
4+
pageSize: number;
5+
}

src/config/default-app-config.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { UIServerConfig } from './ui-server-config.interface';
1717
import { BundleConfig } from './bundle-config.interface';
1818
import { ActuatorsConfig } from './actuators.config';
1919
import { InfoConfig } from './info-config.interface';
20+
import { CommunityListConfig } from './community-list-config.interface';
2021
import { HomeConfig } from './homepage-config.interface';
22+
2123
export class DefaultAppConfig implements AppConfig {
2224
production = false;
2325

@@ -210,6 +212,22 @@ export class DefaultAppConfig implements AppConfig {
210212
defaultLowerLimit: 1900
211213
};
212214

215+
communityList: CommunityListConfig = {
216+
pageSize: 20
217+
};
218+
219+
homePage: HomeConfig = {
220+
recentSubmissions: {
221+
//The number of item showing in recent submission components
222+
pageSize: 5,
223+
//sort record of recent submission
224+
sortField: 'dc.date.accessioned',
225+
},
226+
topLevelCommunityList: {
227+
pageSize: 5
228+
}
229+
};
230+
213231
// Item Config
214232
item: ItemConfig = {
215233
edit: {
@@ -340,13 +358,4 @@ export class DefaultAppConfig implements AppConfig {
340358
enableEndUserAgreement: true,
341359
enablePrivacyStatement: true
342360
};
343-
// Home Pages
344-
homePage: HomeConfig = {
345-
recentSubmissions: {
346-
//The number of item showing in recent submission components
347-
pageSize: 5,
348-
//sort record of recent submission
349-
sortField: 'dc.date.accessioned',
350-
}
351-
};
352361
}

src/config/homepage-config.interface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ export interface HomeConfig extends Config {
1616
sortField: string;
1717
}
1818

19-
19+
topLevelCommunityList: {
20+
pageSize: number;
21+
};
2022
}

src/environments/environment.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ export const environment: BuildConfig = {
204204
// The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items)
205205
defaultLowerLimit: 1900,
206206
},
207+
communityList: {
208+
pageSize: 20
209+
},
210+
homePage: {
211+
recentSubmissions: {
212+
pageSize: 5,
213+
//sort record of recent submission
214+
sortField: 'dc.date.accessioned',
215+
},
216+
topLevelCommunityList: {
217+
pageSize: 5
218+
}
219+
},
207220
item: {
208221
edit: {
209222
undoTimeout: 10000 // 10 seconds
@@ -252,12 +265,4 @@ export const environment: BuildConfig = {
252265
enableEndUserAgreement: true,
253266
enablePrivacyStatement: true,
254267
},
255-
//Home Page
256-
homePage: {
257-
recentSubmissions: {
258-
pageSize: 5,
259-
//sort record of recent submission
260-
sortField: 'dc.date.accessioned',
261-
}
262-
}
263268
};

0 commit comments

Comments
 (0)