@@ -23,6 +23,7 @@ import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.u
2323import { SearchConfig , SortConfig } from './search-filters/search-config.model' ;
2424import { SearchService } from './search.service' ;
2525import { PaginationService } from '../../pagination/pagination.service' ;
26+ import { ViewMode } from '../view-mode.model' ;
2627
2728/**
2829 * Service that performs all actions that have to do with the current search configuration
@@ -196,6 +197,15 @@ export class SearchConfigurationService implements OnDestroy {
196197 return this . routeService . getQueryParamsWithPrefix ( 'f.' ) ;
197198 }
198199
200+ /**
201+ * @returns {Observable<string> } Emits the current view mode
202+ */
203+ getCurrentViewMode ( defaultViewMode : ViewMode ) {
204+ return this . routeService . getQueryParameterValue ( 'view' ) . pipe ( map ( ( viewMode ) => {
205+ return viewMode || defaultViewMode ;
206+ } ) ) ;
207+ }
208+
199209 /**
200210 * Creates an observable of SearchConfig every time the configuration stream emits.
201211 * @param configuration The search configuration
@@ -285,7 +295,8 @@ export class SearchConfigurationService implements OnDestroy {
285295 this . getQueryPart ( defaults . query ) ,
286296 this . getDSOTypePart ( ) ,
287297 this . getFiltersPart ( ) ,
288- this . getFixedFilterPart ( )
298+ this . getFixedFilterPart ( ) ,
299+ this . getViewModePart ( defaults . view )
289300 ) . subscribe ( ( update ) => {
290301 const currentValue : SearchOptions = this . searchOptions . getValue ( ) ;
291302 const updatedValue : SearchOptions = Object . assign ( new PaginatedSearchOptions ( { } ) , currentValue , update ) ;
@@ -308,7 +319,8 @@ export class SearchConfigurationService implements OnDestroy {
308319 this . getQueryPart ( defaults . query ) ,
309320 this . getDSOTypePart ( ) ,
310321 this . getFiltersPart ( ) ,
311- this . getFixedFilterPart ( )
322+ this . getFixedFilterPart ( ) ,
323+ this . getViewModePart ( defaults . view )
312324 ) . subscribe ( ( update ) => {
313325 const currentValue : PaginatedSearchOptions = this . paginatedSearchOptions . getValue ( ) ;
314326 const updatedValue : PaginatedSearchOptions = Object . assign ( new PaginatedSearchOptions ( { } ) , currentValue , update ) ;
@@ -403,4 +415,13 @@ export class SearchConfigurationService implements OnDestroy {
403415 } ) ,
404416 ) ;
405417 }
418+
419+ /**
420+ * @returns {Observable<Params> } Emits the current view mode as a partial SearchOptions object
421+ */
422+ private getViewModePart ( defaultViewMode : ViewMode ) : Observable < any > {
423+ return this . getCurrentViewMode ( defaultViewMode ) . pipe ( map ( ( view ) => {
424+ return { view } ;
425+ } ) ) ;
426+ }
406427}
0 commit comments