Skip to content

Commit 086bd47

Browse files
committed
Resolve feedback
Inject environment rather than importing it Redo the configuration for better consistency across pages
1 parent 3e803e8 commit 086bd47

11 files changed

Lines changed: 84 additions & 64 deletions

config/config.example.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,20 @@ 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-
browseCommunities:
179-
communityListPageSize: 20
180-
topLevelPageSize: 5
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
181192

182193
# Item Config
183194
item:
@@ -268,10 +279,3 @@ mediaViewer:
268279
info:
269280
enableEndUserAgreement: true
270281
enablePrivacyStatement: true
271-
# Home Page
272-
homePage:
273-
recentSubmissions:
274-
# The number of item showing in recent submission components
275-
pageSize: 5
276-
# Sort record of recent submission
277-
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 & 9 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,7 +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 { environment } from 'src/environments/environment';
26+
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
2727

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

84-
export const MAX_COMCOLS_PER_PAGE = environment.browseCommunities.communityListPageSize;
85-
8684
/**
8785
* Service class for the community list, responsible for the creating of the flat list used by communityList dataSource
8886
* and connection to the store to retrieve and save the state of the community list
8987
*/
9088
@Injectable()
9189
export class CommunityListService {
9290

93-
constructor(private communityDataService: CommunityDataService, private collectionDataService: CollectionDataService,
94-
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;
95100
}
96101

97102
private configOnePage: FindListOptions = Object.assign(new FindListOptions(), {
@@ -146,7 +151,7 @@ export class CommunityListService {
146151
private getTopCommunities(options: FindListOptions): Observable<PaginatedList<Community>> {
147152
return this.communityDataService.findTop({
148153
currentPage: options.currentPage,
149-
elementsPerPage: MAX_COMCOLS_PER_PAGE,
154+
elementsPerPage: this.pageSize,
150155
sort: {
151156
field: options.sort.field,
152157
direction: options.sort.direction
@@ -217,7 +222,7 @@ export class CommunityListService {
217222
let subcoms = [];
218223
for (let i = 1; i <= currentCommunityPage; i++) {
219224
const nextSetOfSubcommunitiesPage = this.communityDataService.findByParent(community.uuid, {
220-
elementsPerPage: MAX_COMCOLS_PER_PAGE,
225+
elementsPerPage: this.pageSize,
221226
currentPage: i
222227
},
223228
followLink('subcommunities', { findListOptions: this.configOnePage }),
@@ -242,7 +247,7 @@ export class CommunityListService {
242247
let collections = [];
243248
for (let i = 1; i <= currentCollectionPage; i++) {
244249
const nextSetOfCollectionsPage = this.collectionDataService.findByParent(community.uuid, {
245-
elementsPerPage: MAX_COMCOLS_PER_PAGE,
250+
elementsPerPage: this.pageSize,
246251
currentPage: i
247252
})
248253
.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 & 5 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,7 +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 { environment } from 'src/environments/environment';
15+
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
1616

1717
/**
1818
* this component renders the Top-Level Community list
@@ -51,11 +51,14 @@ export class TopLevelCommunityListComponent implements OnInit, OnDestroy {
5151
*/
5252
currentPageSubscription: Subscription;
5353

54-
constructor(private cds: CommunityDataService,
55-
private paginationService: PaginationService) {
54+
constructor(
55+
@Inject(APP_CONFIG) protected appConfig: AppConfig,
56+
private cds: CommunityDataService,
57+
private paginationService: PaginationService
58+
) {
5659
this.config = new PaginationComponentOptions();
5760
this.config.id = this.pageId;
58-
this.config.pageSize = environment.browseCommunities.topLevelPageSize;
61+
this.config.pageSize = appConfig.homePage.topLevelCommunityList.pageSize;
5962
this.config.currentPage = 1;
6063
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
6164
}

src/config/app-config.interface.ts

Lines changed: 4 additions & 2 deletions
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,15 +33,15 @@ interface AppConfig extends Config {
3133
defaultLanguage: string;
3234
languages: LangConfig[];
3335
browseBy: BrowseByConfig;
34-
browseCommunities: BrowseCommunitiesConfig;
36+
communityList: CommunityListConfig;
37+
homePage: HomeConfig;
3538
item: ItemConfig;
3639
collection: CollectionPageConfig;
3740
themes: ThemeConfig[];
3841
mediaViewer: MediaViewerConfig;
3942
bundle: BundleConfig;
4043
actuators: ActuatorsConfig
4144
info: InfoConfig;
42-
homePage: HomeConfig;
4345
}
4446

4547
/**

src/config/browse-communities-config.interface.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
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: 17 additions & 13 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,10 +212,21 @@ export class DefaultAppConfig implements AppConfig {
210212
defaultLowerLimit: 1900
211213
};
212214

213-
browseCommunities: BrowseCommunitiesConfig = {
214-
communityListPageSize: 20,
215-
topLevelPageSize: 5
216-
}
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+
};
217230

218231
// Item Config
219232
item: ItemConfig = {
@@ -345,13 +358,4 @@ export class DefaultAppConfig implements AppConfig {
345358
enableEndUserAgreement: true,
346359
enablePrivacyStatement: true
347360
};
348-
// Home Pages
349-
homePage: HomeConfig = {
350-
recentSubmissions: {
351-
//The number of item showing in recent submission components
352-
pageSize: 5,
353-
//sort record of recent submission
354-
sortField: 'dc.date.accessioned',
355-
}
356-
};
357361
}

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
}

0 commit comments

Comments
 (0)