Skip to content

Commit

Permalink
Merge 0d34152 into 5be883f
Browse files Browse the repository at this point in the history
  • Loading branch information
LotteHofstede committed Jul 25, 2019
2 parents 5be883f + 0d34152 commit 792dff7
Show file tree
Hide file tree
Showing 82 changed files with 375 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { CommonModule } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RouteService } from '../../shared/services/route.service';
import { RouteService } from '../../core/services/route.service';
import { SharedModule } from '../../shared/shared.module';
import { CollectionDataService } from '../../core/data/collection-data.service';
import { of as observableOf } from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { CommunityDataService } from '../../core/data/community-data.service';
import { RouteService } from '../../shared/services/route.service';
import { RouteService } from '../../core/services/route.service';
import { Router } from '@angular/router';
import { CreateComColPageComponent } from '../../shared/comcol-forms/create-comcol-page/create-comcol-page.component';
import { Collection } from '../../core/shared/collection.model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { CommonModule } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RouteService } from '../../shared/services/route.service';
import { RouteService } from '../../core/services/route.service';
import { SharedModule } from '../../shared/shared.module';
import { CollectionDataService } from '../../core/data/collection-data.service';
import { of as observableOf } from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { Community } from '../../core/shared/community.model';
import { CommunityDataService } from '../../core/data/community-data.service';
import { RouteService } from '../../shared/services/route.service';
import { RouteService } from '../../core/services/route.service';
import { Router } from '@angular/router';
import { CreateComColPageComponent } from '../../shared/comcol-forms/create-comcol-page/create-comcol-page.component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { CommonModule } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RouteService } from '../../shared/services/route.service';
import { RouteService } from '../../core/services/route.service';
import { SharedModule } from '../../shared/shared.module';
import { of as observableOf } from 'rxjs';
import { NotificationsService } from '../../shared/notifications/notifications.service';
Expand Down
2 changes: 1 addition & 1 deletion src/app/+my-dspace-page/my-dspace-configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MyDSpaceConfigurationValueType } from './my-dspace-configuration-value-
import { RoleService } from '../core/roles/role.service';
import { SearchConfigurationOption } from '../+search-page/search-switch-configuration/search-configuration-option.model';
import { SearchConfigurationService } from '../+search-page/search-service/search-configuration.service';
import { RouteService } from '../shared/services/route.service';
import { RouteService } from '../core/services/route.service';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
import { SearchFixedFilterService } from '../+search-page/search-filters/search-filter/search-fixed-filter.service';
Expand Down
2 changes: 1 addition & 1 deletion src/app/+my-dspace-page/my-dspace-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { HostWindowService } from '../shared/host-window.service';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { RemoteData } from '../core/data/remote-data';
import { MyDSpacePageComponent, SEARCH_CONFIG_SERVICE } from './my-dspace-page.component';
import { RouteService } from '../shared/services/route.service';
import { RouteService } from '../core/services/route.service';
import { routeServiceStub } from '../shared/testing/route-service-stub';
import { SearchConfigurationServiceStub } from '../shared/testing/search-configuration-service-stub';
import { SearchService } from '../+search-page/search-service/search.service';
Expand Down
7 changes: 6 additions & 1 deletion src/app/+search-page/filtered-search-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ 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 { RouteService } from '../core/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 { isEmpty, isNotEmpty } from '../shared/empty.util';
import { ActivatedRoute } from '@angular/router';

/**
* This component renders a simple item page.
Expand Down Expand Up @@ -53,6 +55,9 @@ export class FilteredSearchPageComponent extends SearchPageComponent implements
* If something changes, update the list of scopes for the dropdown
*/
ngOnInit(): void {
if (isEmpty(this.fixedFilter$)) {
this.fixedFilter$ = this.routeService.getRouteParameterValue('filter');
}
super.ngOnInit();
}

Expand Down
37 changes: 33 additions & 4 deletions src/app/+search-page/filtered-search-page.guard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import {
ActivatedRouteSnapshot,
CanActivate,
NavigationEnd,
Router,
RouterStateSnapshot
} from '@angular/router';
import { Observable } from 'rxjs';
import { SearchFixedFilterService } from './search-filters/search-filter/search-fixed-filter.service';
import { map, take, tap, filter } from 'rxjs/operators';
import { isEmpty, isNotEmpty } from '../shared/empty.util';
import { Location } from '@angular/common';

