Skip to content

Commit d95f9d0

Browse files
108588: Passed the scope to the browse sections
1 parent d9759d1 commit d95f9d0

10 files changed

Lines changed: 114 additions & 67 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
6161
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
6262
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
6363
this.subs.push(
64-
observableCombineLatest([this.route.params, this.route.queryParams, this.route.data,
64+
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data,
6565
this.currentPagination$, this.currentSort$]).pipe(
66-
map(([routeParams, queryParams, data, currentPage, currentSort]) => {
67-
return [Object.assign({}, routeParams, queryParams, data), currentPage, currentSort];
66+
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => {
67+
return [Object.assign({}, routeParams, queryParams, data), scope, currentPage, currentSort];
6868
})
69-
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
69+
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
7070
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
7171
this.browseId = params.id || this.defaultBrowseId;
7272
this.startsWith = +params.startsWith || params.startsWith;
73-
const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId, this.fetchThumbnails);
73+
const searchOptions = browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails);
7474
this.updatePageWithItems(searchOptions, this.value, undefined);
7575
this.updateStartsWithOptions(this.browseId, metadataKeys, params.scope);
7676
}));

src/app/browse-by/browse-by-guard.spec.ts

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { first } from 'rxjs/operators';
22
import { BrowseByGuard } from './browse-by-guard';
3-
import { of as observableOf } from 'rxjs';
43
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
54
import { BrowseByDataType } from './browse-by-switcher/browse-by-data-type';
65
import { ValueListBrowseDefinition } from '../core/shared/value-list-browse-definition.model';
7-
import { DSONameServiceMock } from '../shared/mocks/dso-name.service.mock';
8-
import { DSONameService } from '../core/breadcrumbs/dso-name.service';
96
import { RouterStub } from '../shared/testing/router.stub';
107

