Skip to content

Commit 2ceaba7

Browse files
committed
[CST-5182 Fix issue with grid view mode
1 parent 4fdd3b8 commit 2ceaba7

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/app/core/shared/search/search-configuration.service.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.u
2323
import { SearchConfig, SortConfig } from './search-filters/search-config.model';
2424
import { SearchService } from './search.service';
2525
import { 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
}

src/app/shared/search/models/paginated-search-options.model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isNotEmpty } from '../../empty.util';
44
import { SearchOptions } from './search-options.model';
55
import { SearchFilter } from './search-filter.model';
66
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
7+
import { ViewMode } from '../../../core/shared/view-mode.model';
78

89
/**
910
* 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 {
1213
pagination?: PaginationComponentOptions;
1314
sort?: SortOptions;
1415

15-
constructor(options: {configuration?: string, scope?: string, query?: string, dsoTypes?: DSpaceObjectType[], filters?: SearchFilter[], fixedFilter?: any, pagination?: PaginationComponentOptions, sort?: SortOptions}) {
16+
constructor(options: {configuration?: string, scope?: string, query?: string, dsoTypes?: DSpaceObjectType[], filters?: SearchFilter[], fixedFilter?: any, pagination?: PaginationComponentOptions, sort?: SortOptions, view?: ViewMode}) {
1617
super(options);
1718
this.pagination = options.pagination;
1819
this.sort = options.sort;
20+
this.view = options.view;
1921
}
2022

2123
/**

0 commit comments

Comments
 (0)