@Injectable()
/**
Expand All @@ -9,14 +19,33 @@ import { Observable } from 'rxjs';
* - filter: The current filter stored in route.params
*/
export class FilteredSearchPageGuard implements CanActivate {
constructor(private service: SearchFixedFilterService, private router: Router, private location: Location) {
}

canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
const filter = route.params.filter;
route.params = Object.assign({}, route.params, { filter: route.params.filter.toLowerCase() });
const filterName = route.params.filter;

const newTitle = filter + '.search.title';
const newTitle = filterName + '.search.title';

route.data = { title: newTitle };
return true;

return this.service.getQueryByFilterName(filterName).pipe(
tap((query) => {
if (isEmpty(query)) {
this.router.navigateByUrl('/404', { skipLocationChange: true });
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
take(1)
)
.subscribe(() => this.location.replaceState(state.url));
}
}
),
map((query) => isNotEmpty(query))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
<ds-input-suggestions [suggestions]="(filterSearchResults | async)"
[placeholder]="'search.filters.filter.' + filterConfig.name + '.placeholder'| translate"
[action]="getCurrentUrl()"
[action]="currentUrl"
[name]="filterConfig.paramName"
[(ngModel)]="filter"
(submitSuggestion)="onSubmit($event)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<a *ngIf="isVisible | async" class="d-flex flex-row"
[routerLink]="[getSearchLink()]"
[routerLink]="[searchLink]"
[queryParams]="addQueryParams" queryParamsHandling="merge">
<input type="checkbox" [checked]="false" class="my-1 align-self-stretch"/>
<span class="filter-value px-1">{{filterValue.value}}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class SearchFacetOptionComponent implements OnInit, OnDestroy {
*/
addQueryParams;

searchLink: string;
/**
* Subscription to unsubscribe from on destroy
*/
Expand All @@ -66,6 +67,7 @@ export class SearchFacetOptionComponent implements OnInit, OnDestroy {
* Initializes all observable instance variables and starts listening to them
*/
ngOnInit(): void {
this.searchLink = this.getSearchLink();
this.isVisible = this.isChecked().pipe(map((checked: boolean) => !checked));
this.sub = observableCombineLatest(this.selectedValues$, this.searchConfigService.searchOptions)
.subscribe(([selectedValues, searchOptions]) => {
Expand All @@ -83,7 +85,7 @@ export class SearchFacetOptionComponent implements OnInit, OnDestroy {
/**
* @returns {string} The base path to the search page, or the current page when inPlaceSearch is true
*/
public getSearchLink(): string {
private getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<a *ngIf="isVisible | async" class="d-flex flex-row"
[routerLink]="[getSearchLink()]"
[routerLink]="[searchLink]"
[queryParams]="changeQueryParams" queryParamsHandling="merge">
<span class="filter-value px-1">{{filterValue.label}}</span>
<span class="float-right filter-value-count ml-auto">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export class SearchFacetRangeOptionComponent implements OnInit, OnDestroy {
*/
sub: Subscription;

searchLink: string;

constructor(protected searchService: SearchService,
protected filterService: SearchFilterService,
protected searchConfigService: SearchConfigurationService,
Expand All @@ -67,6 +69,7 @@ export class SearchFacetRangeOptionComponent implements OnInit, OnDestroy {
* Initializes all observable instance variables and starts listening to them
*/
ngOnInit(): void {
this.searchLink = this.getSearchLink();
this.isVisible = this.isChecked().pipe(map((checked: boolean) => !checked));
this.sub = this.searchConfigService.searchOptions.subscribe(() => {
this.updateChangeParams()
Expand All @@ -83,7 +86,7 @@ export class SearchFacetRangeOptionComponent implements OnInit, OnDestroy {
/**
* @returns {string} The base path to the search page, or the current page when inPlaceSearch is true
*/
public getSearchLink(): string {
private getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<a class="d-flex flex-row"
[routerLink]="[getSearchLink()]"
[routerLink]="[searchLink]"
[queryParams]="removeQueryParams" queryParamsHandling="merge">
<input type="checkbox" [checked]="true" class="my-1 align-self-stretch"/>
<span class="filter-value pl-1 text-capitalize">{{selectedValue.label}}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export class SearchFacetSelectedOptionComponent implements OnInit, OnDestroy {
*/
sub: Subscription;

searchLink: string;

constructor(protected searchService: SearchService,
protected filterService: SearchFilterService,
protected searchConfigService: SearchConfigurationService,
Expand All @@ -64,12 +66,13 @@ export class SearchFacetSelectedOptionComponent implements OnInit, OnDestroy {
.subscribe(([selectedValues, searchOptions]) => {
this.updateRemoveParams(selectedValues)
});
this.searchLink = this.getSearchLink();
}

/**
* @returns {string} The base path to the search page, or the current page when inPlaceSearch is true
*/
public getSearchLink(): string {
private getSearchLink(): string {
if (this.inPlaceSearch) {
return './';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
*/
searchOptions$: Observable<SearchOptions>;

/**
* The current URL
*/
currentUrl: string;

constructor(protected searchService: SearchService,
protected filterService: SearchFilterService,
protected rdbs: RemoteDataBuildService,
Expand All @@ -93,6 +98,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
* Initializes all observable instance variables and starts listening to them
*/
ngOnInit(): void {
this.currentUrl = this.router.url;
this.filterValues$ = new BehaviorSubject(new RemoteData(true, false, undefined, undefined, undefined));
this.currentPage = this.getCurrentPage().pipe(distinctUntilChanged());

Expand Down Expand Up @@ -215,13 +221,6 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
return this.filterService.getPage(this.filterConfig.name);
}

/**
* @returns {string} the current URL
*/
getCurrentUrl() {
return this.router.url;
}

/**
* Submits a new active custom value to the filter from the input field
* @param data The string from the input field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
import { mergeMap, map, distinctUntilChanged } from 'rxjs/operators';
import { distinctUntilChanged, map, mergeMap } from 'rxjs/operators';
import { Injectable, InjectionToken } from '@angular/core';
import { SearchFiltersState, SearchFilterState } from './search-filter.reducer';
import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
Expand All @@ -14,15 +14,11 @@ import {
} from './search-filter.actions';
import { hasValue, isNotEmpty, } from '../../../shared/empty.util';
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
import { RouteService } from '../../../shared/services/route.service';
import { RouteService } from '../../../core/services/route.service';
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';
import { PaginatedSearchOptions } from '../../paginated-search-options.model';
import { SearchFixedFilterService } from './search-fixed-filter.service';
import { Params } from '@angular/router';
import * as postcss from 'postcss';
import prefix = postcss.vendor.prefix;
// const spy = create();
const filterStateSelector = (state: SearchFiltersState) => state.searchFilter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { SearchFixedFilterService } from './search-fixed-filter.service';
import { RouteService } from '../../../shared/services/route.service';
import { RequestService } from '../../../core/data/request.service';
import { HALEndpointService } from '../../../core/shared/hal-endpoint.service';
import { of as observableOf } from 'rxjs';
import { RequestEntry } from '../../../core/data/request.reducer';
import { FilteredDiscoveryQueryResponse, RestResponse } from '../../../core/cache/response.models';
import {SearchFixedFilterService} from './search-fixed-filter.service';
import {RequestService} from '../../../core/data/request.service';
import {HALEndpointService} from '../../../core/shared/hal-endpoint.service';
import {of as observableOf} from 'rxjs';
import {RequestEntry} from '../../../core/data/request.reducer';
import {FilteredDiscoveryQueryResponse} from '../../../core/cache/response.models';

describe('SearchFixedFilterService', () => {
let service: SearchFixedFilterService;

const filterQuery = 'filter:query';

const routeServiceStub = {} as RouteService;
const requestServiceStub = Object.assign({
/* tslint:disable:no-empty */
configure: () => {},
Expand All @@ -26,7 +24,7 @@ describe('SearchFixedFilterService', () => {
});

beforeEach(() => {
service = new SearchFixedFilterService(routeServiceStub, requestServiceStub, halServiceStub);
service = new SearchFixedFilterService(requestServiceStub, halServiceStub);
});

describe('when getQueryByFilterName is called with a filterName', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { GenericConstructor } from '../../../core/shared/generic-constructor';
import { FilteredDiscoveryPageResponseParsingService } from '../../../core/data/filtered-discovery-page-response-parsing.service';
import { hasValue } from '../../../shared/empty.util';
import { configureRequest, getResponseFromEntry } from '../../../core/shared/operators';
import { RouteService } from '../../../shared/services/route.service';
import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models';

/**
Expand All @@ -19,8 +18,7 @@ import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.mod
export class SearchFixedFilterService {
private queryByFilterPath = 'filtered-discovery-pages';

constructor(private routeService: RouteService,
protected requestService: RequestService,
constructor(protected requestService: RequestService,
private halService: HALEndpointService) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
<ds-input-suggestions [suggestions]="(filterSearchResults | async)"
[placeholder]="'search.filters.filter.' + filterConfig.name + '.placeholder'| translate"
[action]="getCurrentUrl()"
[action]="currentUrl"
[name]="filterConfig.paramName"
[(ngModel)]="filter"
(submitSuggestion)="onSubmit($event)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
<div class="filters py-2">
<form #form="ngForm" (ngSubmit)="onSubmit()" class="add-filter row"
[action]="getCurrentUrl()">
[action]="currentUrl">
<div class="col-6">
<input type="text" [(ngModel)]="range[0]" [name]="filterConfig.paramName + '.min'"
class="form-control" (blur)="onSubmit()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { RouterStub } from '../../../../shared/testing/router-stub';
import { Router } from '@angular/router';
import { PageInfo } from '../../../../core/shared/page-info.model';
import { SearchRangeFilterComponent } from './search-range-filter.component';
import { RouteService } from '../../../../shared/services/route.service';
import { RouteService } from '../../../../core/services/route.service';
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
import { SEARCH_CONFIG_SERVICE } from '../../../../+my-dspace-page/my-dspace-page.component';
import { SearchConfigurationServiceStub } from '../../../../shared/testing/search-configuration-service-stub';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FILTER_CONFIG, IN_PLACE_SEARCH, SearchFilterService } from '../search-f
import { SearchService } from '../../../search-service/search.service';
import { Router } from '@angular/router';
import * as moment from 'moment';
import { RouteService } from '../../../../shared/services/route.service';
import { RouteService } from '../../../../core/services/route.service';
import { hasValue } from '../../../../shared/empty.util';
import { SearchConfigurationService } from '../../../search-service/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../../+my-dspace-page/my-dspace-page.component';
Expand Down

0 comments on commit 792dff7

Please sign in to comment.