w2p-85847 Add Authority to browse indexes

This commit is contained in:
Nathan Buckingham
2021-12-13 13:48:09 -05:00
parent 768de1a1e7
commit e2614b9dad
7 changed files with 45 additions and 9 deletions

View File

@@ -63,7 +63,7 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
this.browseId = params.id || this.defaultBrowseId; this.browseId = params.id || this.defaultBrowseId;
this.startsWith = +params.startsWith || params.startsWith; this.startsWith = +params.startsWith || params.startsWith;
const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId); const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId);
this.updatePageWithItems(searchOptions, this.value); this.updatePageWithItems(searchOptions, this.value, undefined);
this.updateParent(params.scope); this.updateParent(params.scope);
this.updateStartsWithOptions(this.browseId, metadataField, params.scope); this.updateStartsWithOptions(this.browseId, metadataField, params.scope);
})); }));

View File

@@ -99,6 +99,11 @@ export class BrowseByMetadataPageComponent implements OnInit {
*/ */
value = ''; value = '';
/**
* The authority key (may be undefined) associated with {@link #value}.
*/
authority: string;
/** /**
* The current startsWith option (fetched and updated from query-params) * The current startsWith option (fetched and updated from query-params)
*/ */
@@ -123,11 +128,12 @@ export class BrowseByMetadataPageComponent implements OnInit {
}) })
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => { ).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
this.browseId = params.id || this.defaultBrowseId; this.browseId = params.id || this.defaultBrowseId;
this.authority = params.authority;
this.value = +params.value || params.value || ''; this.value = +params.value || params.value || '';
this.startsWith = +params.startsWith || params.startsWith; this.startsWith = +params.startsWith || params.startsWith;
const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId); const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId);
if (isNotEmpty(this.value)) { if (isNotEmpty(this.value)) {
this.updatePageWithItems(searchOptions, this.value); this.updatePageWithItems(searchOptions, this.value, this.authority);
} else { } else {
this.updatePage(searchOptions); this.updatePage(searchOptions);
} }
@@ -166,8 +172,8 @@ export class BrowseByMetadataPageComponent implements OnInit {
* scope: string } * scope: string }
* @param value The value of the browse-entry to display items for * @param value The value of the browse-entry to display items for
*/ */
updatePageWithItems(searchOptions: BrowseEntrySearchOptions, value: string) { updatePageWithItems(searchOptions: BrowseEntrySearchOptions, value: string, authority: string) {
this.items$ = this.browseService.getBrowseItemsFor(value, searchOptions); this.items$ = this.browseService.getBrowseItemsFor(value, authority, searchOptions);
} }
/** /**

View File

@@ -46,7 +46,7 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
}) })
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => { ).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
this.browseId = params.id || this.defaultBrowseId; this.browseId = params.id || this.defaultBrowseId;
this.updatePageWithItems(browseParamsToOptions(params, currentPage, currentSort, this.browseId), undefined); this.updatePageWithItems(browseParamsToOptions(params, currentPage, currentSort, this.browseId), undefined, undefined);
this.updateParent(params.scope); this.updateParent(params.scope);
})); }));
this.updateStartsWithTextOptions(); this.updateStartsWithTextOptions();

View File

@@ -129,6 +129,7 @@ describe('BrowseService', () => {
describe('getBrowseEntriesFor and findList', () => { describe('getBrowseEntriesFor and findList', () => {
// should contain special characters such that url encoding can be tested as well // should contain special characters such that url encoding can be tested as well
const mockAuthorName = 'Donald Smith & Sons'; const mockAuthorName = 'Donald Smith & Sons';
const mockAuthorityKey = 'some authority key ?=;';
beforeEach(() => { beforeEach(() => {
requestService = getMockRequestService(getRequestEntry$(true)); requestService = getMockRequestService(getRequestEntry$(true));
@@ -155,7 +156,7 @@ describe('BrowseService', () => {
it('should call hrefOnlyDataService.findAllByHref with the expected href', () => { it('should call hrefOnlyDataService.findAllByHref with the expected href', () => {
const expected = browseDefinitions[1]._links.items.href + '?filterValue=' + encodeURIComponent(mockAuthorName); const expected = browseDefinitions[1]._links.items.href + '?filterValue=' + encodeURIComponent(mockAuthorName);
scheduler.schedule(() => service.getBrowseItemsFor(mockAuthorName, new BrowseEntrySearchOptions(browseDefinitions[1].id)).subscribe()); scheduler.schedule(() => service.getBrowseItemsFor(mockAuthorName, undefined, new BrowseEntrySearchOptions(browseDefinitions[1].id)).subscribe());
scheduler.flush(); scheduler.flush();
expect(getFirstUsedArgumentOfSpyMethod(hrefOnlyDataService.findAllByHref)).toBeObservable(cold('(a|)', { expect(getFirstUsedArgumentOfSpyMethod(hrefOnlyDataService.findAllByHref)).toBeObservable(cold('(a|)', {
@@ -164,6 +165,20 @@ describe('BrowseService', () => {
}); });
}); });
describe('when getBrowseItemsFor is called with a valid filter value and authority key', () => {
it('should call hrefOnlyDataService.findAllByHref with the expected href', () => {
const expected = browseDefinitions[1]._links.items.href +
'?filterValue=' + encodeURIComponent(mockAuthorName) +
'&filterAuthority=' + encodeURIComponent(mockAuthorityKey);
scheduler.schedule(() => service.getBrowseItemsFor(mockAuthorName, mockAuthorityKey, new BrowseEntrySearchOptions(browseDefinitions[1].id)).subscribe());
scheduler.flush();
expect(getFirstUsedArgumentOfSpyMethod(hrefOnlyDataService.findAllByHref)).toBeObservable(cold('(a|)', {
a: expected
}));
});
});
}); });
describe('getBrowseURLFor', () => { describe('getBrowseURLFor', () => {

View File

@@ -105,7 +105,7 @@ export class BrowseService {
* @param options Options to narrow down your search * @param options Options to narrow down your search
* @returns {Observable<RemoteData<PaginatedList<Item>>>} * @returns {Observable<RemoteData<PaginatedList<Item>>>}
*/ */
getBrowseItemsFor(filterValue: string, options: BrowseEntrySearchOptions): Observable<RemoteData<PaginatedList<Item>>> { getBrowseItemsFor(filterValue: string, filterAuthority: string, options: BrowseEntrySearchOptions): Observable<RemoteData<PaginatedList<Item>>> {
const href$ = this.getBrowseDefinitions().pipe( const href$ = this.getBrowseDefinitions().pipe(
getBrowseDefinitionLinks(options.metadataDefinition), getBrowseDefinitionLinks(options.metadataDefinition),
hasValueOperator(), hasValueOperator(),
@@ -132,6 +132,9 @@ export class BrowseService {
if (isNotEmpty(filterValue)) { if (isNotEmpty(filterValue)) {
args.push(`filterValue=${encodeURIComponent(filterValue)}`); args.push(`filterValue=${encodeURIComponent(filterValue)}`);
} }
if (isNotEmpty(filterAuthority)) {
args.push(`filterAuthority=${encodeURIComponent(filterAuthority)}`);
}
if (isNotEmpty(args)) { if (isNotEmpty(args)) {
href = new URLCombiner(href, `?${args.join('&')}`).toString(); href = new URLCombiner(href, `?${args.join('&')}`).toString();
} }

View File

@@ -1,5 +1,5 @@
<div class="d-flex flex-row"> <div class="d-flex flex-row">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="" [queryParams]="{value: object.value, startsWith: undefined}" [queryParamsHandling]="'merge'" class="lead"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="" [queryParams]="getQueryParams()" [queryParamsHandling]="'merge'" class="lead">
{{object.value}} {{object.value}}
</a> </a>
<span *ngIf="linkType == linkTypes.None" class="lead"> <span *ngIf="linkType == linkTypes.None" class="lead">

View File

@@ -15,4 +15,16 @@ import { listableObjectComponent } from '../../object-collection/shared/listable
* This component is automatically used to create a list view for BrowseEntry objects when used in ObjectCollectionComponent * This component is automatically used to create a list view for BrowseEntry objects when used in ObjectCollectionComponent
*/ */
@listableObjectComponent(BrowseEntry, ViewMode.ListElement) @listableObjectComponent(BrowseEntry, ViewMode.ListElement)
export class BrowseEntryListElementComponent extends AbstractListableElementComponent<BrowseEntry> {} export class BrowseEntryListElementComponent extends AbstractListableElementComponent<BrowseEntry> {
/**
* Get the query params to access the item page of this browse entry.
*/
public getQueryParams(): {[param: string]: any} {
return {
value: this.object.value,
authority: !!this.object.authority ? this.object.authority : undefined,
startsWith: undefined,
};
}
}