Skip to content

Commit db4ad7f

Browse files
committed
Resolve feedback
Inject environment rather than importing it Redo the configuration for better consistency across pages
1 parent 2bd02f8 commit db4ad7f

9 files changed

Lines changed: 65 additions & 39 deletions

config/config.example.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,15 @@ browseBy:
169169
# The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items)
170170
defaultLowerLimit: 1900
171171

172-
browseCommunities:
173-
communityListPageSize: 20
174-
topLevelPageSize: 5
172+
communityList:
173+
# No. of communities to list per expansion (show more)
174+
pageSize: 20
175+
176+
home:
177+
topLevelCommunityList:
178+
# No. of communities to list per page on the home page
179+
# 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
180+
pageSize: 5
175181

176182
# Item Config
177183
item:

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.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.home.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,8 @@ 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 { BrowseCommunitiesConfig } from './browse-communities-config.interface';
20+
import { CommunityListPageConfig } from './community-list-page-config.interface';
21+
import { HomePageConfig } from './home-page-config.interface';
2122

2223
interface AppConfig extends Config {
2324
ui: UIServerConfig;
@@ -32,7 +33,8 @@ interface AppConfig extends Config {
3233
defaultLanguage: string;
3334
languages: LangConfig[];
3435
browseBy: BrowseByConfig;
35-
browseCommunities: BrowseCommunitiesConfig;
36+
communityList: CommunityListPageConfig;
37+
home: HomePageConfig;
3638
item: ItemConfig;
3739
collection: CollectionPageConfig;
3840
themes: ThemeConfig[];

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 CommunityListPageConfig extends Config {
4+
pageSize: number;
5+
}

src/config/default-app-config.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ 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 { BrowseCommunitiesConfig } from './browse-communities-config.interface';
20+
import { CommunityListPageConfig } from './community-list-page-config.interface';
21+
import { HomePageConfig } from './home-page-config.interface';
2122

2223
export class DefaultAppConfig implements AppConfig {
2324
production = false;
@@ -209,10 +210,15 @@ export class DefaultAppConfig implements AppConfig {
209210
defaultLowerLimit: 1900
210211
};
211212

212-
browseCommunities: BrowseCommunitiesConfig = {
213-
communityListPageSize: 20,
214-
topLevelPageSize: 5
215-
}
213+
communityList: CommunityListPageConfig = {
214+
pageSize: 20
215+
};
216+
217+
home: HomePageConfig = {
218+
topLevelCommunityList: {
219+
pageSize: 5
220+
}
221+
};
216222

217223
// Item Config
218224
item: ItemConfig = {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Config } from './config.interface';
2+
3+
export interface HomePageConfig extends Config {
4+
topLevelCommunityList: {
5+
pageSize: number;
6+
};
7+
}

src/environments/environment.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,13 @@ export const environment: BuildConfig = {
200200
// The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items)
201201
defaultLowerLimit: 1900,
202202
},
203-
browseCommunities: {
204-
communityListPageSize: 20,
205-
topLevelPageSize: 5
203+
communityList: {
204+
pageSize: 20
205+
},
206+
home: {
207+
topLevelCommunityList: {
208+
pageSize: 5
209+
}
206210
},
207211
item: {
208212
edit: {

0 commit comments

Comments
 (0)