Skip to content

Commit

Permalink
Merge branch 'dspace-cris-7' into DSC-283-align-with-7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Nov 11, 2021
2 parents f811fdc + 00ecd00 commit f1b60c0
Show file tree
Hide file tree
Showing 29 changed files with 505 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<div class="d-inline">
<div ngbDropdown class="d-inline">
<button class="btn btn-success" id="dropdownSubmission" ngbDropdownToggle
type="button">
<button *ngIf="isCollectionFixed; else chooseCollection" class="btn btn-success" type="button" (click)="approveAndImportCollectionFixed()">
<i class="fa fa-check" aria-hidden="true"></i> {{ approveAndImportLabel() | translate}}
<span class="caret"></span>
</button>
<div ngbDropdownMenu
class="dropdown-menu"
id="entityControlsDropdownMenu"
aria-labelledby="dropdownSubmission">
<ds-entity-dropdown (selectionChange)="openDialog($event)"></ds-entity-dropdown>
</div>
<ng-template #chooseCollection>
<button class="btn btn-success" id="dropdownSubmission" ngbDropdownToggle
type="button">
<i class="fa fa-check" aria-hidden="true"></i> {{ approveAndImportLabel() | translate}}
<span class="caret"></span>
</button>

<div ngbDropdownMenu
class="dropdown-menu"
id="entityControlsDropdownMenu"
aria-labelledby="dropdownSubmission">
<ds-entity-dropdown (selectionChange)="openDialog($event)"></ds-entity-dropdown>
</div>
</ng-template>

