[CST-5182 Fix issue with grid view mode

This commit is contained in:
Giuseppe Digilio
2022-01-25 19:28:03 +01:00
parent 4fdd3b84cb
commit 2ceaba742f
2 changed files with 26 additions and 3 deletions

View File

@@ -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<string>} 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<Params>} Emits the current view mode as a partial SearchOptions object
*/
private getViewModePart(defaultViewMode: ViewMode): Observable<any> {
return this.getCurrentViewMode(defaultViewMode).pipe(map((view) => {
return { view };
}));
}
}

View File

@@ -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;
}
/**