Merge remote-tracking branch 'alex/fix-scope-issues-on-search-form_contribute-7.6' into added-recently-added-section-to-community-page_contribute-7.6

This commit is contained in:
Alexandre Vryghem
2024-02-15 19:57:31 +01:00
17 changed files with 118 additions and 95 deletions

View File

@@ -27,6 +27,7 @@ const filterStateSelector = (state: SearchFiltersState) => state.searchFilter;
export const FILTER_CONFIG: InjectionToken<SearchFilterConfig> = new InjectionToken<SearchFilterConfig>('filterConfig'); export const FILTER_CONFIG: InjectionToken<SearchFilterConfig> = new InjectionToken<SearchFilterConfig>('filterConfig');
export const IN_PLACE_SEARCH: InjectionToken<boolean> = new InjectionToken<boolean>('inPlaceSearch'); export const IN_PLACE_SEARCH: InjectionToken<boolean> = new InjectionToken<boolean>('inPlaceSearch');
export const REFRESH_FILTER: InjectionToken<BehaviorSubject<any>> = new InjectionToken<boolean>('refreshFilters'); export const REFRESH_FILTER: InjectionToken<BehaviorSubject<any>> = new InjectionToken<boolean>('refreshFilters');
export const SCOPE: InjectionToken<string> = new InjectionToken<string>('scope');
/** /**
* Service that performs all actions that have to do with search filters and facets * Service that performs all actions that have to do with search filters and facets

View File

@@ -4,6 +4,7 @@ import { FilterType } from '../../../models/filter-type.model';
import { SearchFilterConfig } from '../../../models/search-filter-config.model'; import { SearchFilterConfig } from '../../../models/search-filter-config.model';
import { import {
FILTER_CONFIG, FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH, IN_PLACE_SEARCH,
REFRESH_FILTER REFRESH_FILTER
} from '../../../../../core/shared/search/search-filter.service'; } from '../../../../../core/shared/search/search-filter.service';
@@ -35,6 +36,11 @@ export class SearchFacetFilterWrapperComponent implements OnInit {
*/ */
@Input() refreshFilters: BehaviorSubject<boolean>; @Input() refreshFilters: BehaviorSubject<boolean>;
/**
* The current scope
*/
@Input() scope: string;
/** /**
* The constructor of the search facet filter that should be rendered, based on the filter config's type * The constructor of the search facet filter that should be rendered, based on the filter config's type
*/ */
@@ -56,7 +62,8 @@ export class SearchFacetFilterWrapperComponent implements OnInit {
providers: [ providers: [
{ provide: FILTER_CONFIG, useFactory: () => (this.filterConfig), deps: [] }, { provide: FILTER_CONFIG, useFactory: () => (this.filterConfig), deps: [] },
{ provide: IN_PLACE_SEARCH, useFactory: () => (this.inPlaceSearch), deps: [] }, { provide: IN_PLACE_SEARCH, useFactory: () => (this.inPlaceSearch), deps: [] },
{ provide: REFRESH_FILTER, useFactory: () => (this.refreshFilters), deps: [] } { provide: REFRESH_FILTER, useFactory: () => (this.refreshFilters), deps: [] },
{ provide: SCOPE, useFactory: () => (this.scope), deps: [] },
], ],
parent: this.injector parent: this.injector
}); });

View File

