diff --git a/src/app/+search-page/configuration-search-page.component.ts b/src/app/+search-page/configuration-search-page.component.ts index 85619e8f04..8bd5724844 100644 --- a/src/app/+search-page/configuration-search-page.component.ts +++ b/src/app/+search-page/configuration-search-page.component.ts @@ -1,15 +1,16 @@ 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, 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'; +import { SearchConfigurationService } from '../core/shared/search/search-configuration.service'; +import { SearchService } from '../core/shared/search/search.service'; +import { SearchSidebarService } from '../core/shared/search/search-sidebar.service'; +import { Router } from '@angular/router'; +import { PaginatedSearchOptions } from '../shared/search/paginated-search-options.model'; /** * This component renders a search page using a configuration as input. @@ -39,8 +40,9 @@ export class ConfigurationSearchPageComponent extends SearchPageComponent implem 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); } /** diff --git a/src/app/+search-page/filtered-search-page.component.ts b/src/app/+search-page/filtered-search-page.component.ts index 385196d23a..1eb3704f30 100644 --- a/src/app/+search-page/filtered-search-page.component.ts +++ b/src/app/+search-page/filtered-search-page.component.ts @@ -9,8 +9,9 @@ import { SearchConfigurationService } from '../core/shared/search/search-configu 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 { map, take } from 'rxjs/operators'; import { Router } from '@angular/router'; +import { hasValue, isNotEmpty, isNotEmptyOperator } from '../shared/empty.util'; /** * This component renders a simple item page. @@ -56,21 +57,8 @@ export class FilteredSearchPageComponent extends SearchPageComponent implements */ 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} - */ - protected getSearchOptions(): Observable { - return this.searchConfigService.paginatedSearchOptions.pipe( - map((options: PaginatedSearchOptions) => { - const filter = this.fixedFilterQuery || options.fixedFilter; - - return this.routeService.addParameter({ fixedFilter: filter }); - }) - ); + if (hasValue(this.fixedFilterQuery)) { + this.routeService.setParameter('filterQuery', this.fixedFilterQuery); + } } } diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index c63fa40634..70ce9b2906 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -5,6 +5,7 @@ import { SharedModule } from '../shared/shared.module'; import { SearchPageRoutingModule } from './search-page-routing.module'; import { SearchPageComponent } from './search-page.component'; import { FilteredSearchPageComponent } from './filtered-search-page.component'; +import { ConfigurationSearchPageGuard } from './configuration-search-page.guard'; const components = [ @@ -19,6 +20,7 @@ const components = [ SharedModule, CoreModule.forRoot() ], + providers: [ConfigurationSearchPageGuard], declarations: components, exports: components }) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 294df66db5..d1408d585d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -23,7 +23,6 @@ import { NativeWindowRef, NativeWindowService } from './shared/services/window.s import { isAuthenticated } from './core/auth/selectors'; import { AuthService } from './core/auth/auth.service'; import { Angulartics2GoogleAnalytics } from 'angulartics2/ga'; -import { RouteService } from './shared/services/route.service'; import variables from '../styles/_exposed_variables.scss'; import { CSSVariableService } from './shared/sass-helper/sass-helper.service'; import { MenuService } from './shared/menu/menu.service'; diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 63accb53b1..2536d654c4 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -98,7 +98,6 @@ import { ENV_CONFIG, GLOBAL_CONFIG, GlobalConfig } from '../../config'; import { SearchSidebarService } from './shared/search/search-sidebar.service'; import { SearchFilterService } from './shared/search/search-filter.service'; import { SearchFixedFilterService } from './shared/search/search-fixed-filter.service'; -import { FilteredSearchPageGuard } from '../+search-page/filtered-search-page.guard'; import { SearchConfigurationService } from './shared/search/search-configuration.service'; import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service'; @@ -203,7 +202,6 @@ const PROVIDERS = [ SearchSidebarService, SearchFilterService, SearchFixedFilterService, - FilteredSearchPageGuard, SearchFilterService, SearchConfigurationService, SelectableListService, diff --git a/src/app/core/shared/operators.ts b/src/app/core/shared/operators.ts index 66cf842f87..39e6baf46e 100644 --- a/src/app/core/shared/operators.ts +++ b/src/app/core/shared/operators.ts @@ -125,3 +125,10 @@ export const getFirstOccurrence = () => source.pipe( map((rd) => Object.assign(rd, { payload: rd.payload.page.length > 0 ? rd.payload.page[0] : undefined })) ); + + +export const obsLog = (logString?: string) => + (source: Observable): Observable => + source.pipe( + tap((t) => console.log(logString || '', t)) + ); \ No newline at end of file diff --git a/src/app/core/shared/search/search-configuration.service.ts b/src/app/core/shared/search/search-configuration.service.ts index ed5c26ac56..9ccfc5f320 100644 --- a/src/app/core/shared/search/search-configuration.service.ts +++ b/src/app/core/shared/search/search-configuration.service.ts @@ -10,17 +10,17 @@ import { Subscription } from 'rxjs'; import { filter, flatMap, map, startWith, 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 '../../../shared/search/search-options.model'; import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model'; import { RouteService } from '../../../shared/services/route.service'; import { hasNoValue, hasValue, isNotEmpty, isNotEmptyOperator } from '../../../shared/empty.util'; -import { RemoteData } from '../../core/data/remote-data'; -import { getSucceededRemoteData } from '../../core/shared/operators'; import { SearchFilter } from '../../../shared/search/search-filter.model'; -import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model'; import { SearchFixedFilterService } from './search-fixed-filter.service'; +import { SortDirection, SortOptions } from '../../cache/models/sort-options.model'; +import { RemoteData } from '../../data/remote-data'; +import { getSucceededRemoteData } from '../operators'; +import { DSpaceObjectType } from '../dspace-object-type.model'; /** * Service that performs all actions that have to do with the current search configuration @@ -95,7 +95,7 @@ export class SearchConfigurationService implements OnDestroy { protected initDefaults() { this.defaults .pipe(getSucceededRemoteData()) - .subscribe((defRD) => { + .subscribe((defRD: RemoteData) => { const defs = defRD.payload; this.paginatedSearchOptions = new BehaviorSubject(defs); this.searchOptions = new BehaviorSubject(defs); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.ts index 918d623fb1..8053d3d63b 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.ts @@ -9,13 +9,14 @@ 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, switchMap, take, takeWhile } from 'rxjs/operators'; -import { Router } from '@angular/router'; +import { concat, filter, map, multicast, switchMap, take, takeWhile } from 'rxjs/operators'; +import { NavigationEnd, 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'; import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service'; import { SelectableListState } from '../../../../../object-list/selectable-list/selectable-list.reducer'; import { ListableObject } from '../../../../../object-collection/shared/listable-object.model'; +import { RouteService } from '../../../../../services/route.service'; const RELATION_TYPE_FILTER_PREFIX = 'f.entityType='; @@ -45,12 +46,15 @@ export class DsDynamicLookupRelationModalComponent implements OnInit { }); selection: Observable; fixedFilter: string; - constructor(public modal: NgbActiveModal, private searchService: SearchService, private router: Router, private selectableListService: SelectableListService, private searchConfigService: SearchConfigurationService) { + constructor(public modal: NgbActiveModal, private searchService: SearchService, private router: Router, private selectableListService: SelectableListService, private searchConfigService: SearchConfigurationService, private routeService: RouteService) { } ngOnInit(): void { this.resetRoute(); this.fixedFilter = RELATION_TYPE_FILTER_PREFIX + this.fieldName; + + ///Throw away, this is just a hack for now + this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe((t) => this.routeService.setParameter('filterQuery', this.fixedFilter)); 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) => { diff --git a/src/app/shared/search/search-filters/search-filters.component.ts b/src/app/shared/search/search-filters/search-filters.component.ts index 46e5bace6d..0915d19ea0 100644 --- a/src/app/shared/search/search-filters/search-filters.component.ts +++ b/src/app/shared/search/search-filters/search-filters.component.ts @@ -8,7 +8,7 @@ import { RemoteData } from '../../../core/data/remote-data'; import { SearchFilterConfig } from '../search-filter-config.model'; import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; import { SearchFilterService } from '../../../core/shared/search/search-filter.service'; -import { getSucceededRemoteData } from '../../../core/shared/operators'; +import { getSucceededRemoteData, obsLog } 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'; @@ -54,9 +54,9 @@ export class SearchFiltersComponent implements OnInit { } ngOnInit(): void { - console.log(this.searchConfigService); this.filters = this.searchConfigService.searchOptions.pipe( - switchMap((options) => this.searchService.getConfig(options.scope, options.configuration).pipe(getSucceededRemoteData())) + switchMap((options) => this.searchService.getConfig(options.scope, options.configuration).pipe(getSucceededRemoteData())), + obsLog('searchoptions') ); this.clearParams = this.searchConfigService.getCurrentFrontendFilters().pipe(map((filters) => { diff --git a/src/app/shared/search/search-results/search-results.component.html b/src/app/shared/search/search-results/search-results.component.html index 6e74177106..bbf84f305c 100644 --- a/src/app/shared/search/search-results/search-results.component.html +++ b/src/app/shared/search/search-results/search-results.component.html @@ -1,4 +1,4 @@ -

{{ getTitleKey() | translate }}

+

{{ (configuration ? configuration + '.search.results.head' : 'search.results.head') | translate }}

+ actions.map((navigateAction) => { + const urlTree = this.router.parseUrl(navigateAction.payload.routerState.url); + return urlTree.root.children['primary'].segments.map(it => it.path).join('/'); + })), + filter((actions: string[]) => actions[0] !== actions[1]), map(() => new ResetRouteStateAction()) ); - constructor(private actions$: Actions) { + constructor(private actions$: Actions, private router: Router) { } diff --git a/src/app/shared/services/route.reducer.ts b/src/app/shared/services/route.reducer.ts index 5b24939d99..3a4e957ab4 100644 --- a/src/app/shared/services/route.reducer.ts +++ b/src/app/shared/services/route.reducer.ts @@ -3,7 +3,11 @@ import { AddParameterAction, AddQueryParameterAction, RouteActions, - RouteActionTypes, SetParametersAction, SetQueryParametersAction + RouteActionTypes, + SetParameterAction, + SetParametersAction, + SetQueryParameterAction, + SetQueryParametersAction } from './route.actions'; /** @@ -33,19 +37,23 @@ 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: { return addParameter(state, action as AddQueryParameterAction, 'queryParams'); } + case RouteActionTypes.SET_PARAMETER: { + return setParameter(state, action as SetParameterAction, 'params'); + } + case RouteActionTypes.SET_QUERY_PARAMETER: { + return setParameter(state, action as SetQueryParameterAction, 'queryParams'); + } default: { return state; } @@ -62,7 +70,7 @@ function addParameter(state: RouteState, action: AddParameterAction | AddQueryPa const subState = state[paramType]; const existingValues = subState[action.payload.key] || []; const newValues = [...existingValues, action.payload.value]; - const newSubstate = Object.assign(subState, { [action.payload.key]: newValues }); + const newSubstate = Object.assign({}, subState, { [action.payload.key]: newValues }); return Object.assign({}, state, { [paramType]: newSubstate }); } /** @@ -74,3 +82,15 @@ function addParameter(state: RouteState, action: AddParameterAction | AddQueryPa function setParameters(state: RouteState, action: SetParametersAction | SetQueryParametersAction, paramType: string): RouteState { return Object.assign({}, state, { [paramType]: action.payload }); } + +/** + * Set a route or query parameter in the store + * @param state The current state + * @param action The set action to perform on the current state + * @param paramType The type of parameter to set: route or query parameter + */ +function setParameter(state: RouteState, action: SetParameterAction | SetQueryParameterAction, paramType: string): RouteState { + const subState = state[paramType]; + const newSubstate = Object.assign({}, subState, action.payload); + return Object.assign({}, state, { [paramType]: newSubstate }); +} \ No newline at end of file diff --git a/src/app/shared/services/route.service.ts b/src/app/shared/services/route.service.ts index b60c8c71a3..d008216301 100644 --- a/src/app/shared/services/route.service.ts +++ b/src/app/shared/services/route.service.ts @@ -14,7 +14,12 @@ import { isEqual } from 'lodash'; import { AddUrlToHistoryAction } from '../history/history.actions'; import { historySelector } from '../history/selectors'; -import { AddParameterAction, SetParametersAction, SetQueryParametersAction } from './route.actions'; +import { + AddParameterAction, + SetParameterAction, + SetParametersAction, + SetQueryParametersAction +} from './route.actions'; import { CoreState } from '../../core/core.reducers'; import { hasValue } from '../empty.util'; import { coreSelector } from '../../core/core.selectors'; @@ -117,7 +122,7 @@ export class RouteService { } getRouteParameterValue(paramName: string): Observable { - return this.store.pipe(select(routeParameterSelector(paramName)), tap((t) => console.log('test', t))); + return this.store.pipe(select(routeParameterSelector(paramName))); } getRouteDataValue(datafield: string): Observable { @@ -157,11 +162,9 @@ export class RouteService { } public saveRouting(): void { - combineLatest(this.router.events, this.getRouteParams(), this.route.queryParams) - .pipe(filter(([event, params, queryParams]) => event instanceof NavigationEnd)) - .subscribe(([event, params, queryParams]: [NavigationEnd, Params, Params]) => { - this.store.dispatch(new SetParametersAction(params)); - this.store.dispatch(new SetQueryParametersAction(queryParams)); + this.router.events + .pipe(filter((event) => event instanceof NavigationEnd)) + .subscribe((event: NavigationEnd) => { this.store.dispatch(new AddUrlToHistoryAction(event.urlAfterRedirects)); }); } @@ -187,4 +190,19 @@ export class RouteService { public addParameter(key, value) { this.store.dispatch(new AddParameterAction(key, value)); } + + public setParameter(key, value) { + this.store.dispatch(new SetParameterAction(key, value)); + } + + + public setCurrentRouteInfo() { + combineLatest(this.getRouteParams(), this.route.queryParams) + .subscribe( + ([params, queryParams]: [Params, Params]) => { + this.store.dispatch(new SetParametersAction(params)); + this.store.dispatch(new SetQueryParametersAction(queryParams)); + } + ) + } } diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 96dfb87321..31164b691f 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -160,6 +160,7 @@ import { SearchFacetSelectedOptionComponent } from './search/search-filters/sear import { SearchFacetRangeOptionComponent } from './search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component'; import { SearchSwitchConfigurationComponent } from './search/search-switch-configuration/search-switch-configuration.component'; import { SearchAuthorityFilterComponent } from './search/search-filters/search-filter/search-authority-filter/search-authority-filter.component'; +import { ConfigurationSearchPageComponent } from '../+search-page/configuration-search-page.component'; const MODULES = [ // Do NOT include UniversalModule, HttpModule, or JsonpModule here @@ -303,6 +304,7 @@ const COMPONENTS = [ SearchFacetRangeOptionComponent, SearchSwitchConfigurationComponent, SearchAuthorityFilterComponent, + ConfigurationSearchPageComponent ]; const ENTRY_COMPONENTS = [