Skip to content

Commit 86c30e9

Browse files
author
Jens Vannerum
committed
122064: fetch configured sort option of browse definition before first call so default sort option isn't ignored
1 parent dcea3ba commit 86c30e9

5 files changed

Lines changed: 58 additions & 28 deletions

File tree

src/app/browse-by/browse-by-date/browse-by-date.component.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,29 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
102102
}
103103

104104
ngOnInit(): void {
105-
const sortConfig = new SortOptions('default', SortDirection.ASC);
105+
this.browseId = this.route.snapshot.params.id;
106106
this.startsWithType = StartsWithType.date;
107-
// include the thumbnail configuration in browse search options
108-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig, this.fetchThumbnails));
109-
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
110-
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
107+
111108
this.subs.push(
112-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data,
113-
this.currentPagination$, this.currentSort$]).pipe(
114-
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => {
115-
return [Object.assign({}, routeParams, queryParams, data), scope, currentPage, currentSort];
116-
}),
117-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
109+
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
110+
map((sortDir) => new SortOptions(this.browseId, sortDir)),
111+
switchMap((sortConfig) => {
112+
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
113+
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
114+
return observableCombineLatest([this.route.params, this.route.queryParams, this.route.data, this.currentPagination$, this.currentSort$]).pipe(
115+
map(([routeParams, queryParams, data, currentPage, currentSort]) => ({
116+
params: Object.assign({}, routeParams, queryParams, data), currentPage, currentSort
117+
})));
118+
})).subscribe(({ params, currentPage, currentSort }) => {
118119
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
119-
this.browseId = params.id || this.defaultBrowseId;
120120
this.startsWith = +params.startsWith || params.startsWith;
121-
const searchOptions = browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails);
121+
const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId, this.fetchThumbnails);
122122
this.updatePageWithItems(searchOptions, this.value, undefined);
123+
this.updateParent(params.scope);
124+
this.updateLogo();
123125
this.updateStartsWithOptions(this.browseId, metadataKeys, params.scope);
124-
}));
126+
})
127+
);
125128
}
126129

127130
/**

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,18 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
210210

211211

212212
ngOnInit(): void {
213-
214-
const sortConfig = new SortOptions('default', SortDirection.ASC);
215-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig));
216-
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
217-
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
213+
this.browseId = this.route.snapshot.params.id;
218214
this.subs.push(
219-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
220-
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
221-
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
222-
}),
223-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
224-
this.browseId = params.id || this.defaultBrowseId;
215+
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
216+
map((sortDir) => new SortOptions(this.browseId, sortDir)),
217+
switchMap((sortConfig) => {
218+
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
219+
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
220+
return observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
221+
map(([routeParams, queryParams, scope, currentPage, currentSort]) => ({
222+
params: Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort
223+
})));
224+
})).subscribe(({ params, scope, currentPage, currentSort }) => {
225225
this.authority = params.authority;
226226

227227
if (typeof params.value === 'string') {
@@ -241,11 +241,10 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
241241
if (isNotEmpty(this.value)) {
242242
this.updatePageWithItems(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails), this.value, this.authority);
243243
} else {
244-
this.updatePage(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, false));
244+
is.updatePage(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, false));
245245
}
246+
this.updateStartsWithTextOptions();
246247
}));
247-
this.updateStartsWithTextOptions();
248-
249248
}
250249

251250
ngOnChanges(): void {

src/app/browse-by/browse-by-title-page/browse-by-title-page.component.ts

Whitespace-only changes.

src/app/core/browse/browse.service.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,31 @@ export class BrowseService {
127127
return this.hrefOnlyDataService.findListByHref<BrowseEntry>(href$);
128128
}
129129

130+
/*
131+
* Get the sort direction for a browse index based on its unique id
132+
* @param browseId The unique id of the browse index
133+
* @param defaultDirection The default sort direction to return if the browse index has no sort direction configured
134+
* @returns {Observable<SortDirection>} The sort direction of the browse index
135+
*/
136+
getConfiguredSortDirection(browseId: string, defaultDirection: SortDirection): Observable<SortDirection> {
137+
return this.getBrowseDefinitions().pipe(
138+
getRemoteDataPayload(),
139+
getPaginatedListPayload(),
140+
map((browseDefinitions: BrowseDefinition[]) => browseDefinitions
141+
.find((def: BrowseDefinition) => def.id === browseId)
142+
),
143+
map((browseDef: BrowseDefinition) => {
144+
console.log('comparing for browseDef', browseDef);
145+
if (browseDef.order === SortDirection.ASC || browseDef.order === SortDirection.DESC) {
146+
console.log('returning browseDef.order', browseDef.order);
147+
return browseDef.order;
148+
} else {
149+
return defaultDirection;
150+
}
151+
}),
152+
);
153+
}
154+
130155
/**
131156
* Get all items linked to a certain metadata value
132157
* @param {string} filterValue metadata value to filter by (e.g. author's name)

src/app/core/shared/browse-definition.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export abstract class BrowseDefinition extends CacheableObject {
1111
@autoserialize
1212
id: string;
1313

14+
@autoserialize
15+
order: string;
16+
1417
/**
1518
* Get the render type of the BrowseDefinition model
1619
*/

0 commit comments

Comments
 (0)