@@ -4,6 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { import {
FILTER_CONFIG, FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH, IN_PLACE_SEARCH,
REFRESH_FILTER, REFRESH_FILTER,
SearchFilterService SearchFilterService
@@ -99,6 +100,7 @@ describe('SearchFacetFilterComponent', () => {
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }, { provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: IN_PLACE_SEARCH, useValue: false }, { provide: IN_PLACE_SEARCH, useValue: false },
{ provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false) }, { provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false) },
{ provide: SCOPE, useValue: undefined },
{ {
provide: SearchFilterService, useValue: { provide: SearchFilterService, useValue: {
getSelectedValuesForFilter: () => observableOf(selectedValues), getSelectedValuesForFilter: () => observableOf(selectedValues),

View File

@@ -22,6 +22,7 @@ import { SearchFilterConfig } from '../../../models/search-filter-config.model';
import { SearchService } from '../../../../../core/shared/search/search.service'; import { SearchService } from '../../../../../core/shared/search/search.service';
import { import {
FILTER_CONFIG, FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH, IN_PLACE_SEARCH,
REFRESH_FILTER, REFRESH_FILTER,
SearchFilterService SearchFilterService
@@ -104,7 +105,9 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService, @Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
@Inject(IN_PLACE_SEARCH) public inPlaceSearch: boolean, @Inject(IN_PLACE_SEARCH) public inPlaceSearch: boolean,
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig, @Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>) { @Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>,
@Inject(SCOPE) public scope: string,
) {
} }
/** /**
@@ -114,8 +117,11 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
this.currentUrl = this.router.url; this.currentUrl = this.router.url;
this.filterValues$ = new BehaviorSubject(createPendingRemoteDataObject()); this.filterValues$ = new BehaviorSubject(createPendingRemoteDataObject());
this.currentPage = this.getCurrentPage().pipe(distinctUntilChanged()); this.currentPage = this.getCurrentPage().pipe(distinctUntilChanged());
this.searchOptions$ = this.searchConfigService.searchOptions.pipe(
this.searchOptions$ = this.searchConfigService.searchOptions; map((options: SearchOptions) => hasNoValue(this.scope) ? options : Object.assign({}, options, {
scope: this.scope,
})),
);
this.subs.push( this.subs.push(
this.searchOptions$.subscribe(() => this.updateFilterValueList()), this.searchOptions$.subscribe(() => this.updateFilterValueList()),
this.refreshFilters.asObservable().pipe( this.refreshFilters.asObservable().pipe(

View File

@@ -18,6 +18,7 @@
(@slide.start)="startSlide($event)" (@slide.done)="finishSlide($event)" (@slide.start)="startSlide($event)" (@slide.done)="finishSlide($event)"
class="search-filter-wrapper" [ngClass]="{ 'closed' : closed, 'notab': notab }"> class="search-filter-wrapper" [ngClass]="{ 'closed' : closed, 'notab': notab }">
<ds-search-facet-filter-wrapper <ds-search-facet-filter-wrapper
[scope]="scope"
[filterConfig]="filter" [filterConfig]="filter"
[inPlaceSearch]="inPlaceSearch" [inPlaceSearch]="inPlaceSearch"
[refreshFilters]="refreshFilters" > [refreshFilters]="refreshFilters" >

View File

@@ -6,7 +6,7 @@ import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
import { SearchFilterConfig } from '../../models/search-filter-config.model'; import { SearchFilterConfig } from '../../models/search-filter-config.model';
import { SearchFilterService } from '../../../../core/shared/search/search-filter.service'; import { SearchFilterService } from '../../../../core/shared/search/search-filter.service';
import { slide } from '../../../animations/slide'; import { slide } from '../../../animations/slide';
import { isNotEmpty } from '../../../empty.util'; import { isNotEmpty, hasValue } from '../../../empty.util';
import { SearchService } from '../../../../core/shared/search/search.service'; import { SearchService } from '../../../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../../my-dspace-page/my-dspace-page.component'; import { SEARCH_CONFIG_SERVICE } from '../../../../my-dspace-page/my-dspace-page.component';
@@ -38,6 +38,11 @@ export class SearchFilterComponent implements OnInit {
*/ */
@Input() refreshFilters: BehaviorSubject<boolean>; @Input() refreshFilters: BehaviorSubject<boolean>;
/**
* The current scope
*/
@Input() scope: string;
/** /**
* True when the filter is 100% collapsed in the UI * True when the filter is 100% collapsed in the UI
*/ */
@@ -171,6 +176,9 @@ export class SearchFilterComponent implements OnInit {
} else { } else {
return this.searchConfigService.searchOptions.pipe( return this.searchConfigService.searchOptions.pipe(
switchMap((options) => { switchMap((options) => {
if (hasValue(this.scope)) {
options.scope = this.scope;
}
return this.searchService.getFacetValuesFor(this.filter, 1, options).pipe( return this.searchService.getFacetValuesFor(this.filter, 1, options).pipe(
filter((RD) => !RD.isLoading), filter((RD) => !RD.isLoading),
map((valuesRD) => { map((valuesRD) => {

View File

@@ -14,6 +14,7 @@ import { CommonModule } from '@angular/common';
import { SearchService } from '../../../../../core/shared/search/search.service'; import { SearchService } from '../../../../../core/shared/search/search.service';
import { import {
FILTER_CONFIG, FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH, IN_PLACE_SEARCH,
SearchFilterService, SearchFilterService,
REFRESH_FILTER REFRESH_FILTER
@@ -75,7 +76,8 @@ describe('SearchHierarchyFilterComponent', () => {
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }, { provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: IN_PLACE_SEARCH, useValue: false }, { provide: IN_PLACE_SEARCH, useValue: false },
{ provide: FILTER_CONFIG, useValue: Object.assign(new SearchFilterConfig(), { name: testSearchFilter }) }, { provide: FILTER_CONFIG, useValue: Object.assign(new SearchFilterConfig(), { name: testSearchFilter }) },
{ provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false)} { provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false)},
{ provide: SCOPE, useValue: undefined },
], ],
schemas: [NO_ERRORS_SCHEMA], schemas: [NO_ERRORS_SCHEMA],
}).compileComponents(); }).compileComponents();

View File

@@ -9,6 +9,7 @@ import {
import { SearchService } from '../../../../../core/shared/search/search.service'; import { SearchService } from '../../../../../core/shared/search/search.service';
import { import {
FILTER_CONFIG, FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH, IN_PLACE_SEARCH,
SearchFilterService, REFRESH_FILTER SearchFilterService, REFRESH_FILTER
} from '../../../../../core/shared/search/search-filter.service'; } from '../../../../../core/shared/search/search-filter.service';
@@ -49,9 +50,10 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService, @Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
@Inject(IN_PLACE_SEARCH) public inPlaceSearch: boolean, @Inject(IN_PLACE_SEARCH) public inPlaceSearch: boolean,
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig, @Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean> @Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>,
@Inject(SCOPE) public scope: string,
) { ) {
super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters); super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters, scope);
} }
vocabularyExists$: Observable<boolean>; vocabularyExists$: Observable<boolean>;

View File

@@ -4,6 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { import {
FILTER_CONFIG, FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH, IN_PLACE_SEARCH,
REFRESH_FILTER, REFRESH_FILTER,
SearchFilterService SearchFilterService
@@ -105,6 +106,7 @@ describe('SearchRangeFilterComponent', () => {
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }, { provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: IN_PLACE_SEARCH, useValue: false }, { provide: IN_PLACE_SEARCH, useValue: false },
{ provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false) }, { provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false) },
{ provide: SCOPE, useValue: undefined },
{ {
provide: SearchFilterService, useValue: { provide: SearchFilterService, useValue: {
getSelectedValuesForFilter: () => selectedValues, getSelectedValuesForFilter: () => selectedValues,

View File

@@ -9,6 +9,7 @@ import { facetLoad, SearchFacetFilterComponent } from '../search-facet-filter/se
import { SearchFilterConfig } from '../../../models/search-filter-config.model'; import { SearchFilterConfig } from '../../../models/search-filter-config.model';
import { import {
FILTER_CONFIG, FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH, IN_PLACE_SEARCH,
REFRESH_FILTER, REFRESH_FILTER,
SearchFilterService SearchFilterService
@@ -83,8 +84,9 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig, @Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
@Inject(PLATFORM_ID) private platformId: any, @Inject(PLATFORM_ID) private platformId: any,
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>, @Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>,
@Inject(SCOPE) public scope: string,
private route: RouteService) { private route: RouteService) {
super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters); super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters, scope);
} }

View File

@@ -1,7 +1,7 @@
<h3>{{"search.filters.head" | translate}}</h3> <h3>{{"search.filters.head" | translate}}</h3>
<div *ngIf="(filters | async)?.hasSucceeded"> <div *ngIf="(filters | async)?.hasSucceeded">
<div *ngFor="let filter of (filters | async)?.payload; trackBy: trackUpdate"> <div *ngFor="let filter of (filters | async)?.payload; trackBy: trackUpdate">
<ds-search-filter [filter]="filter" [inPlaceSearch]="inPlaceSearch" [refreshFilters]="refreshFilters"></ds-search-filter> <ds-search-filter [scope]="currentScope" [filter]="filter" [inPlaceSearch]="inPlaceSearch" [refreshFilters]="refreshFilters"></ds-search-filter>
</div> </div>
</div> </div>
<a class="btn btn-primary" [routerLink]="[searchLink]" [queryParams]="clearParams | async" queryParamsHandling="merge" role="button"><i class="fas fa-undo"></i> {{"search.filters.reset" | translate}}</a> <a class="btn btn-primary" [routerLink]="[searchLink]" [queryParams]="clearParams | async" queryParamsHandling="merge" role="button"><i class="fas fa-undo"></i> {{"search.filters.reset" | translate}}</a>

View File

@@ -1,4 +1,3 @@
import { SearchService } from '../../../core/shared/search/search.service';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { SearchSettingsComponent } from './search-settings.component'; import { SearchSettingsComponent } from './search-settings.component';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
@@ -6,15 +5,11 @@ import { PaginationComponentOptions } from '../../pagination/pagination-componen
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { ActivatedRoute } from '@angular/router';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EnumKeysPipe } from '../../utils/enum-keys-pipe'; import { EnumKeysPipe } from '../../utils/enum-keys-pipe';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
import { VarDirective } from '../../utils/var.directive'; import { VarDirective } from '../../utils/var.directive';
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component'; import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
import { SidebarService } from '../../sidebar/sidebar.service';
import { SidebarServiceStub } from '../../testing/sidebar-service.stub';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../testing/pagination-service.stub'; import { PaginationServiceStub } from '../../testing/pagination-service.stub';
@@ -22,32 +17,23 @@ describe('SearchSettingsComponent', () => {
let comp: SearchSettingsComponent; let comp: SearchSettingsComponent;
let fixture: ComponentFixture<SearchSettingsComponent>; let fixture: ComponentFixture<SearchSettingsComponent>;
let searchServiceObject: SearchService;
let pagination: PaginationComponentOptions; let pagination: PaginationComponentOptions;
let sort: SortOptions; let sort: SortOptions;
let mockResults;
let searchServiceStub;
let queryParam; let queryParam;
let scopeParam; let scopeParam;
let paginatedSearchOptions; let paginatedSearchOptions;
let paginationService; let paginationService: PaginationServiceStub;
let activatedRouteStub;
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(async () => {
pagination = new PaginationComponentOptions(); pagination = new PaginationComponentOptions();
pagination.id = 'search-results-pagination'; pagination.id = 'search-results-pagination';
pagination.currentPage = 1; pagination.currentPage = 1;
pagination.pageSize = 10; pagination.pageSize = 10;
sort = new SortOptions('score', SortDirection.DESC); sort = new SortOptions('score', SortDirection.DESC);
mockResults = ['test', 'data'];
searchServiceStub = {
searchOptions: { pagination: pagination, sort: sort },
search: () => mockResults,
};
queryParam = 'test query'; queryParam = 'test query';
scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
@@ -58,30 +44,12 @@ describe('SearchSettingsComponent', () => {
sort, sort,
}; };
activatedRouteStub = {
queryParams: observableOf({
query: queryParam,
scope: scopeParam,
}),
};
paginationService = new PaginationServiceStub(pagination, sort); paginationService = new PaginationServiceStub(pagination, sort);
TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective], declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
providers: [ providers: [
{ provide: SearchService, useValue: searchServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{
provide: SidebarService,
useValue: SidebarServiceStub,
},
{
provide: SearchFilterService,
useValue: {},
},
{ {
provide: PaginationService, provide: PaginationService,
useValue: paginationService, useValue: paginationService,
@@ -111,10 +79,7 @@ describe('SearchSettingsComponent', () => {
// SearchPageComponent test instance // SearchPageComponent test instance
fixture.detectChanges(); fixture.detectChanges();
searchServiceObject = (comp as any).service;
spyOn(comp, 'reloadOrder'); spyOn(comp, 'reloadOrder');
spyOn(searchServiceObject, 'search').and.callThrough();
}); });
it('it should show the order settings with the respective selectable options', () => { it('it should show the order settings with the respective selectable options', () => {

View File

@@ -1,7 +1,5 @@
import { Component, Inject, Input } from '@angular/core'; import { Component, Inject, Input } from '@angular/core';
import { SearchService } from '../../../core/shared/search/search.service';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { ActivatedRoute, Router } from '@angular/router';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component'; import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
@@ -26,11 +24,10 @@ export class SearchSettingsComponent {
*/ */
@Input() sortOptionsList: SortOptions[]; @Input() sortOptionsList: SortOptions[];
constructor(private service: SearchService, constructor(
private route: ActivatedRoute, protected paginationService: PaginationService,
private router: Router, @Inject(SEARCH_CONFIG_SERVICE) public searchConfigurationService: SearchConfigurationService,
private paginationService: PaginationService, ) {
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigurationService: SearchConfigurationService) {
} }
/** /**

View File

@@ -36,8 +36,6 @@ import { getCollectionPageRoute } from '../../collection-page/collection-page-ro
let comp: SearchComponent; let comp: SearchComponent;
let fixture: ComponentFixture<SearchComponent>; let fixture: ComponentFixture<SearchComponent>;
let searchServiceObject: SearchService;
let searchConfigurationServiceObject: SearchConfigurationService;
const store: Store<SearchComponent> = jasmine.createSpyObj('store', { const store: Store<SearchComponent> = jasmine.createSpyObj('store', {
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */ /* eslint-disable no-empty,@typescript-eslint/no-empty-function */
dispatch: {}, dispatch: {},
@@ -93,7 +91,6 @@ const mockDso2 = Object.assign(new Item(), {
} }
} }
}); });
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
const mockSearchResults: SearchObjects<DSpaceObject> = Object.assign(new SearchObjects(), { const mockSearchResults: SearchObjects<DSpaceObject> = Object.assign(new SearchObjects(), {
page: [mockDso, mockDso2] page: [mockDso, mockDso2]
}); });
@@ -106,23 +103,13 @@ const searchServiceStub = jasmine.createSpyObj('SearchService', {
getSearchConfigurationFor: createSuccessfulRemoteDataObject$(searchConfig), getSearchConfigurationFor: createSuccessfulRemoteDataObject$(searchConfig),
trackSearch: {}, trackSearch: {},
}) as SearchService; }) as SearchService;
const configurationParam = 'default';
const queryParam = 'test query'; const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const fixedFilter = 'fixed filter';
const defaultSearchOptions = new PaginatedSearchOptions({ pagination }); const defaultSearchOptions = new PaginatedSearchOptions({ pagination });
const paginatedSearchOptions$ = new BehaviorSubject(defaultSearchOptions); const paginatedSearchOptions$ = new BehaviorSubject(defaultSearchOptions);
const paginatedSearchOptions = new PaginatedSearchOptions({
configuration: configurationParam,
query: queryParam,
scope: scopeParam,
fixedFilter: fixedFilter,
pagination,
sort
});
const activatedRouteStub = { const activatedRouteStub = {
snapshot: { snapshot: {
queryParamMap: new Map([ queryParamMap: new Map([
@@ -155,14 +142,11 @@ const filtersConfigRD = createSuccessfulRemoteDataObject([mockFilterConfig, mock
const filtersConfigRD$ = observableOf(filtersConfigRD); const filtersConfigRD$ = observableOf(filtersConfigRD);
const routeServiceStub = { const routeServiceStub = {
getRouteParameterValue: () => {
return observableOf('');
},
getQueryParameterValue: () => { getQueryParameterValue: () => {
return observableOf(''); return observableOf(null);
}, },
getQueryParamsWithPrefix: () => { getQueryParamsWithPrefix: () => {
return observableOf(''); return observableOf(null);
}, },
setParameter: () => { setParameter: () => {
return; return;
@@ -252,16 +236,10 @@ describe('SearchComponent', () => {
comp.paginationId = paginationId; comp.paginationId = paginationId;
spyOn((comp as any), 'getSearchOptions').and.returnValue(paginatedSearchOptions$.asObservable()); spyOn((comp as any), 'getSearchOptions').and.returnValue(paginatedSearchOptions$.asObservable());
searchServiceObject = TestBed.inject(SearchService);
searchConfigurationServiceObject = TestBed.inject(SEARCH_CONFIG_SERVICE);
}); });
afterEach(() => { afterEach(() => {
comp = null; comp = null;
searchServiceObject = null;
searchConfigurationServiceObject = null;
}); });
it('should init search parameters properly and call retrieveSearchResults', fakeAsync(() => { it('should init search parameters properly and call retrieveSearchResults', fakeAsync(() => {

View File

@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core'; import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, OnInit, Output, OnDestroy } from '@angular/core';
import { NavigationStart, Router } from '@angular/router'; import { NavigationStart, Router } from '@angular/router';
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
@@ -11,7 +11,7 @@ import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { pushInOut } from '../animations/push'; import { pushInOut } from '../animations/push';
import { HostWindowService } from '../host-window.service'; import { HostWindowService } from '../host-window.service';
import { SidebarService } from '../sidebar/sidebar.service'; import { SidebarService } from '../sidebar/sidebar.service';
import { hasValue, hasValueOperator, isNotEmpty } from '../empty.util'; import { hasValue, hasValueOperator, isEmpty, isNotEmpty } from '../empty.util';
import { RouteService } from '../../core/services/route.service'; import { RouteService } from '../../core/services/route.service';
import { SEARCH_CONFIG_SERVICE } from '../../my-dspace-page/my-dspace-page.component'; import { SEARCH_CONFIG_SERVICE } from '../../my-dspace-page/my-dspace-page.component';
import { PaginatedSearchOptions } from './models/paginated-search-options.model'; import { PaginatedSearchOptions } from './models/paginated-search-options.model';
@@ -34,7 +34,7 @@ import { CollectionElementLinkType } from '../object-collection/collection-eleme
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { SubmissionObject } from '../../core/submission/models/submission-object.model'; import { SubmissionObject } from '../../core/submission/models/submission-object.model';
import { SearchFilterConfig } from './models/search-filter-config.model'; import { SearchFilterConfig } from './models/search-filter-config.model';
import { WorkspaceItem } from '../..//core/submission/models/workspaceitem.model'; import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model';
import { ITEM_MODULE_PATH } from '../../item-page/item-page-routing-paths'; import { ITEM_MODULE_PATH } from '../../item-page/item-page-routing-paths';
import { COLLECTION_MODULE_PATH } from '../../collection-page/collection-page-routing-paths'; import { COLLECTION_MODULE_PATH } from '../../collection-page/collection-page-routing-paths';
import { COMMUNITY_MODULE_PATH } from '../../community-page/community-page-routing-paths'; import { COMMUNITY_MODULE_PATH } from '../../community-page/community-page-routing-paths';
@@ -50,7 +50,7 @@ import { COMMUNITY_MODULE_PATH } from '../../community-page/community-page-routi
/** /**
* This component renders a sidebar, a search input bar and the search results. * This component renders a sidebar, a search input bar and the search results.
*/ */
export class SearchComponent implements OnInit { export class SearchComponent implements OnDestroy, OnInit {
/** /**
* The list of available configuration options * The list of available configuration options
@@ -166,6 +166,11 @@ export class SearchComponent implements OnInit {
*/ */
@Input() query: string; @Input() query: string;
/**
* The fallback scope when no scope is defined in the url, if this is also undefined no scope will be set
*/
@Input() scope: string;
/** /**
* The current configuration used during the search * The current configuration used during the search
*/ */
@@ -179,7 +184,7 @@ export class SearchComponent implements OnInit {
/** /**
* The current sort options used * The current sort options used
*/ */
currentScope$: BehaviorSubject<string> = new BehaviorSubject<string>(''); currentScope$: Observable<string>;
/** /**
* The current sort options used * The current sort options used
@@ -299,6 +304,10 @@ export class SearchComponent implements OnInit {
this.routeService.setParameter('fixedFilterQuery', this.fixedFilterQuery); this.routeService.setParameter('fixedFilterQuery', this.fixedFilterQuery);
} }
this.currentScope$ = this.routeService.getQueryParameterValue('scope').pipe(
map((routeValue: string) => hasValue(routeValue) ? routeValue : this.scope),
);
this.isSidebarCollapsed$ = this.isSidebarCollapsed(); this.isSidebarCollapsed$ = this.isSidebarCollapsed();
this.searchLink = this.getSearchLink(); this.searchLink = this.getSearchLink();
this.currentContext$.next(this.context); this.currentContext$.next(this.context);
@@ -306,9 +315,8 @@ export class SearchComponent implements OnInit {
// Determinate PaginatedSearchOptions and listen to any update on it // Determinate PaginatedSearchOptions and listen to any update on it
const configuration$: Observable<string> = this.searchConfigService const configuration$: Observable<string> = this.searchConfigService
.getCurrentConfiguration(this.configuration).pipe(distinctUntilChanged()); .getCurrentConfiguration(this.configuration).pipe(distinctUntilChanged());
const searchSortOptions$: Observable<SortOptions[]> = configuration$.pipe( const searchSortOptions$: Observable<SortOptions[]> = combineLatest([configuration$, this.currentScope$]).pipe(
switchMap((configuration: string) => this.searchConfigService switchMap(([configuration, scope]: [string, string]) => this.searchConfigService.getConfigurationSearchConfig(configuration, scope)),
.getConfigurationSearchConfig(configuration)),
map((searchConfig: SearchConfig) => this.searchConfigService.getConfigurationSortOptions(searchConfig)), map((searchConfig: SearchConfig) => this.searchConfigService.getConfigurationSortOptions(searchConfig)),
distinctUntilChanged() distinctUntilChanged()
); );
@@ -321,13 +329,13 @@ export class SearchComponent implements OnInit {
); );
const searchOptions$: Observable<PaginatedSearchOptions> = this.getSearchOptions().pipe(distinctUntilChanged()); const searchOptions$: Observable<PaginatedSearchOptions> = this.getSearchOptions().pipe(distinctUntilChanged());
this.subs.push(combineLatest([configuration$, searchSortOptions$, searchOptions$, sortOption$]).pipe( this.subs.push(combineLatest([configuration$, searchSortOptions$, searchOptions$, sortOption$, this.currentScope$]).pipe(
filter(([configuration, searchSortOptions, searchOptions, sortOption]: [string, SortOptions[], PaginatedSearchOptions, SortOptions]) => { filter(([configuration, searchSortOptions, searchOptions, sortOption, scope]: [string, SortOptions[], PaginatedSearchOptions, SortOptions, string]) => {
// filter for search options related to instanced paginated id // filter for search options related to instanced paginated id
return searchOptions.pagination.id === this.paginationId; return searchOptions.pagination.id === this.paginationId;
}), }),
debounceTime(100) debounceTime(100)
).subscribe(([configuration, searchSortOptions, searchOptions, sortOption]: [string, SortOptions[], PaginatedSearchOptions, SortOptions]) => { ).subscribe(([configuration, searchSortOptions, searchOptions, sortOption, scope]: [string, SortOptions[], PaginatedSearchOptions, SortOptions, string]) => {
// Build the PaginatedSearchOptions object // Build the PaginatedSearchOptions object
const combinedOptions = Object.assign({}, searchOptions, const combinedOptions = Object.assign({}, searchOptions,
{ {
@@ -337,6 +345,9 @@ export class SearchComponent implements OnInit {
if (combinedOptions.query === '') { if (combinedOptions.query === '') {
combinedOptions.query = this.query; combinedOptions.query = this.query;
} }
if (isEmpty(combinedOptions.scope)) {
combinedOptions.scope = scope;
}
const newSearchOptions = new PaginatedSearchOptions(combinedOptions); const newSearchOptions = new PaginatedSearchOptions(combinedOptions);
// check if search options are changed // check if search options are changed
// if so retrieve new related results otherwise skip it // if so retrieve new related results otherwise skip it
@@ -344,13 +355,12 @@ export class SearchComponent implements OnInit {
// Initialize variables // Initialize variables
this.currentConfiguration$.next(configuration); this.currentConfiguration$.next(configuration);
this.currentSortOptions$.next(newSearchOptions.sort); this.currentSortOptions$.next(newSearchOptions.sort);
this.currentScope$.next(newSearchOptions.scope);
this.sortOptionsList$.next(searchSortOptions); this.sortOptionsList$.next(searchSortOptions);
this.searchOptions$.next(newSearchOptions); this.searchOptions$.next(newSearchOptions);
this.initialized$.next(true); this.initialized$.next(true);
// retrieve results // retrieve results
this.retrieveSearchResults(newSearchOptions); this.retrieveSearchResults(newSearchOptions);
this.retrieveFilters(searchOptions); this.retrieveFilters(newSearchOptions);
} }
})); }));

View File

@@ -15,11 +15,37 @@ import { ListableObject } from '../object-collection/shared/listable-object.mode
*/ */
@Component({ @Component({
selector: 'ds-themed-search', selector: 'ds-themed-search',
styleUrls: [],
templateUrl: '../theme-support/themed.component.html', templateUrl: '../theme-support/themed.component.html',
}) })
export class ThemedSearchComponent extends ThemedComponent<SearchComponent> { export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = ['configurationList', 'context', 'configuration', 'fixedFilterQuery', 'useCachedVersionIfAvailable', 'inPlaceSearch', 'linkType', 'paginationId', 'searchEnabled', 'sideBarWidth', 'searchFormPlaceholder', 'selectable', 'selectionConfig', 'showCsvExport', 'showSidebar', 'showThumbnails', 'showViewModes', 'useUniquePageId', 'viewModeList', 'showScopeSelector', 'resultFound', 'deselectObject', 'selectObject', 'trackStatistics', 'query']; protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = [
'configurationList',
'context',
'configuration',
'fixedFilterQuery',
'useCachedVersionIfAvailable',
'inPlaceSearch',
'linkType',
'paginationId',
'searchEnabled',
'sideBarWidth',
'searchFormPlaceholder',
'selectable',
'selectionConfig',
'showCsvExport',
'showSidebar',
'showThumbnails',
'showViewModes',
'useUniquePageId',
'viewModeList',
'showScopeSelector',
'trackStatistics',
'query',
'scope',
'resultFound',
'deselectObject',
'selectObject',
];
@Input() configurationList: SearchConfigurationOption[]; @Input() configurationList: SearchConfigurationOption[];
@@ -51,7 +77,7 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
@Input() showSidebar: boolean; @Input() showSidebar: boolean;
@Input() showThumbnails; @Input() showThumbnails: boolean;
@Input() showViewModes: boolean; @Input() showViewModes: boolean;
@@ -65,6 +91,8 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
@Input() query: string; @Input() query: string;
@Input() scope: string;
@Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter(); @Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter();
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter(); @Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter();

View File

@@ -3890,6 +3890,18 @@
"sorting.lastModified.DESC": "Last modified Descending", "sorting.lastModified.DESC": "Last modified Descending",
"sorting.person.familyName.ASC": "Surname Ascending",
"sorting.person.familyName.DESC": "Surname Descending",
"sorting.person.givenName.ASC": "Name Ascending",
"sorting.person.givenName.DESC": "Name Descending",
"sorting.person.birthDate.ASC": "Birth Date Ascending",
"sorting.person.birthDate.DESC": "Birth Date Descending",
"statistics.title": "Statistics", "statistics.title": "Statistics",
"statistics.header": "Statistics for {{ scope }}", "statistics.header": "Statistics for {{ scope }}",