118
describe('BrowseByGuard', () => {
129
describe('canActivate', () => {
1310
let guard: BrowseByGuard;
14-
let dsoService: any;
1511
let translateService: any;
1612
let browseDefinitionService: any;
1713
let router: any;
@@ -25,10 +21,6 @@ describe('BrowseByGuard', () => {
2521
const browseDefinition = Object.assign(new ValueListBrowseDefinition(), { type: BrowseByDataType.Metadata, metadataKeys: ['dc.contributor'] });
2622

2723
beforeEach(() => {
28-
dsoService = {
29-
findById: (dsoId: string) => observableOf({ payload: { name: name }, hasSucceeded: true })
30-
};
31-
3224
translateService = {
3325
instant: () => field
3426
};
@@ -39,7 +31,7 @@ describe('BrowseByGuard', () => {
3931

4032
router = new RouterStub() as any;
4133

42-
guard = new BrowseByGuard(dsoService, translateService, browseDefinitionService, new DSONameServiceMock() as DSONameService, router);
34+
guard = new BrowseByGuard(translateService, browseDefinitionService, router);
4335
});
4436

4537
it('should return true, and sets up the data correctly, with a scope and value', () => {
@@ -48,6 +40,7 @@ describe('BrowseByGuard', () => {
4840
title: field,
4941
browseDefinition,
5042
},
43+
parent: null,
5144
params: {
5245
id,
5346
},
@@ -64,7 +57,7 @@ describe('BrowseByGuard', () => {
6457
title,
6558
id,
6659
browseDefinition,
67-
collection: name,
60+
scope,
6861
field,
6962
value: '"' + value + '"'
7063
};
@@ -97,7 +90,7 @@ describe('BrowseByGuard', () => {
9790
title,
9891
id,
9992
browseDefinition,
100-
collection: name,
93+
scope,
10194
field,
10295
value: ''
10396
};
@@ -108,12 +101,48 @@ describe('BrowseByGuard', () => {
108101
);
109102
});
110103

104+
it('should return true, and sets up the data correctly using the community/collection page id, with a scope and without value', () => {
105+
const scopedNoValueRoute = {
106+
data: {
107+
title: field,
108+
browseDefinition,
109+
},
110+
parent: {
111+
params: {
112+
id: scope,
113+
},
114+
},
115+
params: {
116+
id,
117+
},
118+
queryParams: {
119+
},
120+
};
121+
122+
guard.canActivate(scopedNoValueRoute as any, undefined).pipe(
123+
first(),
124+
).subscribe((canActivate) => {
125+
const result = {
126+
title,
127+
id,
128+
browseDefinition,
129+
scope,
130+
field,
131+
value: '',
132+
};
133+
expect(scopedNoValueRoute.data).toEqual(result);
134+
expect(router.navigate).not.toHaveBeenCalled();
135+
expect(canActivate).toEqual(true);
136+
});
137+
});
138+
111139
it('should return true, and sets up the data correctly, without a scope and with a value', () => {
112140
const route = {
113141
data: {
114142
title: field,
115143
browseDefinition,
116144
},
145+
parent: null,
117146
params: {
118147
id,
119148
},
@@ -129,7 +158,7 @@ describe('BrowseByGuard', () => {
129158
title,
130159
id,
131160
browseDefinition,
132-
collection: '',
161+
scope: undefined,
133162
field,
134163
value: '"' + value + '"'
135164
};
@@ -147,6 +176,7 @@ describe('BrowseByGuard', () => {
147176
data: {
148177
title: field,
149178
},
179+
parent: null,
150180
params: {
151181
id,
152182
},
Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
1+
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, Data } from '@angular/router';
22
import { Injectable } from '@angular/core';
3-
import { DSpaceObjectDataService } from '../core/data/dspace-object-data.service';
43
import { hasNoValue, hasValue } from '../shared/empty.util';
54
import { map, switchMap } from 'rxjs/operators';
6-
import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from '../core/shared/operators';
5+
import { getFirstCompletedRemoteData } from '../core/shared/operators';
76
import { TranslateService } from '@ngx-translate/core';
87
import { Observable, of as observableOf } from 'rxjs';
98
import { BrowseDefinitionDataService } from '../core/browse/browse-definition-data.service';
109
import { BrowseDefinition } from '../core/shared/browse-definition.model';
11-
import { DSONameService } from '../core/breadcrumbs/dso-name.service';
12-
import { DSpaceObject } from '../core/shared/dspace-object.model';
1310
import { RemoteData } from '../core/data/remote-data';
1411
import { PAGE_NOT_FOUND_PATH } from '../app-routing-paths';
1512

@@ -19,11 +16,10 @@ import { PAGE_NOT_FOUND_PATH } from '../app-routing-paths';
1916
*/
2017
export class BrowseByGuard implements CanActivate {
2118

22-
constructor(protected dsoService: DSpaceObjectDataService,
23-
protected translate: TranslateService,
24-
protected browseDefinitionService: BrowseDefinitionDataService,
25-
protected dsoNameService: DSONameService,
26-
protected router: Router,
19+
constructor(
20+
protected translate: TranslateService,
21+
protected browseDefinitionService: BrowseDefinitionDataService,
22+
protected router: Router,
2723
) {
2824
}
2925

@@ -39,25 +35,14 @@ export class BrowseByGuard implements CanActivate {
3935
} else {
4036
browseDefinition$ = observableOf(route.data.browseDefinition);
4137
}
42-
const scope = route.queryParams.scope;
38+
const scope = route.queryParams.scope ?? route.parent?.params.id;
4339
const value = route.queryParams.value;
4440
const metadataTranslated = this.translate.instant(`browse.metadata.${id}`);
4541
return browseDefinition$.pipe(
4642
switchMap((browseDefinition: BrowseDefinition | undefined) => {
4743
if (hasValue(browseDefinition)) {
48-
if (hasValue(scope)) {
49-
const dso$: Observable<DSpaceObject> = this.dsoService.findById(scope).pipe(getFirstSucceededRemoteDataPayload());
50-
return dso$.pipe(
51-
map((dso: DSpaceObject) => {
52-
const name = this.dsoNameService.getName(dso);
53-
route.data = this.createData(title, id, browseDefinition, name, metadataTranslated, value, route);
54-
return true;
55-
})
56-
);
57-
} else {
58-
route.data = this.createData(title, id, browseDefinition, '', metadataTranslated, value, route);
59-
return observableOf(true);
60-
}
44+
route.data = this.createData(title, id, browseDefinition, metadataTranslated, value, route, scope);
45+
return observableOf(true);
6146
} else {
6247
void this.router.navigate([PAGE_NOT_FOUND_PATH]);
6348
return observableOf(false);
@@ -66,14 +51,14 @@ export class BrowseByGuard implements CanActivate {
6651
);
6752
}
6853

69-
private createData(title, id, browseDefinition, collection, field, value, route) {
54+
private createData(title: string, id: string, browseDefinition: BrowseDefinition, field: string, value: string, route: ActivatedRouteSnapshot, scope: string): Data {
7055
return Object.assign({}, route.data, {
7156
title: title,
7257
id: id,
7358
browseDefinition: browseDefinition,
74-
collection: collection,
7559
field: field,
76-
value: hasValue(value) ? `"${value}"` : ''
60+
value: hasValue(value) ? `"${value}"` : '',
61+
scope: scope,
7762
});
7863
}
7964
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ describe('BrowseByMetadataComponent', () => {
170170
field: 'fake-field',
171171
};
172172

173-
result = browseParamsToOptions(paramsScope, paginationOptions, sortOptions, 'author', comp.fetchThumbnails);
173+
result = browseParamsToOptions(paramsScope, 'fake-scope', paginationOptions, sortOptions, 'author', comp.fetchThumbnails);
174174
});
175175

176176
it('should return BrowseEntrySearchOptions with the correct properties', () => {

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
2-
import { Component, Inject, OnInit, OnDestroy, Input } from '@angular/core';
1+
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
2+
import { Component, Inject, OnInit, OnDestroy, Input, OnChanges } from '@angular/core';
33
import { RemoteData } from '../../core/data/remote-data';
44
import { PaginatedList } from '../../core/data/paginated-list.model';
55
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
@@ -35,7 +35,7 @@ export const BBM_PAGINATION_ID = 'bbm';
3535
* 'dc.contributor.*'
3636
*/
3737
@rendersBrowseBy(BrowseByDataType.Metadata)
38-
export class BrowseByMetadataComponent implements OnInit, OnDestroy {
38+
export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
3939

4040
/**
4141
* The optional context
@@ -47,6 +47,13 @@ export class BrowseByMetadataComponent implements OnInit, OnDestroy {
4747
*/
4848
@Input() browseByType: BrowseByDataType;
4949

50+
/**
51+
* The ID of the {@link Community} or {@link Collection} of the scope to display
52+
*/
53+
@Input() scope: string;
54+
55+
scope$: BehaviorSubject<string> = new BehaviorSubject(undefined);
56+
5057
/**
5158
* The list of browse-entries to display
5259
*/
@@ -145,12 +152,12 @@ export class BrowseByMetadataComponent implements OnInit, OnDestroy {
145152
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
146153
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
147154
this.subs.push(
148-
observableCombineLatest([this.route.params, this.route.queryParams, this.currentPagination$, this.currentSort$]).pipe(
149-
map(([routeParams, queryParams, currentPage, currentSort]) => {
150-
return [Object.assign({}, routeParams, queryParams),currentPage,currentSort];
155+
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
156+
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
157+
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
151158
})
152-
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
153-
this.browseId = params.id || this.defaultBrowseId;
159+
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
160+
this.browseId = params.id || this.defaultBrowseId;
154161
this.authority = params.authority;
155162

156163
if (typeof params.value === 'string'){
@@ -164,16 +171,19 @@ export class BrowseByMetadataComponent implements OnInit, OnDestroy {
164171
}
165172

166173
if (isNotEmpty(this.value)) {
167-
this.updatePageWithItems(
168-
browseParamsToOptions(params, currentPage, currentSort, this.browseId, this.fetchThumbnails), this.value, this.authority);
174+
this.updatePageWithItems(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails), this.value, this.authority);
169175
} else {
170-
this.updatePage(browseParamsToOptions(params, currentPage, currentSort, this.browseId, false));
176+
this.updatePage(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, false));
171177
}
172178
}));
173179
this.updateStartsWithTextOptions();
174180

175181
}
176182

183+
ngOnChanges(): void {
184+
this.scope$.next(this.scope);
185+
}
186+
177187
/**
178188
* Update the StartsWith options with text values
179189
* It adds the value "0-9" as well as all letters from A to Z
@@ -268,12 +278,14 @@ export function getBrowseSearchOptions(defaultBrowseId: string,
268278
/**
269279
* Function to transform query and url parameters into searchOptions used to fetch browse entries or items
270280
* @param params URL and query parameters
281+
* @param scope The scope to show the results
271282
* @param paginationConfig Pagination configuration
272283
* @param sortConfig Sorting configuration
273284
* @param metadata Optional metadata definition to fetch browse entries/items for
274285
* @param fetchThumbnail Optional parameter for requesting thumbnail images
275286
*/
276287
export function browseParamsToOptions(params: any,
288+
scope: string,
277289
paginationConfig: PaginationComponentOptions,
278290
sortConfig: SortOptions,
279291
metadata?: string,
@@ -283,7 +295,7 @@ export function browseParamsToOptions(params: any,
283295
paginationConfig,
284296
sortConfig,
285297
params.startsWith,
286-
params.scope,
298+
scope,
287299
fetchThumbnail
288300
);
289301
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<
1515

1616
@Input() browseByType: BrowseByDataType;
1717

18+
@Input() scope: string;
19+
1820
protected inputNamesDependentForComponent: (keyof this & string)[] = [
1921
'context',
2022
'browseByType',
@@ -23,6 +25,7 @@ export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<
2325
protected inputNames: (keyof this & string)[] = [
2426
'context',
2527
'browseByType',
28+
'scope',
2629
];
2730

2831
public getComponent(): GenericConstructor<Component> {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
1+
import { Component, OnInit, OnChanges, OnDestroy, Input } from '@angular/core';
22
import { VocabularyOptions } from '../../core/submission/vocabularies/models/vocabulary-options.model';
33
import { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
44
import { ActivatedRoute } from '@angular/router';
5-
import { Observable, Subscription } from 'rxjs';
5+
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
66
import { BrowseDefinition } from '../../core/shared/browse-definition.model';
77
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
88
import { map } from 'rxjs/operators';
@@ -19,7 +19,7 @@ import { Context } from '../../core/shared/context.model';
1919
* Component for browsing items by metadata in a hierarchical controlled vocabulary
2020
*/
2121
@rendersBrowseBy(BrowseByDataType.Hierarchy)
22-
export class BrowseByTaxonomyComponent implements OnInit, OnDestroy {
22+
export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
2323

2424
/**
2525
* The optional context
@@ -31,6 +31,13 @@ export class BrowseByTaxonomyComponent implements OnInit, OnDestroy {
3131
*/
3232
@Input() browseByType: BrowseByDataType;
3333

34+
/**
35+
* The ID of the {@link Community} or {@link Collection} of the scope to display
36+
*/
37+
@Input() scope: string;
38+
39+
scope$: BehaviorSubject<string> = new BehaviorSubject(undefined);
40+
3441
/**
3542
* The {@link VocabularyOptions} object
3643
*/
@@ -89,6 +96,10 @@ export class BrowseByTaxonomyComponent implements OnInit, OnDestroy {
8996
}));
9097
}
9198

99+
ngOnChanges(): void {
100+
this.scope$.next(this.scope);
101+
}
102+
92103
/**
93104
* Adds detail to selectedItems, transforms it to be used as query parameter
94105
* and adds that to filterValues.

0 commit comments

Comments
 (0)