Skip to content

Commit 2dc67bd

Browse files
tdonohuejsutton24
authored andcommitted
Merge pull request #3741 from atmire/w2p-122064_browse-pages-ignore-sort-config-fix-UI-main
browse pages should not ignore sort config from back end
1 parent 1116ead commit 2dc67bd

8 files changed

Lines changed: 72 additions & 63 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ describe('BrowseByDateComponent', () => {
8989
getBrowseEntriesFor: (options: BrowseEntrySearchOptions) => toRemoteData([]),
9090
getBrowseItemsFor: (value: string, options: BrowseEntrySearchOptions) => toRemoteData([firstItem]),
9191
getFirstItemFor: (definition: string, scope?: string, sortDirection?: SortDirection) => null,
92+
getConfiguredSortDirection: () => of(SortDirection.DESC),
9293
};
9394

9495
const mockDsoService = {

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '@angular/core';
1212
import {
1313
ActivatedRoute,
14-
Params,
1514
Router,
1615
} from '@angular/router';
1716
import { TranslateModule } from '@ngx-translate/core';
@@ -21,8 +20,8 @@ import {
2120
of,
2221
} from 'rxjs';
2322
import {
24-
distinctUntilChanged,
2523
map,
24+
switchMap,
2625
} from 'rxjs/operators';
2726
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';
2827

@@ -47,7 +46,6 @@ import {
4746
isNotEmpty,
4847
} from '../../shared/empty.util';
4948
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
50-
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
5149
import { StartsWithType } from '../../shared/starts-with/starts-with-type';
5250
import {
5351
BrowseByMetadataComponent,
@@ -96,27 +94,23 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
9694
this.loading$ = of(false);
9795
return;
9896
}
99-
const sortConfig = new SortOptions('default', SortDirection.ASC);
97+
this.browseId = this.route.snapshot.params.id;
10098
this.startsWithType = StartsWithType.date;
101-
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
102-
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
103-
const routeParams$: Observable<Params> = observableCombineLatest([
104-
this.route.params,
105-
this.route.queryParams,
106-
]).pipe(
107-
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
108-
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
109-
);
99+
110100
this.subs.push(
111-
observableCombineLatest([
112-
routeParams$,
113-
this.scope$,
114-
this.currentPagination$,
115-
this.currentSort$,
116-
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
101+
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
102+
map((sortDir) => new SortOptions(this.browseId, sortDir)),
103+
switchMap((sortConfig) => {
104+
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
105+
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
106+
return observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data, this.currentPagination$, this.currentSort$]).pipe(
107+
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => ({
108+
params: Object.assign({}, routeParams, queryParams, data), scope, currentPage, currentSort,
109+
})));
110+
})).subscribe(({ params, scope, currentPage, currentSort }) => {
117111
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
118-
this.browseId = params.id;
119112
this.startsWith = +params.startsWith || params.startsWith;
113+
this.browseId = params.id;
120114
const searchOptions = browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails);
121115
this.updatePageWithItems(searchOptions, this.value, undefined);
122116
this.updateStartsWithOptions(this.browseId, metadataKeys, params.scope);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ describe('BrowseByMetadataComponent', () => {
117117
const mockBrowseService = {
118118
getBrowseEntriesFor: (options: BrowseEntrySearchOptions) => toRemoteData(mockEntries),
119119
getBrowseItemsFor: (value: string, options: BrowseEntrySearchOptions) => toRemoteData(mockItems),
120+
getConfiguredSortDirection: () => of(SortDirection.ASC),
120121
};
121122

122123
const mockDsoService = {

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from '@angular/core';
1515
import {
1616
ActivatedRoute,
17-
Params,
1817
Router,
1918
} from '@angular/router';
2019
import { TranslateModule } from '@ngx-translate/core';
@@ -26,8 +25,8 @@ import {
2625
Subscription,
2726
} from 'rxjs';
2827
import {
29-
distinctUntilChanged,
3028
map,
29+
switchMap,
3130
} from 'rxjs/operators';
3231
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';
3332

@@ -209,24 +208,18 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
209208
this.loading$ = of(false);
210209
return;
211210
}
212-
const sortConfig = new SortOptions('default', SortDirection.ASC);
213-
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
214-
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
215-
const routeParams$: Observable<Params> = observableCombineLatest([
216-
this.route.params,
217-
this.route.queryParams,
218-
]).pipe(
219-
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
220-
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.authority === curr.authority && prev.value === curr.value && prev.startsWith === curr.startsWith),
221-
);
211+
this.browseId = this.route.snapshot.params.id;
222212
this.subs.push(
223-
observableCombineLatest([
224-
routeParams$,
225-
this.scope$,
226-
this.currentPagination$,
227-
this.currentSort$,
228-
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
229-
this.browseId = params.id;
213+
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
214+
map((sortDir) => new SortOptions(this.browseId, sortDir)),
215+
switchMap((sortConfig) => {
216+
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
217+
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
218+
return observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
219+
map(([routeParams, queryParams, scope, currentPage, currentSort]) => ({
220+
params: Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort,
221+
})));
222+
})).subscribe(({ params, scope, currentPage, currentSort }) => {
230223
this.authority = params.authority;
231224

232225
if (typeof params.value === 'string') {
@@ -250,9 +243,8 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
250243
} else {
251244
this.updatePage(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, false));
252245
}
246+
this.updateStartsWithTextOptions();
253247
}));
254-
this.updateStartsWithTextOptions();
255-
256248
}
257249

258250
ngOnChanges(changes: SimpleChanges): void {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { of } from 'rxjs';
2222
import { APP_CONFIG } from '../../../config/app-config.interface';
2323
import { environment } from '../../../environments/environment';
2424
import { BrowseService } from '../../core/browse/browse.service';
25+
import { SortDirection } from '../../core/cache/models/sort-options.model';
2526
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
2627
import { ItemDataService } from '../../core/data/item-data.service';
2728
import { PaginationService } from '../../core/pagination/pagination.service';
@@ -76,6 +77,7 @@ describe('BrowseByTitleComponent', () => {
7677
const mockBrowseService = {
7778
getBrowseItemsFor: () => toRemoteData(mockItems),
7879
getBrowseEntriesFor: () => toRemoteData([]),
80+
getConfiguredSortDirection: () => of(SortDirection.ASC),
7981
};
8082

8183
const mockDsoService = {

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ import {
66
Component,
77
OnInit,
88
} from '@angular/core';
9-
import { Params } from '@angular/router';
109
import { TranslateModule } from '@ngx-translate/core';
1110
import {
1211
combineLatest as observableCombineLatest,
13-
Observable,
1412
of,
1513
} from 'rxjs';
1614
import {
17-
distinctUntilChanged,
1815
map,
16+
switchMap,
1917
} from 'rxjs/operators';
2018

2119
import { environment } from '../../../environments/environment';
@@ -25,7 +23,6 @@ import {
2523
} from '../../core/cache/models/sort-options.model';
2624
import { ThemedBrowseByComponent } from '../../shared/browse-by/themed-browse-by.component';
2725
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
28-
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
2926
import {
3027
BrowseByMetadataComponent,
3128
browseParamsToOptions,
@@ -52,28 +49,23 @@ export class BrowseByTitleComponent extends BrowseByMetadataComponent implements
5249
this.loading$ = of(false);
5350
return;
5451
}
55-
const sortConfig = new SortOptions('dc.title', SortDirection.ASC);
56-
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
57-
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
58-
const routeParams$: Observable<Params> = observableCombineLatest([
59-
this.route.params,
60-
this.route.queryParams,
61-
]).pipe(
62-
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
63-
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
64-
);
52+
this.browseId = this.route.snapshot.params.id;
6553
this.subs.push(
66-
observableCombineLatest([
67-
routeParams$,
68-
this.scope$,
69-
this.currentPagination$,
70-
this.currentSort$,
71-
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
54+
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
55+
map((sortDir) => new SortOptions(this.browseId, sortDir)),
56+
switchMap((sortConfig) => {
57+
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
58+
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
59+
return observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
60+
map(([routeParams, queryParams, scope, currentPage, currentSort]) => ({
61+
params: Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort,
62+
})),
63+
);
64+
})).subscribe(({ params, scope, currentPage, currentSort }) => {
7265
this.startsWith = +params.startsWith || params.startsWith;
73-
this.browseId = params.id;
7466
this.updatePageWithItems(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails), undefined, undefined);
67+
this.updateStartsWithTextOptions();
7568
}));
76-
this.updateStartsWithTextOptions();
7769
}
7870

7971
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ 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+
if (browseDef.order === SortDirection.ASC || browseDef.order === SortDirection.DESC) {
145+
return browseDef.order;
146+
} else {
147+
return defaultDirection;
148+
}
149+
}),
150+
);
151+
}
152+
130153
/**
131154
* Get all items linked to a certain metadata value
132155
* @param {string} filterValue metadata value to filter by (e.g. author's name)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55

66
import { BrowseByDataType } from '../../browse-by/browse-by-switcher/browse-by-data-type';
77
import { CacheableObject } from '../cache/cacheable-object.model';
8+
import { SortDirection } from '../cache/models/sort-options.model';
89

910
/**
1011
* Base class for BrowseDefinition models
@@ -17,6 +18,9 @@ export abstract class BrowseDefinition extends CacheableObject {
1718
@autoserializeAs('metadata')
1819
metadataKeys: string[];
1920

21+
@autoserialize
22+
order: SortDirection;
23+
2024
/**
2125
* Get the render type of the BrowseDefinition model
2226
*/

0 commit comments

Comments
 (0)