diff --git a/src/app/+search-page/search-filters/search-filter/search-boolean-filter/search-boolean-filter.component.html b/src/app/+search-page/search-filters/search-filter/search-boolean-filter/search-boolean-filter.component.html
index 54640a8846..576ba1b05b 100644
--- a/src/app/+search-page/search-filters/search-filter/search-boolean-filter/search-boolean-filter.component.html
+++ b/src/app/+search-page/search-filters/search-filter/search-boolean-filter/search-boolean-filter.component.html
@@ -1,16 +1,16 @@
-
+ [queryParams]="getRemoveParams(value) | async" queryParamsHandling="merge">
{{value}}
-
+ [queryParams]="getAddParams(value.value) | async" queryParamsHandling="merge">
{{value.value}}
diff --git a/src/app/+search-page/search-filters/search-filter/search-facet-filter-wrapper/search-facet-filter-wrapper.component.ts b/src/app/+search-page/search-filters/search-filter/search-facet-filter-wrapper/search-facet-filter-wrapper.component.ts
index d1f7eeab5c..6f24725deb 100644
--- a/src/app/+search-page/search-filters/search-filter/search-facet-filter-wrapper/search-facet-filter-wrapper.component.ts
+++ b/src/app/+search-page/search-filters/search-filter/search-facet-filter-wrapper/search-facet-filter-wrapper.component.ts
@@ -2,7 +2,7 @@ import { Component, Injector, Input, OnInit } from '@angular/core';
import { renderFilterType } from '../search-filter-type-decorator';
import { FilterType } from '../../../search-service/filter-type.model';
import { SearchFilterConfig } from '../../../search-service/search-filter-config.model';
-import { FILTER_CONFIG, SELECTED_VALUES } from '../search-filter.service';
+import { FILTER_CONFIG } from '../search-filter.service';
import { Observable } from 'rxjs/Observable';
@Component({
@@ -18,14 +18,11 @@ export class SearchFacetFilterWrapperComponent implements OnInit {
}
ngOnInit(): void {
- this.selectedValues.subscribe((values) => {
- this.objectInjector = Injector.create({
- providers: [
- { provide: FILTER_CONFIG, useFactory: () => (this.filterConfig), deps: [] },
- { provide: SELECTED_VALUES, useFactory: () => (values), deps: [] }],
-
- parent: this.injector
- });
+ this.objectInjector = Injector.create({
+ providers: [
+ { provide: FILTER_CONFIG, useFactory: () => (this.filterConfig), deps: [] }
+ ],
+ parent: this.injector
});
}
diff --git a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts
index 65f748b7ab..2a73c4602c 100644
--- a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts
+++ b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts
@@ -1,17 +1,9 @@
-import {
- Component,
- ElementRef,
- Inject,
- OnDestroy,
- OnInit, QueryList,
- ViewChild,
- ViewChildren
-} from '@angular/core';
+import { Component, Inject, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { FacetValue } from '../../../search-service/facet-value.model';
import { SearchFilterConfig } from '../../../search-service/search-filter-config.model';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
-import { FILTER_CONFIG, SearchFilterService, SELECTED_VALUES } from '../search-filter.service';
+import { FILTER_CONFIG, SearchFilterService } from '../search-filter.service';
import { hasNoValue, hasValue, isNotEmpty } from '../../../../shared/empty.util';
import { RemoteData } from '../../../../core/data/remote-data';
import { PaginatedList } from '../../../../core/data/paginated-list';
@@ -20,6 +12,7 @@ import { SearchOptions } from '../../../search-options.model';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Subscription } from 'rxjs/Subscription';
import { EmphasizePipe } from '../../../../shared/utils/emphasize.pipe';
+import { tap } from 'rxjs/operators';
/**
* This component renders a simple item page.
@@ -32,7 +25,7 @@ import { EmphasizePipe } from '../../../../shared/utils/emphasize.pipe';
template: ``,
})
-export class SearchFacetFilterComponent implements OnInit, OnDestroy {
+export class SearchFacetFilterComponent implements OnInit, OnDestroy, OnChanges {
filterValues: Array>>> = [];
filterValues$: BehaviorSubject = new BehaviorSubject(this.filterValues);
currentPage: Observable;
@@ -41,27 +34,33 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
pageChange = false;
sub: Subscription;
filterSearchResults: Observable = Observable.of([]);
+ selectedValues: Observable;
constructor(protected searchService: SearchService,
protected filterService: SearchFilterService,
protected router: Router,
- @Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
- @Inject(SELECTED_VALUES) public selectedValues: string[]) {
+ @Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig) {
}
ngOnInit(): void {
this.currentPage = this.getCurrentPage();
+ this.selectedValues = this.filterService.getSelectedValuesForFilter(this.filterConfig);
this.filterService.getSearchOptions().distinctUntilChanged().subscribe((options) => this.updateFilterValueList(options));
}
updateFilterValueList(options: SearchOptions) {
this.unsubscribe();
this.showFirstPageOnly();
-
- this.sub = this.currentPage.distinctUntilChanged().map((page) => {
- return this.searchService.getFacetValuesFor(this.filterConfig, page, options);
+ let page;
+ this.sub = this.currentPage.distinctUntilChanged().map((p) => {
+ page = p;
+ return this.searchService.getFacetValuesFor(this.filterConfig, p, options).pipe(tap((rd) => {if (this.filterConfig.paramName === 'f.author') console.log(rd.isLoading, rd.hasSucceeded, rd.payload)}));
}).subscribe((newValues$) => {
- this.filterValues = [...this.filterValues, newValues$];
+ if (page > 1) {
+ this.filterValues = [...this.filterValues, newValues$];
+ } else {
+ this.filterValues = [newValues$]
+ }
this.filterValues$.next(this.filterValues);
newValues$.first().subscribe((rd) => this.isLastPage$.next(hasNoValue(rd.payload.next)));
});
@@ -81,7 +80,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
}
showFirstPageOnly() {
- this.filterValues = [];
+ // this.filterValues = [];
this.filterService.resetPage(this.filterConfig.name);
}
@@ -94,15 +93,18 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
}
onSubmit(data: any) {
- if (isNotEmpty(data)) {
- this.router.navigate([this.getSearchLink()], {
- queryParams:
- { [this.filterConfig.paramName]: [...this.selectedValues, data] },
- queryParamsHandling: 'merge'
- });
- this.filter = '';
- }
- this.filterSearchResults = Observable.of([]);
+ this.selectedValues.first().subscribe((selectedValues) => {
+ if (isNotEmpty(data)) {
+ this.router.navigate([this.getSearchLink()], {
+ queryParams:
+ { [this.filterConfig.paramName]: [...selectedValues, data] },
+ queryParamsHandling: 'merge'
+ });
+ this.filter = '';
+ }
+ this.filterSearchResults = Observable.of([]);
+ }
+ )
}
onClick(data: any) {
@@ -113,18 +115,22 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
return hasValue(o);
}
- getRemoveParams(value: string) {
- return {
- [this.filterConfig.paramName]: this.selectedValues.filter((v) => v !== value),
- page: 1
- };
+ getRemoveParams(value: string): Observable {
+ return this.selectedValues.map((selectedValues) => {
+ return {
+ [this.filterConfig.paramName]: selectedValues.filter((v) => v !== value),
+ page: 1
+ };
+ });
}
- getAddParams(value: string) {
- return {
- [this.filterConfig.paramName]: [...this.selectedValues, value],
- page: 1
- };
+ getAddParams(value: string): Observable {
+ return this.selectedValues.map((selectedValues) => {
+ return {
+ [this.filterConfig.paramName]: [...selectedValues, value],
+ page: 1
+ };
+ });
}
ngOnDestroy(): void {
@@ -161,4 +167,8 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
return new EmphasizePipe().transform(facet.value, query) + ' (' + facet.count + ')';
}
+ ngOnChanges(changes: SimpleChanges): void {
+ console.log(changes);
+ }
+
}
diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.component.html b/src/app/+search-page/search-filters/search-filter/search-filter.component.html
index 9ea1eeed14..f5dc5fff38 100644
--- a/src/app/+search-page/search-filters/search-filter/search-filter.component.html
+++ b/src/app/+search-page/search-filters/search-filter/search-filter.component.html
@@ -2,6 +2,6 @@
{{'search.filters.filter.' + filter.name + '.head'| translate}}
-
+
\ No newline at end of file
diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.service.ts b/src/app/+search-page/search-filters/search-filter/search-filter.service.ts
index ff5b3325b7..6c21c8790f 100644
--- a/src/app/+search-page/search-filters/search-filter/search-filter.service.ts
+++ b/src/app/+search-page/search-filters/search-filter/search-filter.service.ts
@@ -1,21 +1,21 @@
import { Injectable, InjectionToken } from '@angular/core';
-import { debounceTime, distinctUntilChanged, map } from 'rxjs/operators';
+import { distinctUntilChanged, map } from 'rxjs/operators';
import { SearchFiltersState, SearchFilterState } from './search-filter.reducer';
import { createSelector, MemoizedSelector, Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import {
SearchFilterCollapseAction,
- SearchFilterDecrementPageAction, SearchFilterExpandAction,
+ SearchFilterDecrementPageAction,
+ SearchFilterExpandAction,
SearchFilterIncrementPageAction,
SearchFilterInitialCollapseAction,
- SearchFilterInitialExpandAction, SearchFilterResetPageAction,
+ SearchFilterInitialExpandAction,
+ SearchFilterResetPageAction,
SearchFilterToggleAction
} from './search-filter.actions';
import { hasValue, isEmpty, isNotEmpty, } from '../../../shared/empty.util';
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
-import { SearchService } from '../../search-service/search.service';
import { RouteService } from '../../../shared/services/route.service';
-import ObjectExpression from 'rollup/dist/typings/ast/nodes/ObjectExpression';
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';
@@ -25,7 +25,6 @@ import { ActivatedRoute, Params } from '@angular/router';
const filterStateSelector = (state: SearchFiltersState) => state.searchFilter;
export const FILTER_CONFIG: InjectionToken
= new InjectionToken('filterConfig');
-export const SELECTED_VALUES: InjectionToken = new InjectionToken('selectedValues');
@Injectable()
export class SearchFilterService {
diff --git a/src/app/+search-page/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.html b/src/app/+search-page/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.html
index 1e485179d6..fab11fa8e1 100644
--- a/src/app/+search-page/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.html
+++ b/src/app/+search-page/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.html
@@ -1,16 +1,16 @@
-
+ [queryParams]="getRemoveParams(value) | async" queryParamsHandling="merge">
{{value}}
-
+ [queryParams]="getAddParams(value.value) | async" queryParamsHandling="merge" >
{{value.value}}
diff --git a/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.html b/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.html
index f13687419a..729301ed82 100644
--- a/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.html
+++ b/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.html
@@ -25,9 +25,9 @@
-
+ [queryParams]="getAddParams(value.value) | async" queryParamsHandling="merge">
{{value.value}}
{{value.count}}
diff --git a/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.ts b/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.ts
index c910b3e54f..04cc12bd29 100644
--- a/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.ts
+++ b/src/app/+search-page/search-filters/search-filter/search-range-filter/search-range-filter.component.ts
@@ -1,14 +1,14 @@
import { isPlatformBrowser } from '@angular/common';
-import { Component, Inject, OnChanges, OnInit, PLATFORM_ID } from '@angular/core';
+import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { FilterType } from '../../../search-service/filter-type.model';
import { renderFacetFor } from '../search-filter-type-decorator';
import { SearchFacetFilterComponent } from '../search-facet-filter/search-facet-filter.component';
-import { isNotEmpty } from '../../../../shared/empty.util';
import { SearchFilterConfig } from '../../../search-service/search-filter-config.model';
-import { FILTER_CONFIG, SearchFilterService, SELECTED_VALUES } from '../search-filter.service';
+import { FILTER_CONFIG, SearchFilterService } from '../search-filter.service';
import { SearchService } from '../../../search-service/search.service';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
+import { Observable } from 'rxjs/Observable';
/**
* This component renders a simple item page.
@@ -31,14 +31,14 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
min = 1950;
max = 2018;
range;
+
constructor(protected searchService: SearchService,
protected filterService: SearchFilterService,
protected router: Router,
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
- @Inject(SELECTED_VALUES) public selectedValues: string[],
@Inject(PLATFORM_ID) private platformId: any,
private route: ActivatedRoute) {
- super(searchService, filterService, router, filterConfig, selectedValues);
+ super(searchService, filterService, router, filterConfig);
}
ngOnInit(): void {
@@ -51,52 +51,41 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
}
-
-
getAddParams(value: string) {
const parts = value.split(rangeDelimiter);
const min = parts.length > 1 ? parts[0].trim() : value;
const max = parts.length > 1 ? parts[1].trim() : value;
- return {
- [this.filterConfig.paramName + minSuffix]: [min],
- [this.filterConfig.paramName + maxSuffix]: [max],
- page: 1
- };
+ return Observable.of(
+ {
+ [this.filterConfig.paramName + minSuffix]: [min],
+ [this.filterConfig.paramName + maxSuffix]: [max],
+ page: 1
+ });
}
getRemoveParams(value: string) {
- return {
- [this.filterConfig.paramName + minSuffix]: null,
- [this.filterConfig.paramName + maxSuffix]: null,
- page: 1
- };
+ return Observable.of(
+ {
+ [this.filterConfig.paramName + minSuffix]: null,
+ [this.filterConfig.paramName + maxSuffix]: null,
+ page: 1
+ }
+ );
}
- getRemoveMaxParam() {
- return {
- [this.filterConfig.paramName + maxSuffix]: null,
- page: 1
- };
- }
- getRemoveMinParam() {
- return {
- [this.filterConfig.paramName + minSuffix]: null,
- page: 1
- };
- }
onSubmit() {
- const newMin = this.range[0] !== this.min ? [this.range[0]] : null;
- const newMax = this.range[1] !== this.max ? [this.range[1]] : null;
- this.router.navigate([this.getSearchLink()], {
- queryParams:
- {
- [this.filterConfig.paramName + minSuffix]: newMin,
- [this.filterConfig.paramName + maxSuffix]: newMax
- },
- queryParamsHandling: 'merge'
- });
- this.filter = '';
+ const newMin = this.range[0] !== this.min ? [this.range[0]] : null;
+ const newMax = this.range[1] !== this.max ? [this.range[1]] : null;
+ this.router.navigate([this.getSearchLink()], {
+ queryParams:
+ {
+ [this.filterConfig.paramName + minSuffix]: newMin,
+ [this.filterConfig.paramName + maxSuffix]: newMax
+ },
+ queryParamsHandling: 'merge'
+ });
+ this.filter = '';
}
/**
diff --git a/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.html b/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.html
index 1e485179d6..fab11fa8e1 100644
--- a/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.html
+++ b/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.html
@@ -1,16 +1,16 @@