Skip to content

Commit 54021da

Browse files
author
Luca Giamminonni
committed
Merged in DSC-213 (pull request #37)
2 parents d7fe870 + c5eb935 commit 54021da

4 files changed

Lines changed: 90 additions & 14 deletions

File tree

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
<div class="col-12">
22
<h2>{{ 'explore.facet-section.title' | translate }}</h2>
33
<div class="row">
4-
<div *ngFor="let facet of (facets$ | async)" class="col-{{getFacetsBoxCol()}} mb-4">
4+
<div *ngFor="let facet of (facets$ | async)" class="col-{{getFacetsBoxCol(facet)}} mb-4">
55
<span>{{'explore.index.' + facet.name | translate}}</span>
6-
<div *ngFor="let facetValue of facet._embedded.values" class="border p-3">
7-
<a [routerLink]="[searchService.getSearchLink()]"
8-
[queryParams]="getSearchQueryParams(facet, facetValue)">
9-
{{facetValue.label}}
10-
</a>
11-
<span class="badge badge-secondary float-right">{{facetValue.count}}</span>
6+
<div *ngIf="facet.filterType.includes('chart'); else notChartFacet">
7+
<ds-search-chart [filter]="facet" [inPlaceSearch]="false"> </ds-search-chart>
128
</div>
9+
<ng-template #notChartFacet>
10+
<div *ngFor="let facetValue of facet._embedded.values" class="border p-3">
11+
<a [routerLink]="[searchService.getSearchLink()]"
12+
[queryParams]="getSearchQueryParams(facet, facetValue)">
13+
{{facetValue.label}}
14+
</a>
15+
<span class="badge badge-secondary float-right">{{facetValue.count}}</span>
16+
</div>
17+
</ng-template>
18+
1319
</div>
1420
</div>
1521
</div>

src/app/shared/explore/section-component/facet-section/facet-section.component.spec.ts

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import { FacetValue } from '../../../search/facet-value.model';
1515
import { FilterType } from '../../../search/filter-type.model';
1616
import { SearchFilterConfig } from '../../../search/search-filter-config.model';
1717
import { FacetSectionComponent } from './facet-section.component';
18+
import {SEARCH_CONFIG_SERVICE} from '../../../../my-dspace-page/my-dspace-page.component';
19+
import {SearchConfigurationServiceStub} from '../../../testing/search-configuration-service.stub';
20+
import {StoreModule} from '@ngrx/store';
21+
import {authReducer} from '../../../../core/auth/auth.reducer';
22+
import {storeModuleConfig} from '../../../../app.reducer';
23+
import {isNotNull} from '../../../empty.util';
1824

1925
describe('FacetSectionComponent', () => {
2026
let component: FacetSectionComponent;
@@ -75,12 +81,43 @@ describe('FacetSectionComponent', () => {
7581
values: [dateIssuedValue]
7682
}
7783
});
78-
84+
const barChartFacetValue: FacetValue = {
85+
label: '2007',
86+
value: '2007',
87+
count: 13,
88+
_links: {
89+
self: { href: 'fa-selectedValue-self-link' },
90+
search: { href: '' }
91+
}
92+
};
93+
const mockGraphBarChartFilterConfig = Object.assign(new SearchFilterConfig(), {
94+
name: 'dateIssued',
95+
filterType: FilterType['chart.bar'],
96+
_embedded: {
97+
values: [barChartFacetValue]
98+
}
99+
});
100+
const pieChartFacetValue: FacetValue = {
101+
label: 'Other',
102+
value: 'Other',
103+
count: 13,
104+
_links: {
105+
self: { href: 'fa-selectedValue-self-link' },
106+
search: { href: '' }
107+
}
108+
};
109+
const mockGraphPieChartFilterConfig = Object.assign(new SearchFilterConfig(), {
110+
name: 'dateIssued',
111+
filterType: FilterType['chart.pie'],
112+
_embedded: {
113+
values: [pieChartFacetValue]
114+
}
115+
});
79116
beforeEach(async(() => {
80117

81118
searchServiceStub = {
82119
searchFacets(scope?: string, configurationName?: string): Observable<RemoteData<SearchFilterConfig[]>> {
83-
return createSuccessfulRemoteDataObject$([mockAuthorFilterConfig, mockSubjectFilterConfig, mockDateIssuedFilterConfig]);
120+
return createSuccessfulRemoteDataObject$([mockAuthorFilterConfig, mockSubjectFilterConfig, mockDateIssuedFilterConfig, mockGraphBarChartFilterConfig, mockGraphPieChartFilterConfig]);
84121
},
85122
getSearchLink(): string {
86123
return '/search';
@@ -89,6 +126,7 @@ describe('FacetSectionComponent', () => {
89126

90127
TestBed.configureTestingModule({
91128
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, RouterTestingModule,
129+
StoreModule.forRoot({ auth: authReducer }, storeModuleConfig),
92130
TranslateModule.forRoot({
93131
loader: {
94132
provide: TranslateLoader,
@@ -98,7 +136,8 @@ describe('FacetSectionComponent', () => {
98136
],
99137
declarations: [FacetSectionComponent],
100138
providers: [FacetSectionComponent,
101-
{ provide: SearchService, useValue: searchServiceStub }],
139+
{ provide: SearchService, useValue: searchServiceStub },
140+
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }],
102141
schemas: [NO_ERRORS_SCHEMA]
103142
}).compileComponents();
104143

@@ -124,6 +163,20 @@ describe('FacetSectionComponent', () => {
124163
}));
125164

126165
it('should create a facet section foreach not empty filter configs', () => {
166+
// graph facets control
167+
const graphFacets = fixture.debugElement.queryAll(By.css('.col-6.mb-4'));
168+
expect(graphFacets.length).toEqual(2);
169+
const barChartFacet = graphFacets[0];
170+
expect(barChartFacet.name).toEqual('div');
171+
expect(barChartFacet.children.length).toEqual(2);
172+
const barChartComponent = barChartFacet.query(By.css('ds-search-chart'));
173+
expect(isNotNull(barChartComponent)).toBe(true);
174+
const pieChartFacet = graphFacets[1];
175+
expect(pieChartFacet.children.length).toEqual(2);
176+
expect(pieChartFacet.name).toEqual('div');
177+
const pieChartComponent = pieChartFacet.query(By.css('ds-search-chart'));
178+
expect(isNotNull(pieChartComponent)).toBe(true);
179+
127180
const facets = fixture.debugElement.queryAll(By.css('.col-3.mb-4'));
128181
expect(facets.length).toEqual(2);
129182

src/app/shared/explore/section-component/facet-section/facet-section.component.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import {Component, Inject, Input, OnInit} from '@angular/core';
22
import { BehaviorSubject } from 'rxjs';
33
import { FacetSection } from '../../../../core/layout/models/section.model';
44
import { getFirstSucceededRemoteDataPayload } from '../../../../core/shared/operators';
@@ -7,13 +7,21 @@ import { SearchFilterConfig } from '../../../search/search-filter-config.model';
77
import { FilterType } from '../../../search/filter-type.model';
88
import { FacetValue } from '../../../search/facet-value.model';
99
import { getFacetValueForTypeAndLabel } from '../../../search/search.utils';
10+
import {SEARCH_CONFIG_SERVICE} from '../../../../my-dspace-page/my-dspace-page.component';
11+
import {SearchConfigurationService} from '../../../../core/shared/search/search-configuration.service';
1012

1113
/**
1214
* Component representing the Facet component section.
1315
*/
1416
@Component({
1517
selector: 'ds-facet-section',
16-
templateUrl: './facet-section.component.html'
18+
templateUrl: './facet-section.component.html',
19+
providers: [
20+
{
21+
provide: SEARCH_CONFIG_SERVICE,
22+
useClass: SearchConfigurationService
23+
}
24+
]
1725
})
1826
export class FacetSectionComponent implements OnInit {
1927

@@ -28,7 +36,9 @@ export class FacetSectionComponent implements OnInit {
2836
facets: SearchFilterConfig[] = [];
2937
facets$ = new BehaviorSubject(this.facets);
3038

31-
constructor(public searchService: SearchService) {
39+
constructor(public searchService: SearchService,
40+
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
41+
) {
3242

3343
}
3444

@@ -75,7 +85,10 @@ export class FacetSectionComponent implements OnInit {
7585
return filterType === FilterType.range && value.split('-').length === 2;
7686
}
7787

78-
getFacetsBoxCol() {
88+
getFacetsBoxCol(facet) {
89+
if (facet.filterType.includes('chart')) {
90+
return 6;
91+
}
7992
const facetsPerRow = this.facetSection.facetsPerRow ? this.facetSection.facetsPerRow : 4;
8093
return 12 / facetsPerRow;
8194
}

src/assets/i18n/en.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,10 @@
15661566

15671567
"explore.index.author" : "Author",
15681568

1569+
"explore.index.graphitemtype" : "Graph by type",
1570+
1571+
"explore.index.graphpubldate" : "Graph by date",
1572+
15691573
"explore.index.birthDate" : "Birthday",
15701574

15711575
"explore.index.metric.view" : "Most viewed",

0 commit comments

Comments
 (0)