diff --git a/src/app/core/shared/search/search-configuration.service.ts b/src/app/core/shared/search/search-configuration.service.ts index 81df63f6b3..4e911b913e 100644 --- a/src/app/core/shared/search/search-configuration.service.ts +++ b/src/app/core/shared/search/search-configuration.service.ts @@ -23,6 +23,7 @@ import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.u import { SearchConfig, SortConfig } from './search-filters/search-config.model'; import { SearchService } from './search.service'; import { PaginationService } from '../../pagination/pagination.service'; +import { ViewMode } from '../view-mode.model'; /** * Service that performs all actions that have to do with the current search configuration @@ -196,6 +197,15 @@ export class SearchConfigurationService implements OnDestroy { return this.routeService.getQueryParamsWithPrefix('f.'); } + /** + * @returns {Observable} Emits the current view mode + */ + getCurrentViewMode(defaultViewMode: ViewMode) { + return this.routeService.getQueryParameterValue('view').pipe(map((viewMode) => { + return viewMode || defaultViewMode; + })); + } + /** * Creates an observable of SearchConfig every time the configuration stream emits. * @param configuration The search configuration @@ -285,7 +295,8 @@ export class SearchConfigurationService implements OnDestroy { this.getQueryPart(defaults.query), this.getDSOTypePart(), this.getFiltersPart(), - this.getFixedFilterPart() + this.getFixedFilterPart(), + this.getViewModePart(defaults.view) ).subscribe((update) => { const currentValue: SearchOptions = this.searchOptions.getValue(); const updatedValue: SearchOptions = Object.assign(new PaginatedSearchOptions({}), currentValue, update); @@ -308,7 +319,8 @@ export class SearchConfigurationService implements OnDestroy { this.getQueryPart(defaults.query), this.getDSOTypePart(), this.getFiltersPart(), - this.getFixedFilterPart() + this.getFixedFilterPart(), + this.getViewModePart(defaults.view) ).subscribe((update) => { const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue(); const updatedValue: PaginatedSearchOptions = Object.assign(new PaginatedSearchOptions({}), currentValue, update); @@ -403,4 +415,13 @@ export class SearchConfigurationService implements OnDestroy { }), ); } + + /** + * @returns {Observable} Emits the current view mode as a partial SearchOptions object + */ + private getViewModePart(defaultViewMode: ViewMode): Observable { + return this.getCurrentViewMode(defaultViewMode).pipe(map((view) => { + return { view }; + })); + } } diff --git a/src/app/shared/search/models/paginated-search-options.model.ts b/src/app/shared/search/models/paginated-search-options.model.ts index 925a7a3a7e..76ed6cdaa8 100644 --- a/src/app/shared/search/models/paginated-search-options.model.ts +++ b/src/app/shared/search/models/paginated-search-options.model.ts @@ -4,6 +4,7 @@ import { isNotEmpty } from '../../empty.util'; import { SearchOptions } from './search-options.model'; import { SearchFilter } from './search-filter.model'; import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model'; +import { ViewMode } from '../../../core/shared/view-mode.model'; /** * This model class represents all parameters needed to request information about a certain page of a search request, in a certain order @@ -12,10 +13,11 @@ export class PaginatedSearchOptions extends SearchOptions { pagination?: PaginationComponentOptions; sort?: SortOptions; - constructor(options: {configuration?: string, scope?: string, query?: string, dsoTypes?: DSpaceObjectType[], filters?: SearchFilter[], fixedFilter?: any, pagination?: PaginationComponentOptions, sort?: SortOptions}) { + constructor(options: {configuration?: string, scope?: string, query?: string, dsoTypes?: DSpaceObjectType[], filters?: SearchFilter[], fixedFilter?: any, pagination?: PaginationComponentOptions, sort?: SortOptions, view?: ViewMode}) { super(options); this.pagination = options.pagination; this.sort = options.sort; + this.view = options.view; } /**