Skip to content

Commit

Permalink
Merge 24a8e06 into 81b19a9
Browse files Browse the repository at this point in the history
  • Loading branch information
Atmire-Kristof committed Jul 31, 2019
2 parents 81b19a9 + 24a8e06 commit df1014c
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ds-filtered-search-page
[fixedFilterQuery]="fixedFilter"
[fixedFilter$]="fixedFilter$"
[configuration$]="configuration$"
[searchEnabled]="searchEnabled"
[sideBarWidth]="sideBarWidth">
</ds-filtered-search-page>
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ describe('RelatedEntitiesSearchComponent', () => {
expect(comp.fixedFilter).toEqual(mockFilter);
});

it('should create a fixedFilter$', () => {
comp.fixedFilter$.subscribe((fixedFilter) => {
expect(fixedFilter).toEqual(mockRelationEntityType);
it('should create a configuration$', () => {
comp.configuration$.subscribe((configuration) => {
expect(configuration).toEqual(mockRelationEntityType);
})
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class RelatedEntitiesSearchComponent implements OnInit {
@Input() sideBarWidth = 4;

fixedFilter: string;
fixedFilter$: Observable<string>;
configuration$: Observable<string>;

constructor(private fixedFilterService: SearchFixedFilterService) {
}
Expand All @@ -57,7 +57,7 @@ export class RelatedEntitiesSearchComponent implements OnInit {
this.fixedFilter = this.fixedFilterService.getFilterByRelation(this.relationType, this.item.id);
}
if (isNotEmpty(this.relationEntityType)) {
this.fixedFilter$ = of(this.relationEntityType);
this.configuration$ = of(this.relationEntityType);
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/app/+search-page/configuration-search-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { configureSearchComponentTestingModule } from './search-page.component.spec';
import { SearchConfigurationService } from './search-service/search-configuration.service';
import { ConfigurationSearchPageComponent } from './configuration-search-page.component';

describe('ConfigurationSearchPageComponent', () => {
let comp: ConfigurationSearchPageComponent;
let fixture: ComponentFixture<ConfigurationSearchPageComponent>;
let searchConfigService: SearchConfigurationService;

beforeEach(async(() => {
configureSearchComponentTestingModule(ConfigurationSearchPageComponent);
}));

beforeEach(() => {
fixture = TestBed.createComponent(ConfigurationSearchPageComponent);
comp = fixture.componentInstance;
searchConfigService = (comp as any).searchConfigService;
fixture.detectChanges();
});
});
71 changes: 71 additions & 0 deletions src/app/+search-page/configuration-search-page.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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';

/**
* This component renders a search page using a configuration as input.
*/
@Component({
selector: 'ds-configuration-search-page',
styleUrls: ['./search-page.component.scss'],
templateUrl: './search-page.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [pushInOut],
providers: [
{
provide: SEARCH_CONFIG_SERVICE,
useClass: SearchConfigurationService
}
]
})

export class ConfigurationSearchPageComponent extends SearchPageComponent implements OnInit {
/**
* The configuration to use for the search options
* If empty, the configuration will be determined by the route parameter called 'configuration'
*/
@Input() configuration: string;

constructor(protected service: SearchService,
protected sidebarService: SearchSidebarService,
protected windowService: HostWindowService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
protected routeService: RouteService) {
super(service, sidebarService, windowService, searchConfigService, routeService);
}

/**
* Listening to changes in the paginated search options
* If something changes, update the search results
*
* Listen to changes in the scope
* If something changes, update the list of scopes for the dropdown
*/
ngOnInit(): void {
super.ngOnInit();
}

/**
* Get the current paginated search options after updating the configuration using the configuration input
* This is to make sure the configuration 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 config = this.configuration || options.configuration;
return Object.assign(options, { configuration: config });
})
);
}
}
22 changes: 22 additions & 0 deletions src/app/+search-page/configuration-search-page.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';

@Injectable()
/**
* Assemble the correct i18n key for the configuration search page's title depending on the current route's configuration parameter.
* The format of the key will be "{configuration}.search.title" with:
* - configuration: The current configuration stored in route.params
*/
export class ConfigurationSearchPageGuard implements CanActivate {
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
const configuration = route.params.configuration;

const newTitle = configuration + '.search.title';

route.data = { title: newTitle };
return true;
}
}
22 changes: 0 additions & 22 deletions src/app/+search-page/filtered-search-page.guard.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/app/+search-page/search-page-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { SearchPageComponent } from './search-page.component';
import { FilteredSearchPageComponent } from './filtered-search-page.component';
import { FilteredSearchPageGuard } from './filtered-search-page.guard';
import { ConfigurationSearchPageGuard } from './configuration-search-page.guard';
import { ConfigurationSearchPageComponent } from './configuration-search-page.component';

@NgModule({
imports: [
RouterModule.forChild([
{ path: '', component: SearchPageComponent, data: { title: 'search.title' } },
{ path: ':filter', component: FilteredSearchPageComponent, canActivate: [FilteredSearchPageGuard]}
{ path: ':configuration', component: ConfigurationSearchPageComponent, canActivate: [ConfigurationSearchPageGuard]}
])
]
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/+search-page/search-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
<ds-search-results [searchResults]="resultsRD$ | async"
[searchConfig]="searchOptions$ | async"
[fixedFilter]="fixedFilter$ | async"
[configuration]="configuration$ | async"
[disableHeader]="!searchEnabled"></ds-search-results>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/app/+search-page/search-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export class SearchPageComponent implements OnInit {
sideBarWidth = 3;

/**
* The currently applied filter (determines title of search)
* The currently applied configuration (determines title of search)
*/
@Input()
fixedFilter$: Observable<string>;
configuration$: Observable<string>;

constructor(protected service: SearchService,
protected sidebarService: SearchSidebarService,
Expand All @@ -116,8 +116,8 @@ export class SearchPageComponent implements OnInit {
this.scopeListRD$ = this.searchConfigService.getCurrentScope('').pipe(
switchMap((scopeId) => this.service.getScopes(scopeId))
);
if (!isNotEmpty(this.fixedFilter$)) {
this.fixedFilter$ = this.routeService.getRouteParameterValue('filter');
if (!isNotEmpty(this.configuration$)) {
this.configuration$ = this.routeService.getRouteParameterValue('configuration');
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/app/+search-page/search-page.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import { SearchFiltersComponent } from './search-filters/search-filters.componen
import { SearchFilterComponent } from './search-filters/search-filter/search-filter.component';
import { SearchFacetFilterComponent } from './search-filters/search-filter/search-facet-filter/search-facet-filter.component';
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
import { FilteredSearchPageComponent } from './filtered-search-page.component';
import { SearchFixedFilterService } from './search-filters/search-filter/search-fixed-filter.service';
import { FilteredSearchPageGuard } from './filtered-search-page.guard';
import { SearchLabelsComponent } from './search-labels/search-labels.component';
import { SearchRangeFilterComponent } from './search-filters/search-filter/search-range-filter/search-range-filter.component';
import { SearchTextFilterComponent } from './search-filters/search-filter/search-text-filter/search-text-filter.component';
Expand All @@ -32,6 +30,9 @@ import { SearchFacetSelectedOptionComponent } from './search-filters/search-filt
import { SearchFacetRangeOptionComponent } from './search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component';
import { SearchSwitchConfigurationComponent } from './search-switch-configuration/search-switch-configuration.component';
import { SearchAuthorityFilterComponent } from './search-filters/search-filter/search-authority-filter/search-authority-filter.component';
import { ConfigurationSearchPageComponent } from './configuration-search-page.component';
import { ConfigurationSearchPageGuard } from './configuration-search-page.guard';
import { FilteredSearchPageComponent } from './filtered-search-page.component';

const effects = [
SearchSidebarEffects
Expand Down Expand Up @@ -60,7 +61,8 @@ const components = [
SearchFacetRangeOptionComponent,
SearchSwitchConfigurationComponent,
SearchAuthorityFilterComponent,
FilteredSearchPageComponent
FilteredSearchPageComponent,
ConfigurationSearchPageComponent
];

@NgModule({
Expand All @@ -76,7 +78,7 @@ const components = [
SearchSidebarService,
SearchFilterService,
SearchFixedFilterService,
FilteredSearchPageGuard,
ConfigurationSearchPageGuard,
SearchFilterService,
SearchConfigurationService
],
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
17 changes: 2 additions & 15 deletions src/app/+search-page/search-results/search-results.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,16 @@ export class SearchResultsComponent {
@Input() viewMode: SetViewMode;

/**
* An optional fixed filter to filter the result on one type
* An optional configuration to filter the result on one type
*/
@Input() fixedFilter: string;
@Input() configuration: string;

/**
* Whether or not to hide the header of the results
* Defaults to a visible header
*/
@Input() disableHeader = false;

/**
* Get the i18n key for the title depending on the fixed filter
* Defaults to 'search.results.head' if there's no fixed filter found
* @returns {string}
*/
getTitleKey() {
if (isNotEmpty(this.fixedFilter)) {
return this.fixedFilter + '.search.results.head'
} else {
return 'search.results.head';
}
}

/**
* Method to change the given string by surrounding it by quotes if not already present.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
of as observableOf,
Subscription
} from 'rxjs';
import { filter, flatMap, map, switchMap, tap } from 'rxjs/operators';
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 '../search-options.model';
Expand Down Expand Up @@ -109,9 +109,14 @@ export class SearchConfigurationService implements OnDestroy {
* @returns {Observable<string>} Emits the current configuration string
*/
getCurrentConfiguration(defaultConfiguration: string) {
return this.routeService.getQueryParameterValue('configuration').pipe(map((configuration) => {
return configuration || defaultConfiguration;
}));
return observableCombineLatest(
this.routeService.getQueryParameterValue('configuration').pipe(startWith(undefined)),
this.routeService.getRouteParameterValue('configuration').pipe(startWith(undefined))
).pipe(
map(([queryConfig, routeConfig]) => {
return queryConfig || routeConfig || defaultConfiguration;
})
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GenericConstructor } from '../../core/shared/generic-constructor';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { isNull } from '../../shared/empty.util';
import { hasNoValue, isNull } from '../../shared/empty.util';

/**
* Contains the mapping between a search result component and a DSpaceObject
Expand Down Expand Up @@ -34,7 +34,7 @@ export function searchResultFor(domainConstructor: GenericConstructor<ListableOb
* @returns The component's constructor that matches the given DSpaceObject
*/
export function getSearchResultFor(domainConstructor: GenericConstructor<ListableObject>, configuration: string = null) {
if (isNull(configuration) || configuration === 'default') {
if (isNull(configuration) || configuration === 'default' || hasNoValue(searchResultMap.get(configuration))) {
return searchResultMap.get(domainConstructor);
} else {
return searchResultMap.get(configuration).get(domainConstructor);
Expand Down

0 comments on commit df1014c

Please sign in to comment.