mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
refactor followlinks to use a single object for all params and add an isOptional param. Also add support for embedding links to search service
This commit is contained in:
@@ -41,6 +41,43 @@ import { SearchConfig } from './search-filters/search-config.model';
|
||||
import { PaginationService } from '../../pagination/pagination.service';
|
||||
import { SearchConfigurationService } from './search-configuration.service';
|
||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||
import { DataService } from '../../data/data.service';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { CoreState } from '../../core.reducers';
|
||||
import { ObjectCacheService } from '../../cache/object-cache.service';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DSOChangeAnalyzer } from '../../data/dso-change-analyzer.service';
|
||||
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
/**
|
||||
* A class that lets us delegate some methods to DataService
|
||||
*/
|
||||
class DataServiceImpl extends DataService<any> {
|
||||
protected linkPath = 'discover';
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOChangeAnalyzer<any>) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the embed options to the link for the request
|
||||
* @param href The href the params are to be added to
|
||||
* @param args params for the query string
|
||||
* @param linksToFollow links we want to embed in query string if shouldEmbed is true
|
||||
*/
|
||||
public addEmbedParams(href: string, args: string[], ...linksToFollow: FollowLinkConfig<any>[]) {
|
||||
return super.addEmbedParams(href, args, ...linksToFollow);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Service that performs all general actions that have to do with the search page
|
||||
@@ -78,6 +115,11 @@ export class SearchService implements OnDestroy {
|
||||
*/
|
||||
private sub;
|
||||
|
||||
/**
|
||||
* Instance of DataServiceImpl that lets us delegate some methods to DataService
|
||||
*/
|
||||
private searchDataService: DataServiceImpl;
|
||||
|
||||
constructor(private router: Router,
|
||||
private routeService: RouteService,
|
||||
protected requestService: RequestService,
|
||||
@@ -89,6 +131,16 @@ export class SearchService implements OnDestroy {
|
||||
private paginationService: PaginationService,
|
||||
private searchConfigurationService: SearchConfigurationService
|
||||
) {
|
||||
this.searchDataService = new DataServiceImpl(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +183,17 @@ export class SearchService implements OnDestroy {
|
||||
search<T extends DSpaceObject>(searchOptions?: PaginatedSearchOptions, responseMsToLive?: number, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<SearchObjects<T>>> {
|
||||
const href$ = this.getEndpoint(searchOptions);
|
||||
|
||||
href$.pipe(take(1)).subscribe((url: string) => {
|
||||
href$.pipe(
|
||||
take(1),
|
||||
map((href: string) => {
|
||||
const args = this.searchDataService.addEmbedParams(href, [], ...linksToFollow);
|
||||
if (isNotEmpty(args)) {
|
||||
return new URLCombiner(href, `?${args.join('&')}`).toString();
|
||||
} else {
|
||||
return href;
|
||||
}
|
||||
})
|
||||
).subscribe((url: string) => {
|
||||
const request = new this.request(this.requestService.generateRequestId(), url);
|
||||
|
||||
const getResponseParserFn: () => GenericConstructor<ResponseParsingService> = () => {
|
||||
@@ -152,7 +214,7 @@ export class SearchService implements OnDestroy {
|
||||
);
|
||||
|
||||
return this.directlyAttachIndexableObjects(sqr$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve request entries for search results from the server
|
||||
@@ -399,9 +461,9 @@ export class SearchService implements OnDestroy {
|
||||
let pageParams = { page: 1 };
|
||||
const queryParams = { view: viewMode };
|
||||
if (viewMode === ViewMode.DetailedListElement) {
|
||||
pageParams = Object.assign(pageParams, {pageSize: 1});
|
||||
pageParams = Object.assign(pageParams, { pageSize: 1 });
|
||||
} else if (config.pageSize === 1) {
|
||||
pageParams = Object.assign(pageParams, {pageSize: 10});
|
||||
pageParams = Object.assign(pageParams, { pageSize: 10 });
|
||||
}
|
||||
this.paginationService.updateRouteWithUrl(this.searchConfigurationService.paginationID, hasValue(searchLinkParts) ? searchLinkParts : [this.getSearchLink()], pageParams, queryParams);
|
||||
});
|
||||
@@ -413,7 +475,7 @@ export class SearchService implements OnDestroy {
|
||||
* @param {string} configurationName the name of the configuration
|
||||
* @returns {Observable<RemoteData<SearchConfig[]>>} The found configuration
|
||||
*/
|
||||
getSearchConfigurationFor(scope?: string, configurationName?: string ): Observable<RemoteData<SearchConfig>> {
|
||||
getSearchConfigurationFor(scope?: string, configurationName?: string): Observable<RemoteData<SearchConfig>> {
|
||||
const href$ = this.halService.getEndpoint(this.configurationLinkPath).pipe(
|
||||
map((url: string) => this.getConfigUrl(url, scope, configurationName)),
|
||||
);
|
||||
|
Reference in New Issue
Block a user