Merge pull request #1500 from 4Science/search-grid-bug

Fix issue with grid view mode
This commit is contained in:
Tim Donohue
2022-01-25 16:18:50 -06:00
committed by GitHub
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 { SearchConfig, SortConfig } from './search-filters/search-config.model';
import { SearchService } from './search.service'; import { SearchService } from './search.service';
import { PaginationService } from '../../pagination/pagination.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 * 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.'); 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. * Creates an observable of SearchConfig every time the configuration stream emits.
* @param configuration The search configuration * @param configuration The search configuration
@@ -285,7 +295,8 @@ export class SearchConfigurationService implements OnDestroy {
this.getQueryPart(defaults.query), this.getQueryPart(defaults.query),
this.getDSOTypePart(), this.getDSOTypePart(),
this.getFiltersPart(), this.getFiltersPart(),
this.getFixedFilterPart() this.getFixedFilterPart(),
this.getViewModePart(defaults.view)
).subscribe((update) => { ).subscribe((update) => {
const currentValue: SearchOptions = this.searchOptions.getValue(); const currentValue: SearchOptions = this.searchOptions.getValue();
const updatedValue: SearchOptions = Object.assign(new PaginatedSearchOptions({}), currentValue, update); const updatedValue: SearchOptions = Object.assign(new PaginatedSearchOptions({}), currentValue, update);
@@ -308,7 +319,8 @@ export class SearchConfigurationService implements OnDestroy {
this.getQueryPart(defaults.query), this.getQueryPart(defaults.query),
this.getDSOTypePart(), this.getDSOTypePart(),
this.getFiltersPart(), this.getFiltersPart(),
this.getFixedFilterPart() this.getFixedFilterPart(),
this.getViewModePart(defaults.view)
).subscribe((update) => { ).subscribe((update) => {
const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue(); const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue();
const updatedValue: PaginatedSearchOptions = Object.assign(new PaginatedSearchOptions({}), currentValue, update); 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 { SearchOptions } from './search-options.model';
import { SearchFilter } from './search-filter.model'; import { SearchFilter } from './search-filter.model';
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.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 * 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; pagination?: PaginationComponentOptions;
sort?: SortOptions; 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); super(options);
this.pagination = options.pagination; this.pagination = options.pagination;
this.sort = options.sort; this.sort = options.sort;
this.view = options.view;
} }
/** /**