62849: fixed routing issues

This commit is contained in:
lotte
2019-07-23 16:51:06 +02:00
parent 1fd3b04a43
commit 170377f209
15 changed files with 150 additions and 52 deletions

View File

@@ -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);
}
/**

View File

@@ -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<PaginatedSearchOptions>}
*/
protected getSearchOptions(): Observable<PaginatedSearchOptions> {
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);
}
}
}

View File

@@ -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
})

View File

@@ -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';

View File

@@ -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,

View File

@@ -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) =>
<T>(source: Observable<T>): Observable<T> =>
source.pipe(
tap((t) => console.log(logString || '', t))
);

View File

@@ -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<PaginatedSearchOptions>) => {
const defs = defRD.payload;
this.paginatedSearchOptions = new BehaviorSubject<PaginatedSearchOptions>(defs);
this.searchOptions = new BehaviorSubject<SearchOptions>(defs);

View File

@@ -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<ListableObject[]>;
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) => {

View File

@@ -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) => {

View File

@@ -1,4 +1,4 @@
<h2 *ngIf="!disableHeader">{{ getTitleKey() | translate }}</h2>
<h2 *ngIf="!disableHeader">{{ (configuration ? configuration + '.search.results.head' : 'search.results.head') | translate }}</h2>
<div *ngIf="searchResults?.hasSucceeded && !searchResults?.isLoading && searchResults?.payload?.page.length > 0" @fadeIn>
<ds-viewable-collection
[config]="searchConfig.pagination"

View File

@@ -10,6 +10,8 @@ export const RouteActionTypes = {
SET_PARAMETERS: type('dspace/core/route/SET_PARAMETERS'),
ADD_QUERY_PARAMETER: type('dspace/core/route/ADD_QUERY_PARAMETER'),
ADD_PARAMETER: type('dspace/core/route/ADD_PARAMETER'),
SET_QUERY_PARAMETER: type('dspace/core/route/SET_QUERY_PARAMETER'),
SET_PARAMETER: type('dspace/core/route/SET_PARAMETER'),
RESET: type('dspace/core/route/RESET'),
};
@@ -96,6 +98,52 @@ export class AddParameterAction implements Action {
}
}
/**
* An ngrx action to set a query parameter
*/
export class SetQueryParameterAction implements Action {
type = RouteActionTypes.SET_QUERY_PARAMETER;
payload: {
key: string;
value: string;
};
/**
* Create a new SetQueryParameterAction
*
* @param key
* the key to set
* @param value
* the value of this key
*/
constructor(key: string, value: string) {
this.payload = { key, value };
}
}
/**
* An ngrx action to set a parameter
*/
export class SetParameterAction implements Action {
type = RouteActionTypes.SET_PARAMETER;
payload: {
key: string;
value: string;
};
/**
* Create a new SetParameterAction
*
* @param key
* the key to set
* @param value
* the value of this key
*/
constructor(key: string, value: string) {
this.payload = { key, value };
}
}
/**
* An ngrx action to reset the route state
*/
@@ -113,4 +161,5 @@ export type RouteActions =
| SetParametersAction
| AddQueryParameterAction
| AddParameterAction
| ResetRouteStateAction;
| ResetRouteStateAction
| SetParameterAction;

View File

@@ -1,8 +1,10 @@
import { map } from 'rxjs/operators';
import { filter, map, pairwise } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects'
import * as fromRouter from '@ngrx/router-store';
import { RouterNavigationAction } from '@ngrx/router-store';
import { ResetRouteStateAction } from './route.actions';
import { Router } from '@angular/router';
@Injectable()
export class RouteEffects {
@@ -13,10 +15,17 @@ export class RouteEffects {
@Effect() routeChange$ = this.actions$
.pipe(
ofType(fromRouter.ROUTER_NAVIGATION),
pairwise(),
map((actions: RouterNavigationAction[]) =>
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) {
}

View File

@@ -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 });
}

View File

@@ -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<string> {
return this.store.pipe(select(routeParameterSelector(paramName)), tap((t) => console.log('test', t)));
return this.store.pipe(select(routeParameterSelector(paramName)));
}
getRouteDataValue(datafield: string): Observable<any> {
@@ -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));
}
)
}
}

View File

@@ -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 = [