diff --git a/src/app/+search-page/filtered-search-page.component.ts b/src/app/+search-page/filtered-search-page.component.ts index ef427c5fd9..385196d23a 100644 --- a/src/app/+search-page/filtered-search-page.component.ts +++ b/src/app/+search-page/filtered-search-page.component.ts @@ -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 }); }) ); } diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index b343391478..af94645438 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -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(); } diff --git a/src/app/core/shared/search/search-configuration.service.ts b/src/app/core/shared/search/search-configuration.service.ts index bb30070450..f258578535 100644 --- a/src/app/core/shared/search/search-configuration.service.ts +++ b/src/app/core/shared/search/search-configuration.service.ts @@ -204,7 +204,8 @@ export class SearchConfigurationService implements OnDestroy { */ getCurrentFixedFilter(): Observable { return this.routeService.getRouteParameterValue('filter').pipe( - switchMap((f) => this.fixedFilterService.getQueryByFilterName(f)) + switchMap((f) => this.fixedFilterService.getQueryByFilterName(f)), + tap((t) => console.log(t)) ); } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.html index 85dcedd65e..bcc096cca8 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup-relation/dynamic-lookup-relation-modal.component.html @@ -19,7 +19,8 @@ - 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 0a29f9249c..918d623fb1 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,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; - - 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>>) => 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>>) => rd.isLoading), - concat(subject.pipe(take(1)) - ) - ) - ) as any - ) - } - close() { this.modal.close(); } diff --git a/src/app/shared/search-form/search-form.component.ts b/src/app/shared/search-form/search-form.component.ts index 4ecf5de7b6..9821882e2f 100644 --- a/src/app/shared/search-form/search-form.component.ts +++ b/src/app/shared/search-form/search-form.component.ts @@ -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(); } diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.html b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.html index 7ab7ffd0ca..8cc7d8e738 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.html +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.html @@ -1,5 +1,4 @@ - {{filterValue.value}} diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.ts index c22b487f5d..02ccf6aa8f 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.ts @@ -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(); } diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.ts index 6b454f6ee2..353e6cf76f 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.ts @@ -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(); } diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.ts index 1020340d46..e2033aed7a 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.ts @@ -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(); } diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts index 011d259c54..76f3fa3b9c 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts @@ -179,7 +179,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy { */ public getSearchLink(): string { if (this.inPlaceSearch) { - return './'; + return ''; } return this.searchService.getSearchLink(); } 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 737772c744..46e5bace6d 100644 --- a/src/app/shared/search/search-filters/search-filters.component.ts +++ b/src/app/shared/search/search-filters/search-filters.component.ts @@ -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(); } diff --git a/src/app/shared/search/search-labels/search-labels.component.ts b/src/app/shared/search/search-labels/search-labels.component.ts index cadc61c9df..9fc594017a 100644 --- a/src/app/shared/search/search-labels/search-labels.component.ts +++ b/src/app/shared/search/search-labels/search-labels.component.ts @@ -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(); } diff --git a/src/app/shared/search/search-settings/search-settings.component.ts b/src/app/shared/search/search-settings/search-settings.component.ts index a88ef5b9ee..6dac76a2c0 100644 --- a/src/app/shared/search/search-settings/search-settings.component.ts +++ b/src/app/shared/search/search-settings/search-settings.component.ts @@ -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(); } diff --git a/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.ts b/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.ts index ebe520667b..73312e072e 100644 --- a/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.ts +++ b/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.ts @@ -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(); } diff --git a/src/app/shared/services/route.reducer.ts b/src/app/shared/services/route.reducer.ts index b078521c11..5b24939d99 100644 --- a/src/app/shared/services/route.reducer.ts +++ b/src/app/shared/services/route.reducer.ts @@ -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: { diff --git a/src/app/shared/services/route.service.ts b/src/app/shared/services/route.service.ts index dc626484c1..b60c8c71a3 100644 --- a/src/app/shared/services/route.service.ts +++ b/src/app/shared/services/route.service.ts @@ -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 { - return this.store.pipe(select(routeParameterSelector(paramName))); + return this.store.pipe(select(routeParameterSelector(paramName)), tap((t) => console.log('test', t))); } getRouteDataValue(datafield: string): Observable { @@ -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)); + } } diff --git a/src/app/shared/utils/route.utils.ts b/src/app/shared/utils/route.utils.ts new file mode 100644 index 0000000000..10144083aa --- /dev/null +++ b/src/app/shared/utils/route.utils.ts @@ -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('/') +} \ No newline at end of file diff --git a/src/app/shared/view-mode-switch/view-mode-switch.component.ts b/src/app/shared/view-mode-switch/view-mode-switch.component.ts index 2ed6b8c165..945de64987 100644 --- a/src/app/shared/view-mode-switch/view-mode-switch.component.ts +++ b/src/app/shared/view-mode-switch/view-mode-switch.component.ts @@ -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(); }