solve fixedfilter issue

This commit is contained in:
lotte
2019-07-22 16:11:42 +02:00
parent a8d9d74818
commit 1530d7f3d1
19 changed files with 84 additions and 49 deletions

View File

@@ -10,6 +10,7 @@ import { Observable } from 'rxjs';
import { PaginatedSearchOptions } from '../shared/search/paginated-search-options.model';
import { SEARCH_CONFIG_SERVICE } from '../+my-dspace-page/my-dspace-page.component';
import { map } from 'rxjs/operators';
import { Router } from '@angular/router';
/**
* This component renders a simple item page.
@@ -41,8 +42,9 @@ export class FilteredSearchPageComponent extends SearchPageComponent implements
protected sidebarService: SearchSidebarService,
protected windowService: HostWindowService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
protected routeService: RouteService) {
super(service, sidebarService, windowService, searchConfigService, routeService);
protected routeService: RouteService,
protected router: Router) {
super(service, sidebarService, windowService, searchConfigService, routeService, router);
}
/**
@@ -66,7 +68,8 @@ export class FilteredSearchPageComponent extends SearchPageComponent implements
return this.searchConfigService.paginatedSearchOptions.pipe(
map((options: PaginatedSearchOptions) => {
const filter = this.fixedFilterQuery || options.fixedFilter;
return Object.assign(options, { fixedFilter: filter });
return this.routeService.addParameter({ fixedFilter: filter });
})
);
}

View File

@@ -15,6 +15,8 @@ import { SearchConfigurationService } from '../core/shared/search/search-configu
import { getSucceededRemoteData } from '../core/shared/operators';
import { RouteService } from '../shared/services/route.service';
import { SEARCH_CONFIG_SERVICE } from '../+my-dspace-page/my-dspace-page.component';
import { currentPath } from '../shared/utils/route.utils';
import { Router } from '@angular/router';
export const SEARCH_ROUTE = '/search';
@@ -95,7 +97,8 @@ export class SearchPageComponent implements OnInit {
protected sidebarService: SearchSidebarService,
protected windowService: HostWindowService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
protected routeService: RouteService) {
protected routeService: RouteService,
protected router: Router) {
this.isXsOrSm$ = this.windowService.isXsOrSm();
}
@@ -156,7 +159,7 @@ export class SearchPageComponent implements OnInit {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.service.getSearchLink();
}

View File

@@ -204,7 +204,8 @@ export class SearchConfigurationService implements OnDestroy {
*/
getCurrentFixedFilter(): Observable<string> {
return this.routeService.getRouteParameterValue('filter').pipe(
switchMap((f) => this.fixedFilterService.getQueryByFilterName(f))
switchMap((f) => this.fixedFilterService.getQueryByFilterName(f)),
tap((t) => console.log(t))
);
}

View File

@@ -19,7 +19,8 @@
<button class="btn btn-outline-secondary" type="submit">Go</button>
</div>
</form>
<ds-search-results [searchResults]="resultsRD" [sortConfig]="this.searchConfig.sort"
<ds-search-results [searchResults]="resultsRD"
[sortConfig]="this.searchConfig?.sort"
[searchConfig]="this.searchConfig"
[selectable]="true"
[selectionConfig]="{ repeatable: repeatable, listId: listId }">

View File

@@ -9,7 +9,7 @@ import { DSpaceObject } from '../../../../../../core/shared/dspace-object.model'
import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { hasValue } from '../../../../../empty.util';
import { concat, map, multicast, take, takeWhile } from 'rxjs/operators';
import { concat, map, multicast, switchMap, take, takeWhile } from 'rxjs/operators';
import { Router } from '@angular/router';
import { SEARCH_CONFIG_SERVICE } from '../../../../../../+my-dspace-page/my-dspace-page.component';
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
@@ -44,43 +44,43 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
pageSize: 10
});
selection: Observable<ListableObject[]>;
constructor(public modal: NgbActiveModal, private searchService: SearchService, private router: Router, private selectableListService: SelectableListService) {
fixedFilter: string;
constructor(public modal: NgbActiveModal, private searchService: SearchService, private router: Router, private selectableListService: SelectableListService, private searchConfigService: SearchConfigurationService) {
}
ngOnInit(): void {
this.resetRoute();
this.onPaginationChange(this.initialPagination);
this.fixedFilter = RELATION_TYPE_FILTER_PREFIX + this.fieldName;
this.selection = this.selectableListService.getSelectableList(this.listId).pipe(map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []));
this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe(
map((options) => {
return Object.assign(new PaginatedSearchOptions({}), options, { fixedFilter: RELATION_TYPE_FILTER_PREFIX + this.fieldName })
}),
switchMap((options) => {
this.searchConfig = options;
return this.searchService.search(options).pipe(
/* Make sure to only listen to the first x results, until loading is finished */
/* TODO: in Rxjs 6.4.0 and up, we can replace this by takeWhile(predicate, true) - see https://stackoverflow.com/a/44644237 */
multicast(
() => new ReplaySubject(1),
subject => subject.pipe(
takeWhile((rd: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) => rd.isLoading),
concat(subject.pipe(take(1))
)
)
) as any
)
})
)
}
search(query: string) {
this.searchQuery = query;
this.resetRoute();
this.onPaginationChange(this.initialPagination);
this.selectableListService.deselectAll(this.listId);
}
onPaginationChange(pagination: PaginationComponentOptions) {
this.searchConfig = new PaginatedSearchOptions({
query: this.searchQuery,
pagination: pagination,
fixedFilter: RELATION_TYPE_FILTER_PREFIX + this.fieldName
});
this.resultsRD$ = this.searchService.search(this.searchConfig).pipe(
/* Make sure to only listen to the first x results, until loading is finished */
/* TODO: in Rxjs 6.4.0 and up, we can replace this by takeWhile(predicate, true) - see https://stackoverflow.com/a/44644237 */
multicast(
() => new ReplaySubject(1),
subject => subject.pipe(
takeWhile((rd: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) => rd.isLoading),
concat(subject.pipe(take(1))
)
)
) as any
)
}
close() {
this.modal.close();
}

