mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Fixed issue with retrieving request
This commit is contained in:
@@ -18,20 +18,4 @@ describe('FilteredSearchPageComponent', () => {
|
||||
searchConfigService = (comp as any).searchConfigService;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
describe('when fixedFilterQuery is defined', () => {
|
||||
const fixedFilterQuery = 'fixedFilterQuery';
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(searchConfigService, 'updateFixedFilter').and.callThrough();
|
||||
comp.fixedFilterQuery = fixedFilterQuery;
|
||||
comp.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should update the paginated search options', () => {
|
||||
expect(searchConfigService.updateFixedFilter).toHaveBeenCalledWith(fixedFilterQuery);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -2,20 +2,24 @@ import { HostWindowService } from '../shared/host-window.service';
|
||||
import { SearchService } from './search-service/search.service';
|
||||
import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
|
||||
import { SearchPageComponent } from './search-page.component';
|
||||
import { ChangeDetectionStrategy, Component, Inject, Input } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, Inject, Input, OnInit } from '@angular/core';
|
||||
import { pushInOut } from '../shared/animations/push';
|
||||
import { RouteService } from '../shared/services/route.service';
|
||||
import { SearchConfigurationService } from './search-service/search-configuration.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { PaginatedSearchOptions } from './paginated-search-options.model';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../+my-dspace-page/my-dspace-page.component';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { getSucceededRemoteData } from '../core/shared/operators';
|
||||
import { isNotEmpty } from '../shared/empty.util';
|
||||
|
||||
/**
|
||||
* This component renders a simple item page.
|
||||
* The route parameter 'id' is used to request the item it represents.
|
||||
* All fields of the item that should be displayed, are defined in its template.
|
||||
*/
|
||||
@Component({selector: 'ds-filtered-search-page',
|
||||
@Component({
|
||||
selector: 'ds-filtered-search-page',
|
||||
styleUrls: ['./search-page.component.scss'],
|
||||
templateUrl: './search-page.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
@@ -28,7 +32,7 @@ import { SEARCH_CONFIG_SERVICE } from '../+my-dspace-page/my-dspace-page.compone
|
||||
]
|
||||
})
|
||||
|
||||
export class FilteredSearchPageComponent extends SearchPageComponent {
|
||||
export class FilteredSearchPageComponent extends SearchPageComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* The actual query for the fixed filter.
|
||||
@@ -44,6 +48,18 @@ export class FilteredSearchPageComponent extends SearchPageComponent {
|
||||
super(service, sidebarService, windowService, searchConfigService, routeService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listening to changes in the paginated search options
|
||||
* If something changes, update the search results
|
||||
*
|
||||
* Listen to changes in the scope
|
||||
* If something changes, update the list of scopes for the dropdown
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current paginated search options after updating the fixed filter using the fixedFilterQuery input
|
||||
* This is to make sure the fixed filter is included in the paginated search options, as it is not part of any
|
||||
@@ -51,7 +67,11 @@ export class FilteredSearchPageComponent extends SearchPageComponent {
|
||||
* @returns {Observable<PaginatedSearchOptions>}
|
||||
*/
|
||||
protected getSearchOptions(): Observable<PaginatedSearchOptions> {
|
||||
this.searchConfigService.updateFixedFilter(this.fixedFilterQuery);
|
||||
return this.searchConfigService.paginatedSearchOptions;
|
||||
return this.searchConfigService.paginatedSearchOptions.pipe(
|
||||
map((options: PaginatedSearchOptions) => {
|
||||
const filter = this.fixedFilterQuery || options.fixedFilter;
|
||||
return Object.assign(options, { fixedFilter: filter });
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ describe('SearchFixedFilterService', () => {
|
||||
configure: () => {},
|
||||
/* tslint:enable:no-empty */
|
||||
generateRequestId: () => 'fake-id',
|
||||
getByUUID: () => observableOf(Object.assign(new RequestEntry(), {
|
||||
getByHref: () => observableOf(Object.assign(new RequestEntry(), {
|
||||
response: new FilteredDiscoveryQueryResponse(filterQuery, 200, 'OK')
|
||||
}))
|
||||
}) as RequestService;
|
||||
@@ -56,5 +56,4 @@ describe('SearchFixedFilterService', () => {
|
||||
expect(query).toContain(itemUUID);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { flatMap, map } from 'rxjs/operators';
|
||||
import { Observable , of as observableOf } from 'rxjs';
|
||||
import { flatMap, map, switchMap, tap } from 'rxjs/operators';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { HALEndpointService } from '../../../core/shared/hal-endpoint.service';
|
||||
import { GetRequest, RestRequest } from '../../../core/data/request.models';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
@@ -33,7 +33,7 @@ export class SearchFixedFilterService {
|
||||
getQueryByFilterName(filterName: string): Observable<string> {
|
||||
if (hasValue(filterName)) {
|
||||
const requestUuid = this.requestService.generateRequestId();
|
||||
this.halService.getEndpoint(this.queryByFilterPath).pipe(
|
||||
const requestObs = this.halService.getEndpoint(this.queryByFilterPath).pipe(
|
||||
map((url: string) => {
|
||||
url += ('/' + filterName);
|
||||
const request = new GetRequest(requestUuid, url);
|
||||
@@ -44,10 +44,12 @@ export class SearchFixedFilterService {
|
||||
});
|
||||
}),
|
||||
configureRequest(this.requestService)
|
||||
).subscribe();
|
||||
);
|
||||
|
||||
// get search results from response cache
|
||||
const filterQuery: Observable<string> = this.requestService.getByUUID(requestUuid).pipe(
|
||||
const requestEntryObs = requestObs.pipe(
|
||||
switchMap((request: RestRequest) => this.requestService.getByHref(request.href)),
|
||||
);
|
||||
const filterQuery = requestEntryObs.pipe(
|
||||
getResponseFromEntry(),
|
||||
map((response: FilteredDiscoveryQueryResponse) =>
|
||||
response.filterQuery
|
||||
@@ -75,5 +77,4 @@ export class SearchFixedFilterService {
|
||||
getFilterByRelation(relationType: string, itemUUID: string): string {
|
||||
return `f.${relationType}=${itemUUID}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -171,20 +171,4 @@ describe('SearchConfigurationService', () => {
|
||||
expect((service as any).routeService.getRouteParameterValue).toHaveBeenCalledWith('filter');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when updateFixedFilter is called', () => {
|
||||
const filter = 'filter';
|
||||
|
||||
beforeEach(() => {
|
||||
service.updateFixedFilter(filter);
|
||||
});
|
||||
|
||||
it('should update the paginated search options with the correct fixed filter', () => {
|
||||
expect(service.paginatedSearchOptions.getValue().fixedFilter).toEqual(filter);
|
||||
});
|
||||
|
||||
it('should update the search options with the correct fixed filter', () => {
|
||||
expect(service.searchOptions.getValue().fixedFilter).toEqual(filter);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -9,7 +9,7 @@ import {
|
||||
of as observableOf,
|
||||
Subscription
|
||||
} from 'rxjs';
|
||||
import { filter, flatMap, map, tap } from 'rxjs/operators';
|
||||
import { filter, flatMap, map, switchMap, tap } from 'rxjs/operators';
|
||||
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
||||
import { SearchOptions } from '../search-options.model';
|
||||
@@ -204,7 +204,7 @@ export class SearchConfigurationService implements OnDestroy {
|
||||
*/
|
||||
getCurrentFixedFilter(): Observable<string> {
|
||||
return this.routeService.getRouteParameterValue('filter').pipe(
|
||||
flatMap((f) => this.fixedFilterService.getQueryByFilterName(f))
|
||||
switchMap((f) => this.fixedFilterService.getQueryByFilterName(f))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -229,6 +229,7 @@ export class SearchConfigurationService implements OnDestroy {
|
||||
this.getFiltersPart(),
|
||||
this.getFixedFilterPart()
|
||||
).subscribe((update) => {
|
||||
console.log(update);
|
||||
const currentValue: SearchOptions = this.searchOptions.getValue();
|
||||
const updatedValue: SearchOptions = Object.assign(currentValue, update);
|
||||
this.searchOptions.next(updatedValue);
|
||||
@@ -356,21 +357,6 @@ export class SearchConfigurationService implements OnDestroy {
|
||||
map((fixedFilter) => {
|
||||
return { fixedFilter }
|
||||
}),
|
||||
tap(t => console.log(t))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the fixed filter in paginated and non-paginated search options with a given value
|
||||
* @param {string} fixedFilter
|
||||
*/
|
||||
public updateFixedFilter(fixedFilter: string) {
|
||||
const currentPaginatedValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue();
|
||||
const updatedPaginatedValue: PaginatedSearchOptions = Object.assign(currentPaginatedValue, { fixedFilter: fixedFilter });
|
||||
this.paginatedSearchOptions.next(updatedPaginatedValue);
|
||||
|
||||
const currentValue: SearchOptions = this.searchOptions.getValue();
|
||||
const updatedValue: SearchOptions = Object.assign(currentValue, { fixedFilter: fixedFilter });
|
||||
this.searchOptions.next(updatedValue);
|
||||
}
|
||||
}
|
||||
|
@@ -75,7 +75,6 @@ describe('ItemSearchResultListElementComponent', () => {
|
||||
|
||||
it('should show the relationship type badge', () => {
|
||||
const badge = fixture.debugElement.query(By.css('span.badge'));
|
||||
console.log(itemSearchResultListElementComponent.dso);
|
||||
expect(badge.nativeElement.textContent).toContain(type.toLowerCase());
|
||||
});
|
||||
});
|
||||
|
@@ -42,6 +42,7 @@ describe('RouteService', () => {
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
queryParams: observableOf(paramObject),
|
||||
params: observableOf(paramObject),
|
||||
queryParamMap: observableOf(convertToParamMap(paramObject))
|
||||
},
|
||||
},
|
||||
|
@@ -96,7 +96,9 @@ export class RouteService {
|
||||
}
|
||||
|
||||
getRouteParameterValue(paramName: string): Observable<string> {
|
||||
return this.store.pipe(select(routeParameterSelector(paramName)), tap((t) => console.log(paramName, t)));
|
||||
const test = this.store.pipe(select(routeParameterSelector(paramName)));
|
||||
test.subscribe((t) => {console.log('test', t)});
|
||||
return test;
|
||||
}
|
||||
|
||||
getRouteDataValue(datafield: string): Observable<any> {
|
||||
@@ -139,7 +141,6 @@ export class RouteService {
|
||||
combineLatest(this.router.events, this.getRouteParams(), this.route.queryParams)
|
||||
.pipe(filter(([event, params, queryParams]) => event instanceof NavigationEnd))
|
||||
.subscribe(([event, params, queryParams]: [NavigationEnd, Params, Params]) => {
|
||||
console.log(params);
|
||||
this.store.dispatch(new SetParametersAction(params));
|
||||
this.store.dispatch(new SetQueryParametersAction(queryParams));
|
||||
this.store.dispatch(new AddUrlToHistoryAction(event.urlAfterRedirects));
|
||||
@@ -148,7 +149,6 @@ export class RouteService {
|
||||
|
||||
private getRouteParams(): Observable<Params> {
|
||||
let active = this.route;
|
||||
console.log(active);
|
||||
while (active.firstChild) {
|
||||
active = active.firstChild;
|
||||
}
|
||||
|
Reference in New Issue
Block a user