</div>
<button (click)="notMine()" class="btn btn-danger ml-2"><i class="fa fa-ban"></i>
{{ notMineLabel() | translate}}</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ export class SuggestionActionsComponent {

@Input() isBulk = false;

@Input() public hasEvidence = false;
@Input() hasEvidence = false;

@Input() public seeEvidence = false;
@Input() seeEvidence = false;

@Input() isCollectionFixed = false;

/**
* The component is used to Delete suggestion
Expand Down Expand Up @@ -58,6 +60,14 @@ export class SuggestionActionsComponent {
});
}

approveAndImportCollectionFixed() {
this.approveAndImport.emit({
suggestion: this.isBulk ? undefined : this.object,
collectionId: null
});
}


/**
* Delete the suggestion
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<ds-suggestion-actions class="parent mt-2" [hasEvidence]="hasEvidences()"
[seeEvidence]="seeEvidence"
[object]="object"
[isCollectionFixed]="isCollectionFixed"
(approveAndImport)="onApproveAndImport($event)"
(seeEvidences)="onSeeEvidences($event)"
(notMineClicked)="onNotMine($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class SuggestionListElementComponent implements OnInit {

@Input() isSelected = false;

@Input() isCollectionFixed = false;

public listableObject: any;

public seeEvidence = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-container *ngIf="(suggestionsRD$ | async) as suggestions">
<ng-container *ngFor="let suggestion of suggestions" class="alert alert-info">
<div class="alert alert-success" *ngIf="suggestion.total > 0">
<div class="alert alert-success d-block" *ngIf="suggestion.total > 0">
<div [innerHTML]="'mydspace.notification.suggestion.page' | translate: getNotificationSuggestionInterpolation(suggestion)">
</div>
</div>
Expand Down
57 changes: 52 additions & 5 deletions src/app/openaire/reciter-suggestions/suggestions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { OpenaireSuggestionTarget } from '../../core/openaire/reciter-suggestion
import { ResearcherProfileService } from '../../core/profile/researcher-profile.service';
import { AuthService } from '../../core/auth/auth.service';
import { EPerson } from '../../core/eperson/models/eperson.model';
import { isNotEmpty } from '../../shared/empty.util';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { ResearcherProfile } from '../../core/profile/model/researcher-profile.model';
import {
getAllSucceededRemoteDataPayload,
Expand All @@ -24,6 +24,9 @@ import { OpenaireSuggestion } from '../../core/openaire/reciter-suggestions/mode
import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service';
import { TranslateService } from '@ngx-translate/core';
import { NoContent } from '../../core/shared/NoContent.model';
import { environment } from '../../../environments/environment';
import { SuggestionConfig } from '../../../config/layout-config.interfaces';
import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model';

export interface SuggestionBulkResult {
success: number;
Expand Down Expand Up @@ -170,8 +173,10 @@ export class SuggestionsService {
*/
public approveAndImport(workspaceitemService: WorkspaceitemDataService,
suggestion: OpenaireSuggestion,
collectionId: string): Observable<string> {
return workspaceitemService.importExternalSourceEntry(suggestion.externalSourceUri, collectionId)
collectionId: string): Observable<WorkspaceItem> {

const resolvedCollectionId = this.resolveCollectionId(suggestion, collectionId);
return workspaceitemService.importExternalSourceEntry(suggestion.externalSourceUri, resolvedCollectionId)
.pipe(
getFirstSucceededRemoteDataPayload(),
catchError((error) => of(null))
Expand Down Expand Up @@ -200,7 +205,7 @@ export class SuggestionsService {

return forkJoin(suggestions.map((suggestion: OpenaireSuggestion) =>
this.approveAndImport(workspaceitemService, suggestion, collectionId)))
.pipe(map((results: string[]) => {
.pipe(map((results: WorkspaceItem[]) => {
return {
success: results.filter((result) => result != null).length,
fails: results.filter((result) => result == null).length
Expand Down Expand Up @@ -240,10 +245,52 @@ export class SuggestionsService {
public getNotificationSuggestionInterpolation(suggestionTarget: OpenaireSuggestionTarget): any {
return {
count: suggestionTarget.total,
source: this.translateService.instant('reciter.suggestion.source.' + suggestionTarget.source),
source: this.translateService.instant(this.translateSuggestionSource(suggestionTarget.source)),
type: this.translateService.instant(this.translateSuggestionType(suggestionTarget.source)),
suggestionId: suggestionTarget.id,
displayName: suggestionTarget.display
};
}

public translateSuggestionType(source: string): string {
return 'reciter.suggestion.type.' + source;
}

public translateSuggestionSource(source: string): string {
return 'reciter.suggestion.source.' + source;
}

/**
* If the provided collectionId ha no value, tries to resolve it by suggestion source.
* @param suggestion
* @param collectionId
*/
public resolveCollectionId(suggestion: OpenaireSuggestion, collectionId): string {
if (hasValue(collectionId)) {
return collectionId;
}
return environment.suggestion
.find((suggestionConf: SuggestionConfig) => suggestionConf.source === suggestion.source)
.collectionId;
}

/**
* Return true if all the suggestion are configured with the same fixed collection
* in the configuration.
* @param suggestions
*/
public isCollectionFixed(suggestions: OpenaireSuggestion[]): boolean {
return this.getFixedCollectionIds(suggestions).length === 1;
}

private getFixedCollectionIds(suggestions: OpenaireSuggestion[]): string[] {
const collectionIds = {};
suggestions.forEach((suggestion: OpenaireSuggestion) => {
const conf = environment.suggestion.find((suggestionConf: SuggestionConfig) => suggestionConf.source === suggestion.source);
if (hasValue(conf)) {
collectionIds[conf.collectionId] = true;
}
});
return Object.keys(collectionIds);
}
}
5 changes: 4 additions & 1 deletion src/app/profile-page/profile-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ <h3 class="mb-4">{{'profile.head' | translate}}</h3>
<div class="card mb-4">
<div class="card-header">{{'profile.card.researcher' | translate}}</div>
<div class="card-body">
<ds-profile-page-researcher-form [user]="user"></ds-profile-page-researcher-form>
<div class="mb-4">
<ds-profile-page-researcher-form [user]="user"></ds-profile-page-researcher-form>
</div>
<ds-suggestions-notification></ds-suggestions-notification>
</div>
</div>
<div class="card mb-4">
Expand Down
4 changes: 3 additions & 1 deletion src/app/profile-page/profile-page.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { ProfilePageSecurityFormComponent } from './profile-page-security-form/p
import { ProfilePageResearcherFormComponent } from './profile-page-researcher-form/profile-page-researcher-form.component';
import { ThemedProfilePageComponent } from './themed-profile-page.component';
import { UiSwitchModule } from 'ngx-ui-switch';
import { OpenaireModule } from '../openaire/openaire.module';

@NgModule({
imports: [
ProfilePageRoutingModule,
CommonModule,
SharedModule,
UiSwitchModule
UiSwitchModule,
OpenaireModule
],
exports: [
ProfilePageComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<div class="col-12">
<h2>{{ 'explore.facet-section.title' | translate }}</h2>
<div class="row">
<div *ngFor="let facet of (facets$ | async)" class="col-{{getFacetsBoxCol()}} mb-4">
<div *ngFor="let facet of (facets$ | async)" class="col-{{getFacetsBoxCol(facet)}} mb-4">
<span>{{'explore.index.' + facet.name | translate}}</span>
<div *ngFor="let facetValue of facet._embedded.values" class="border p-3">
<a [routerLink]="[searchService.getSearchLink()]"
[queryParams]="getSearchQueryParams(facet, facetValue)">
{{facetValue.label}}
</a>
<span class="badge badge-secondary float-right">{{facetValue.count}}</span>
<div *ngIf="facet.filterType.includes('chart'); else notChartFacet">
<ds-search-chart [filter]="facet" [inPlaceSearch]="false"> </ds-search-chart>
</div>
<ng-template #notChartFacet>
<div *ngFor="let facetValue of facet._embedded.values" class="border p-3">
<a [routerLink]="[searchService.getSearchLink()]"
[queryParams]="getSearchQueryParams(facet, facetValue)">
{{facetValue.label}}
</a>
<span class="badge badge-secondary float-right">{{facetValue.count}}</span>
</div>
</ng-template>

</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import { FacetValue } from '../../../search/facet-value.model';
import { FilterType } from '../../../search/filter-type.model';
import { SearchFilterConfig } from '../../../search/search-filter-config.model';
import { FacetSectionComponent } from './facet-section.component';
import {SEARCH_CONFIG_SERVICE} from '../../../../my-dspace-page/my-dspace-page.component';
import {SearchConfigurationServiceStub} from '../../../testing/search-configuration-service.stub';
import {StoreModule} from '@ngrx/store';
import {authReducer} from '../../../../core/auth/auth.reducer';
import {storeModuleConfig} from '../../../../app.reducer';
import {isNotNull} from '../../../empty.util';

describe('FacetSectionComponent', () => {
let component: FacetSectionComponent;
Expand Down Expand Up @@ -75,12 +81,43 @@ describe('FacetSectionComponent', () => {
values: [dateIssuedValue]
}
});

const barChartFacetValue: FacetValue = {
label: '2007',
value: '2007',
count: 13,
_links: {
self: { href: 'fa-selectedValue-self-link' },
search: { href: '' }
}
};
const mockGraphBarChartFilterConfig = Object.assign(new SearchFilterConfig(), {
name: 'dateIssued',
filterType: FilterType['chart.bar'],
_embedded: {
values: [barChartFacetValue]
}
});
const pieChartFacetValue: FacetValue = {
label: 'Other',
value: 'Other',
count: 13,
_links: {
self: { href: 'fa-selectedValue-self-link' },
search: { href: '' }
}
};
const mockGraphPieChartFilterConfig = Object.assign(new SearchFilterConfig(), {
name: 'dateIssued',
filterType: FilterType['chart.pie'],
_embedded: {
values: [pieChartFacetValue]
}
});
beforeEach(async(() => {

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

TestBed.configureTestingModule({
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, RouterTestingModule,
StoreModule.forRoot({ auth: authReducer }, storeModuleConfig),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
Expand All @@ -98,7 +136,8 @@ describe('FacetSectionComponent', () => {
],
declarations: [FacetSectionComponent],
providers: [FacetSectionComponent,
{ provide: SearchService, useValue: searchServiceStub }],
{ provide: SearchService, useValue: searchServiceStub },
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();

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

it('should create a facet section foreach not empty filter configs', () => {
// graph facets control
const graphFacets = fixture.debugElement.queryAll(By.css('.col-6.mb-4'));
expect(graphFacets.length).toEqual(2);
const barChartFacet = graphFacets[0];
expect(barChartFacet.name).toEqual('div');
expect(barChartFacet.children.length).toEqual(2);
const barChartComponent = barChartFacet.query(By.css('ds-search-chart'));
expect(isNotNull(barChartComponent)).toBe(true);
const pieChartFacet = graphFacets[1];
expect(pieChartFacet.children.length).toEqual(2);
expect(pieChartFacet.name).toEqual('div');
const pieChartComponent = pieChartFacet.query(By.css('ds-search-chart'));
expect(isNotNull(pieChartComponent)).toBe(true);

const facets = fixture.debugElement.queryAll(By.css('.col-3.mb-4'));
expect(facets.length).toEqual(2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core';
import {Component, Inject, Input, OnInit} from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { FacetSection } from '../../../../core/layout/models/section.model';
import { getFirstSucceededRemoteDataPayload } from '../../../../core/shared/operators';
Expand All @@ -7,13 +7,21 @@ import { SearchFilterConfig } from '../../../search/search-filter-config.model';
import { FilterType } from '../../../search/filter-type.model';
import { FacetValue } from '../../../search/facet-value.model';
import { getFacetValueForTypeAndLabel } from '../../../search/search.utils';
import {SEARCH_CONFIG_SERVICE} from '../../../../my-dspace-page/my-dspace-page.component';
import {SearchConfigurationService} from '../../../../core/shared/search/search-configuration.service';

/**
* Component representing the Facet component section.
*/
@Component({
selector: 'ds-facet-section',
templateUrl: './facet-section.component.html'
templateUrl: './facet-section.component.html',
providers: [
{
provide: SEARCH_CONFIG_SERVICE,
useClass: SearchConfigurationService
}
]
})
export class FacetSectionComponent implements OnInit {

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

constructor(public searchService: SearchService) {
constructor(public searchService: SearchService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
) {

}

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

getFacetsBoxCol() {
getFacetsBoxCol(facet) {
if (facet.filterType.includes('chart')) {
return 6;
}
const facetsPerRow = this.facetSection.facetsPerRow ? this.facetSection.facetsPerRow : 4;
return 12 / facetsPerRow;
}
Expand Down
Loading

0 comments on commit f1b60c0

Please sign in to comment.