View File

@@ -5,6 +5,7 @@ import { hasValue, isNotEmpty } from '../empty.util';
import { QueryParamsHandling } from '@angular/router/src/config';
import { MYDSPACE_ROUTE } from '../../+my-dspace-page/my-dspace-page.component';
import { SearchService } from '../../core/shared/search/search.service';
import { currentPath } from '../utils/route.utils';
/**
* This component renders a simple item page.
@@ -87,7 +88,7 @@ export class SearchFormComponent {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}

View File

@@ -1,5 +1,4 @@
<a *ngIf="isVisible | async" class="d-flex flex-row"
[routerLink]="[getSearchLink()]"
<a *ngIf="isVisible | async" class="d-flex flex-row" [routerLink]="[getSearchLink()]"
[queryParams]="addQueryParams" queryParamsHandling="merge">
<input type="checkbox" [checked]="false" class="my-1 align-self-stretch"/>
<span class="filter-value px-1">{{filterValue.value}}</span>

View File

@@ -9,6 +9,7 @@ import { SearchFilterService } from '../../../../../../core/shared/search/search
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
import { hasValue } from '../../../../../empty.util';
import { FilterType } from '../../../../filter-type.model';
import { currentPath } from '../../../../../utils/route.utils';
@Component({
selector: 'ds-search-facet-option',
@@ -85,7 +86,7 @@ export class SearchFacetOptionComponent implements OnInit, OnDestroy {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}

View File

@@ -12,6 +12,7 @@ import {
} from '../../search-range-filter/search-range-filter.component';
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
import { hasValue } from '../../../../../empty.util';
import { currentPath } from '../../../../../utils/route.utils';
const rangeDelimiter = '-';
@@ -84,7 +85,7 @@ export class SearchFacetRangeOptionComponent implements OnInit, OnDestroy {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}

View File

@@ -8,6 +8,7 @@ import { hasValue } from '../../../../../empty.util';
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
import { FacetValue } from '../../../../facet-value.model';
import { FilterType } from '../../../../filter-type.model';
import { currentPath } from '../../../../../utils/route.utils';
@Component({
selector: 'ds-search-facet-selected-option',
@@ -71,7 +72,7 @@ export class SearchFacetSelectedOptionComponent implements OnInit, OnDestroy {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}

View File

@@ -179,7 +179,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return '';
}
return this.searchService.getSearchLink();
}

View File

@@ -1,7 +1,7 @@
import { Component, Inject, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { map, switchMap, tap } from 'rxjs/operators';
import { SearchService } from '../../../core/shared/search/search.service';
import { RemoteData } from '../../../core/data/remote-data';
@@ -10,6 +10,8 @@ import { SearchConfigurationService } from '../../../core/shared/search/search-c
import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
import { getSucceededRemoteData } from '../../../core/shared/operators';
import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component';
import { currentPath } from '../../utils/route.utils';
import { Router } from '@angular/router';
@Component({
selector: 'ds-search-filters',
@@ -46,11 +48,13 @@ export class SearchFiltersComponent implements OnInit {
constructor(
private searchService: SearchService,
private filterService: SearchFilterService,
private router: Router,
@Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService) {
}
ngOnInit(): void {
console.log(this.searchConfigService);
this.filters = this.searchConfigService.searchOptions.pipe(
switchMap((options) => this.searchService.getConfig(options.scope, options.configuration).pipe(getSucceededRemoteData()))
);
@@ -66,7 +70,7 @@ export class SearchFiltersComponent implements OnInit {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}

View File

@@ -1,11 +1,13 @@
import { Component, Inject, Input } from '@angular/core';
import { SearchService } from '../../../core/shared/search/search.service';
import { Observable } from 'rxjs';
import { Params } from '@angular/router';
import { Params, Router } from '@angular/router';
import { map } from 'rxjs/operators';
import { hasValue, isNotEmpty } from '../../empty.util';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component';
import { currentPath } from '../../utils/route.utils';
import { RouteService } from '../../services/route.service';
@Component({
selector: 'ds-search-labels',
@@ -32,6 +34,7 @@ export class SearchLabelsComponent {
*/
constructor(
private searchService: SearchService,
protected router: Router,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService) {
this.appliedFilters = this.searchConfigService.getCurrentFrontendFilters();
}
@@ -60,7 +63,7 @@ export class SearchLabelsComponent {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}

