Skip to content

Commit

Permalink
Merge 16ebaf1 into 2d07cc1
Browse files Browse the repository at this point in the history
  • Loading branch information
LotteHofstede committed May 31, 2019
2 parents 2d07cc1 + 16ebaf1 commit 8967ee0
Show file tree
Hide file tree
Showing 28 changed files with 375 additions and 118 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ cache:

bundler_args: --retry 5

before_install:
- travis_retry yarn run global

install:
- travis_retry yarn install

Expand Down
12 changes: 12 additions & 0 deletions resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,18 @@
"objectpeople": {
"placeholder": "People",
"head": "People"
},
"jobTitle": {
"placeholder": "Job Title",
"head": "Job Title"
},
"knowsLanguage": {
"placeholder": "Known language",
"head": "Known language"
},
"birthDate": {
"placeholder": "Birth Date",
"head": "Birth Date"
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/app/+search-page/filtered-search-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

});
29 changes: 22 additions & 7 deletions src/app/+search-page/filtered-search-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ 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 } from 'rxjs/operators';

/**
* 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,
Expand All @@ -28,8 +30,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.
* If empty, the query will be determined by the route parameter called 'filter'
Expand All @@ -44,15 +45,29 @@ 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
* query or route parameters
* @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 });
})
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,5 +56,4 @@ describe('SearchFixedFilterService', () => {
expect(query).toContain(itemUUID);
});
});

});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -75,5 +77,4 @@ export class SearchFixedFilterService {
getFilterByRelation(relationType: string, itemUUID: string): string {
return `f.${relationType}=${itemUUID}`;
}

}
2 changes: 1 addition & 1 deletion src/app/+search-page/search-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="search-page row">
<ds-search-sidebar *ngIf="!(isXsOrSm$ | async)" class="col-{{sideBarWidth}} sidebar-md-sticky"
id="search-sidebar"
[resultCount]="(resultsRD$ | async)?.payload.totalElements" [inPlaceSearch]="inPlaceSearch"></ds-search-sidebar>
[resultCount]="(resultsRD$ | async)?.payload?.totalElements" [inPlaceSearch]="inPlaceSearch"></ds-search-sidebar>
<div class="col-12 col-md-{{12 - sideBarWidth}}">
<ds-search-form *ngIf="searchEnabled" id="search-form"
[query]="(searchOptions$ | async)?.query"
Expand Down
7 changes: 3 additions & 4 deletions src/app/+search-page/search-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, Inject, Input, OnInit } from '@angular/core';
import { Observable , Subscription , BehaviorSubject } from 'rxjs';
import { switchMap, } from 'rxjs/operators';
import { BehaviorSubject, Observable, of as observableOf, Subscription } from 'rxjs';
import { startWith, switchMap, } from 'rxjs/operators';
import { PaginatedList } from '../core/data/paginated-list';
import { RemoteData } from '../core/data/remote-data';
import { DSpaceObject } from '../core/shared/dspace-object.model';
Expand Down Expand Up @@ -43,7 +43,6 @@ export const SEARCH_ROUTE = '/search';
* It renders search results depending on the current search options
*/
export class SearchPageComponent implements OnInit {

/**
* The current search results
*/
Expand Down Expand Up @@ -110,7 +109,7 @@ export class SearchPageComponent implements OnInit {
ngOnInit(): void {
this.searchOptions$ = this.getSearchOptions();
this.sub = this.searchOptions$.pipe(
switchMap((options) => this.service.search(options).pipe(getSucceededRemoteData())))
switchMap((options) => this.service.search(options).pipe(getSucceededRemoteData(), startWith(observableOf(undefined)))))
.subscribe((results) => {
this.resultsRD$.next(results);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h2 *ngIf="!disableHeader">{{ getTitleKey() | translate }}</h2>
[objects]="searchResults"
[hideGear]="true">
</ds-viewable-collection></div>
<ds-loading *ngIf="!searchResults || searchResults?.isLoading" message="{{'loading.search-results' | translate}}"></ds-loading>
<ds-loading *ngIf="hasNoValue(searchResults) || hasNoValue(searchResults.payload) || searchResults.isLoading" message="{{'loading.search-results' | translate}}"></ds-loading>
<ds-error *ngIf="searchResults?.hasFailed && (!searchResults?.error || searchResults?.error?.statusCode != 400)" message="{{'error.search-results' | translate}}"></ds-error>
<div *ngIf="searchResults?.payload?.page.length == 0 || searchResults?.error?.statusCode == 400">
{{ 'search.results.no-results' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SetViewMode } from '../../shared/view-mode';
import { SearchOptions } from '../search-options.model';
import { SearchResult } from '../search-result.model';
import { PaginatedList } from '../../core/data/paginated-list';
import { isNotEmpty } from '../../shared/empty.util';
import { hasNoValue, isNotEmpty } from '../../shared/empty.util';
import { SortOptions } from '../../core/cache/models/sort-options.model';

@Component({
Expand All @@ -22,6 +22,8 @@ import { SortOptions } from '../../core/cache/models/sort-options.model';
* Component that represents all results from a search
*/
export class SearchResultsComponent {
hasNoValue = hasNoValue;

/**
* The actual search result objects
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
of as observableOf,
Subscription
} from 'rxjs';
import { filter, flatMap, map } 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';
Expand Down Expand Up @@ -44,7 +44,7 @@ export class SearchConfigurationService implements OnDestroy {
/**
* Default configuration parameter setting
*/
protected defaultConfiguration = 'default';
protected defaultConfiguration;

/**
* Default scope setting
Expand Down Expand Up @@ -99,10 +99,8 @@ export class SearchConfigurationService implements OnDestroy {
const defs = defRD.payload;
this.paginatedSearchOptions = new BehaviorSubject<PaginatedSearchOptions>(defs);
this.searchOptions = new BehaviorSubject<SearchOptions>(defs);

this.subs.push(this.subscribeToSearchOptions(defs));
this.subs.push(this.subscribeToPaginatedSearchOptions(defs));

}
)
}
Expand Down Expand Up @@ -206,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))
);
}

Expand Down Expand Up @@ -357,21 +355,7 @@ export class SearchConfigurationService implements OnDestroy {
isNotEmptyOperator(),
map((fixedFilter) => {
return { fixedFilter }
})
}),
);
}

/**
* 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<script src="../search-switch-configuration/search-switch-configuration.component.ts"></script>
<ng-container *ngVar="(searchOptions$ | async) as config">
<h3>{{ 'search.sidebar.settings.title' | translate}}</h3>
<div *ngIf="config?.sort" class="setting-option result-order-settings mb-3 p-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div id="search-sidebar-content">
<ds-view-mode-switch [viewModeList]="viewModeList" class="d-none d-md-block"></ds-view-mode-switch>
<div class="sidebar-content">
<ds-search-switch-configuration *ngIf="configurationList" [configurationList]="configurationList"></ds-search-switch-configuration>
<ds-search-switch-configuration [inPlaceSearch]="inPlaceSearch" *ngIf="configurationList" [configurationList]="configurationList"></ds-search-switch-configuration>
<ds-search-filters [inPlaceSearch]="inPlaceSearch"></ds-search-filters>
<ds-search-settings [inPlaceSearch]="inPlaceSearch"></ds-search-settings>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('SearchSwitchConfigurationComponent', () => {
});

it('should navigate to the route when selecting an option', () => {
(comp as any).searchService.getSearchLink.and.returnValue(MYDSPACE_ROUTE);
spyOn((comp as any), 'getSearchLinkParts').and.returnValue([MYDSPACE_ROUTE]);
comp.selectedOption = MyDSpaceConfigurationValueType.Workflow;
const navigationExtras: NavigationExtras = {
queryParams: {configuration: MyDSpaceConfigurationValueType.Workflow},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import { SearchService } from '../search-service/search.service';
*/
export class SearchSwitchConfigurationComponent implements OnDestroy, OnInit {

/**
* True when the search component should show results on the current page
*/
@Input() inPlaceSearch;
/**
* The list of available configuration options
*/
Expand Down Expand Up @@ -56,7 +60,7 @@ export class SearchSwitchConfigurationComponent implements OnDestroy, OnInit {
queryParams: {configuration: this.selectedOption},
};

this.router.navigate([this.searchService.getSearchLink()], navigationExtras);
this.router.navigate(this.getSearchLinkParts(), navigationExtras);
}

/**
Expand All @@ -77,4 +81,24 @@ export class SearchSwitchConfigurationComponent implements OnDestroy, OnInit {
this.sub.unsubscribe();
}
}

/**
* @returns {string} The base path to the search page, or the current page when inPlaceSearch is true
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
}
return this.searchService.getSearchLink();
}

/**
* @returns {string[]} The base path to the search page, or the current page when inPlaceSearch is true, split in separate pieces
*/
public getSearchLinkParts(): string[] {
if (this.searchService) {
return [];
}
return this.getSearchLink().split('/');
}
}

0 comments on commit 8967ee0

Please sign in to comment.