View File

@@ -6,6 +6,7 @@ import { PaginatedSearchOptions } from '../paginated-search-options.model';
import { Observable } from 'rxjs';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component';
import { currentPath } from '../../utils/route.utils';
@Component({
selector: 'ds-search-settings',
@@ -84,7 +85,7 @@ export class SearchSettingsComponent implements OnInit {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.service.getSearchLink();
}

View File

@@ -9,6 +9,7 @@ import { SearchConfigurationService } from '../../../core/shared/search/search-c
import { MyDSpaceConfigurationValueType } from '../../../+my-dspace-page/my-dspace-configuration-value-type';
import { SearchConfigurationOption } from './search-configuration-option.model';
import { SearchService } from '../../../core/shared/search/search.service';
import { currentPath } from '../../utils/route.utils';
@Component({
selector: 'ds-search-switch-configuration',
@@ -87,7 +88,7 @@ export class SearchSwitchConfigurationComponent implements OnDestroy, OnInit {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}

View File

@@ -33,12 +33,14 @@ export function routeReducer(state = initialState, action: RouteActions): RouteS
return initialState
}
case RouteActionTypes.SET_PARAMETERS: {
console.log('set', action);
return setParameters(state, action as SetParametersAction, 'params');
}
case RouteActionTypes.SET_QUERY_PARAMETERS: {
return setParameters(state, action as SetQueryParametersAction, 'queryParams');
}
case RouteActionTypes.ADD_PARAMETER: {
console.log('add', action);
return addParameter(state, action as AddParameterAction, 'params');
}
case RouteActionTypes.ADD_QUERY_PARAMETER: {

View File

@@ -14,7 +14,7 @@ import { isEqual } from 'lodash';
import { AddUrlToHistoryAction } from '../history/history.actions';
import { historySelector } from '../history/selectors';
import { SetParametersAction, SetQueryParametersAction } from './route.actions';
import { AddParameterAction, SetParametersAction, SetQueryParametersAction } from './route.actions';
import { CoreState } from '../../core/core.reducers';
import { hasValue } from '../empty.util';
import { coreSelector } from '../../core/core.selectors';
@@ -117,7 +117,7 @@ export class RouteService {
}
getRouteParameterValue(paramName: string): Observable<string> {
return this.store.pipe(select(routeParameterSelector(paramName)));
return this.store.pipe(select(routeParameterSelector(paramName)), tap((t) => console.log('test', t)));
}
getRouteDataValue(datafield: string): Observable<any> {
@@ -183,4 +183,8 @@ export class RouteService {
map((history: string[]) => history[history.length - 2] || '')
);
}
public addParameter(key, value) {
this.store.dispatch(new AddParameterAction(key, value));
}
}

View File

@@ -0,0 +1,6 @@
import { Router } from '@angular/router';
export function currentPath(router: Router) {
const urlTree = router.parseUrl(router.url);
return '/' + urlTree.root.children['primary'].segments.map(it => it.path).join('/')
}

View File

@@ -5,6 +5,9 @@ import { Subscription } from 'rxjs';
import { SearchService } from '../../core/shared/search/search.service';
import { ViewMode } from '../../core/shared/view-mode.model';
import { isEmpty } from '../empty.util';
import { currentPath } from '../utils/route.utils';
import { RouteService } from '../services/route.service';
import { Router } from '@angular/router';
/**
* Component to switch between list and grid views.
@@ -26,7 +29,7 @@ export class ViewModeSwitchComponent implements OnInit, OnDestroy {
viewModeEnum = ViewMode;
private sub: Subscription;
constructor(private searchService: SearchService) {
constructor(private searchService: SearchService, private router: Router) {
}
ngOnInit(): void {
@@ -58,7 +61,7 @@ export class ViewModeSwitchComponent implements OnInit, OnDestroy {
*/
public getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
return currentPath(this.router);
}
return this.searchService.getSearchLink();
}