refactor numbersComponent file

This commit is contained in:
Alex Martzios 2022-11-08 14:09:03 +02:00
parent 97c350dfec
commit a2fea9e323
1 changed files with 68 additions and 202 deletions

View File

@ -7,8 +7,8 @@ import {properties} from '../../../../environments/environment';
import {NumberSize, NumberUtils} from '../../utils/number-utils.class';
import {BehaviorSubject, Observable, Subscription, zip} from 'rxjs';
import {RouterHelper} from "../../utils/routerHelper.class";
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {OpenaireEntities} from "../../utils/properties/searchFields";
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
export interface Numbers {
publicationsSize?: NumberSize;
@ -23,152 +23,57 @@ export interface Numbers {
organizationsSize?: NumberSize;
}
type Entity = 'publication' | 'dataset' | 'software' | 'other' | 'project' | 'datasource' | 'organization';
interface Link {
link: string,
params?: any
}
@Component({
selector: 'numbers',
template: `
<div *ngIf="!loading && numbers">
<div class="uk-container uk-section uk-padding-remove-bottom uk-text-center">
<div class="uk-grid uk-grid-large uk-child-width-1-3@m" uk-grid>
<div *ngIf="numbers.fundersSize">
<h3 *ngIf="links.get('project')">
<a *ngIf="externalLink" [href]="links.get('project').link" target="_blank" class="uk-text-bold number uk-link-text uk-button-link">
{{numbers.fundersSize.number|number}}<span class="number-size">{{numbers.fundersSize.size}}</span>
</a>
<a *ngIf="!externalLink" [routerLink]="links.get('project').link"
[queryParams]="links.get('project').params" class="uk-text-bold number uk-link-text uk-button-link">
{{numbers.fundersSize.number|number}}<span class="number-size">{{numbers.fundersSize.size}}</span>
</a>
</h3>
<span class="uk-text-uppercase uk-text-large">Funders</span>
</div>
<div *ngIf="numbers.datasourcesSize">
<h3>
<a *ngIf="externalLink" [href]="links.get('datasource').link" target="_blank" class="uk-text-bold number uk-link-text uk-button-link">
{{numbers.datasourcesSize.number|number}}<span
class="number-size">{{numbers.datasourcesSize.size}}</span>
</a>
<a *ngIf="!externalLink" [routerLink]="links.get('datasource').link"
[queryParams]="links.get('datasource').params" class="uk-text-bold number uk-link-text uk-button-link">
{{numbers.datasourcesSize.number|number}}<span
class="number-size">{{numbers.datasourcesSize.size}}</span>
</a>
</h3>
<span class="uk-text-uppercase uk-text-large">{{openaireEntities.DATASOURCES}}</span>
</div>
<div *ngIf="numbers.projectsSize">
<h3>
<a *ngIf="externalLink" [href]="links.get('project').link" target="_blank" class="uk-text-bold number uk-link-text uk-button-link">
{{numbers.projectsSize.number|number}}<span class="number-size">{{numbers.projectsSize.size}}</span>
</a>
<a *ngIf="!externalLink" [routerLink]="links.get('project').link"
[queryParams]="links.get('project').params" class="uk-text-bold number uk-link-text uk-button-link">
{{numbers.projectsSize.number|number}}<span class="number-size">{{numbers.projectsSize.size}}</span>
</a>
</h3>
<span class="uk-text-uppercase uk-text-large">{{openaireEntities.PROJECTS}}</span>
</div>
</div>
</div>
<div class="uk-section uk-margin-top" [ngClass]="backgroundClass">
<div class="uk-container">
<div class="uk-grid uk-flex-center uk-margin-auto-left@m uk-margin-auto-right@m uk-grid-large" uk-grid>
<div *ngIf="numbers.publicationsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
<div class="number-width uk-width-medium uk-flex uk-flex-column">
<a *ngIf="externalLink" [href]="links.get('publication').link" target="_blank"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.publicationsSize.count|number}}</a>
<a *ngIf="!externalLink" [routerLink]="links.get('publication').link"
[queryParams]="links.get('publication').params"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.publicationsSize.count|number}}</a>
<div class="uk-text-uppercase uk-flex uk-flex-middle uk-flex-center uk-flex-left@m">
<icon name="book" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
<span>{{openaireEntities.PUBLICATIONS}}</span>
</div>
</div>
</div>
<div *ngIf="numbers.datasetsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
<div class="number-width uk-width-medium uk-flex uk-flex-column">
<a *ngIf="externalLink" [href]="links.get('dataset').link" target="_blank"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.datasetsSize.count|number}}</a>
<a *ngIf="!externalLink" [routerLink]="links.get('dataset').link"
[queryParams]="links.get('dataset').params"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.datasetsSize.count|number}}</a>
<div class="uk-text-uppercase uk-flex uk-flex-middle uk-flex-center uk-flex-left@m">
<icon name="database" ratio="1.5" [flex]="true" class="uk-margin-right"
[customClass]="colorClass"></icon>
<span>{{openaireEntities.DATASETS}}</span>
</div>
</div>
</div>
<div *ngIf="numbers.softwareSize" class="uk-width-1-2@m uk-flex uk-flex-center">
<div class="number-width uk-width-medium uk-flex uk-flex-column">
<a *ngIf="externalLink" [href]="links.get('software').link" target="_blank"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.softwareSize.count|number}}</a>
<a *ngIf="!externalLink" [routerLink]="links.get('software').link"
[queryParams]="links.get('software').params"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.softwareSize.count|number}}</a>
<div class="uk-text-uppercase uk-flex uk-flex-middle uk-flex-center uk-flex-left@m">
<icon name="cog" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
<span>{{openaireEntities.SOFTWARE}}</span>
</div>
</div>
</div>
<div *ngIf="numbers.otherSize" class="uk-width-1-2@m uk-flex uk-flex-center">
<div class="number-width uk-width-medium uk-flex uk-flex-column">
<a *ngIf="externalLink" [href]="links.get('other').link" target="_blank"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.otherSize.count|number}}</a>
<a *ngIf="!externalLink" [routerLink]="links.get('other').link"
[queryParams]="links.get('other').params"
class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m uk-link-text uk-button-link">{{numbers.otherSize.count|number}}</a>
<div class="uk-text-uppercase uk-flex uk-flex-middle uk-flex-center uk-flex-left@m">
<icon name="earth" ratio="1.5" [flex]="true" class="uk-margin-right"
[customClass]="colorClass"></icon>
<span>{{openaireEntities.OTHER}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div *ngIf="loading" class="uk-container uk-section uk-text-center" style="min-height: 400px">
<loading [color]="colorClass"></loading>
</div>
<div *ngIf="showContentWithNumbers" class="uk-margin-top" style="max-width: 600px;" uk-scrollspy-class>
<div>
A comprehensive and open dataset of research information covering
<span *ngIf="hasPublications" class="uk-text-bold">{{numbers.publicationsSize.number|number}}<span class="uk-text-lowercase">{{numbers.publicationsSize.size}}</span> {{openaireEntities.PUBLICATIONS.toLowerCase()}}</span>
<ng-container *ngIf="(hasPublications && (hasDatasets || hasSoftware || (hasDatasources || hasProjects || hasOrganizations)))">, </ng-container>
<span *ngIf="hasDatasets" class="uk-text-bold">{{numbers.datasetsSize.number|number}}<span class="uk-text-lowercase">{{numbers.datasetsSize.size}}</span> {{openaireEntities.DATASETS.toLowerCase()}}</span>
<ng-container *ngIf="(hasDatasets && (hasSoftware || (hasDatasources || hasProjects || hasOrganizations)))">, </ng-container>
<span *ngIf="hasSoftware" class="uk-text-bold">{{numbers.softwareSize.number|number}}<span class="uk-text-lowercase">{{numbers.softwareSize.size}}</span> {{openaireEntities.SOFTWARE.toLowerCase()}} items</span>
<ng-container *ngIf="(hasSoftware && (hasDatasources || hasProjects || hasOrganizations))">, </ng-container>
<ng-container *ngIf="((hasPublications || hasDatasets || hasSoftware) && (hasDatasources))"> from </ng-container>
<span *ngIf="hasDatasources" class="uk-text-bold">{{numbers.datasourcesSize.number|number}}<span class="uk-text-lowercase">{{numbers.datasourcesSize.size}}</span> {{openaireEntities.DATASOURCES.toLowerCase()}}</span>
<ng-container *ngIf="(hasDatasources) && ((hasProjects) || hasOrganizations)">, linked to </ng-container>
<span *ngIf="hasProjects" class="uk-text-bold">{{numbers.projectsSize.number|number}}<span class="uk-text-lowercase">{{numbers.projectsSize.size}}</span> grants</span>
<ng-container *ngIf="hasProjects && hasOrganizations"> and </ng-container>
<span *ngIf="hasOrganizations" class="uk-text-bold">{{numbers.organizationsSize.number|number}}<span class="uk-text-lowercase">{{numbers.organizationsSize.size}}</span> {{openaireEntities.ORGANIZATIONS.toLowerCase()}}</span>.
</div>
<div class="uk-text-primary">All linked together through citations and semantics.</div>
</div>
`,
})
export class NumbersComponent implements OnInit, OnDestroy {
@Input() colorClass = 'uk-text-primary';
@Input() backgroundClass = null;
/** Add a value if you want to apply refine query*/
@Input() refineValue = null;
/** True: Default initialization
* False: Call init method to initialize numbers */
@Input() defaultInit = true;
/** Add an external link for numbers link */
@Input() externalLink;
/** When numbers have been initialized this emitter will emitted */
@Output() results: EventEmitter<Numbers> = new EventEmitter<Numbers>();
@Output() results: EventEmitter<Numbers> = new EventEmitter<Numbers>();
showPublications: boolean = true;
showDatasets: boolean = true;
showSoftware: boolean = true;
showOrp: boolean = true;
showOrganizations: boolean = true;
showProjects: boolean = true;
showDataProviders: boolean = true;
numbersLimit: number = 100;
public properties: EnvProperties = properties;
public openaireEntities = OpenaireEntities;
public routerHelper: RouterHelper = new RouterHelper();
public numbers: Numbers = {};
public loading: boolean = true;
public links: Map<Entity, Link> = new Map<Entity, Link>();
private params: Map<Entity, {}> = new Map<Entity, {}>();
private emptySubject: BehaviorSubject<number> = new BehaviorSubject<number>(0);
private subs: any[] = [];
constructor(private searchResearchResultsService: SearchResearchResultsService,
private searchDataprovidersService: SearchDataprovidersService,
private refineFieldResultsService: RefineFieldResultsService) {
this.links = new Map<Entity, Link>();
this.params = new Map<Entity, {}>();
private refineFieldResultsService: RefineFieldResultsService,
private _searchOrganizationsService: SearchOrganizationsService) {
this.emptySubject = new BehaviorSubject<number>(0);
}
@ -176,81 +81,10 @@ export class NumbersComponent implements OnInit, OnDestroy {
if (this.defaultInit) {
this.init();
}
this.setLinks();
}
setParams() {
this.params.set('publication', {type: 'publications'});
this.params.set('dataset', {type: 'datasets'});
this.params.set('software', {type: 'software'});
this.params.set('other', {type: 'other'});
this.params.set('project', {});
this.params.set('datasource', {});
if (this.refineValue) {
this.params.forEach((value) => {
value['fq'] = this.refineValue;
});
}
}
setLinks() {
this.setParams();
if (this.externalLink) {
this.links.set('publication', {
link: this.externalLink + properties.searchLinkToResults +
this.routerHelper.createQueryParamsString(Object.keys(this.params.get('publication')), HelperFunctions.getValues(this.params.get('publication')))
});
this.links.set('dataset', {
link: this.externalLink + properties.searchLinkToResults +
this.routerHelper.createQueryParamsString(Object.keys(this.params.get('dataset')), HelperFunctions.getValues(this.params.get('dataset')))
});
this.links.set('software', {
link: this.externalLink + properties.searchLinkToResults +
this.routerHelper.createQueryParamsString(Object.keys(this.params.get('software')), HelperFunctions.getValues(this.params.get('software')))
});
this.links.set('other', {
link: this.externalLink + properties.searchLinkToResults +
this.routerHelper.createQueryParamsString(Object.keys(this.params.get('other')), HelperFunctions.getValues(this.params.get('other')))
});
this.links.set('project', {
link: this.externalLink + properties.searchLinkToProjects +
this.routerHelper.createQueryParamsString(Object.keys(this.params.get('project')), HelperFunctions.getValues(this.params.get('project')))
});
this.links.set('datasource', {
link: this.externalLink + properties.searchLinkToDataProviders +
this.routerHelper.createQueryParamsString(Object.keys(this.params.get('datasource')), HelperFunctions.getValues(this.params.get('datasource')))
});
} else {
this.links.set('publication', {
link: properties.searchLinkToResults,
params: this.routerHelper.createQueryParams(Object.keys(this.params.get('publication')), HelperFunctions.getValues(this.params.get('publication')))
});
this.links.set('dataset', {
link: properties.searchLinkToResults,
params: this.routerHelper.createQueryParams(Object.keys(this.params.get('dataset')), HelperFunctions.getValues(this.params.get('dataset')))
});
this.links.set('software', {
link: properties.searchLinkToResults,
params: this.routerHelper.createQueryParams(Object.keys(this.params.get('software')), HelperFunctions.getValues(this.params.get('software')))
});
this.links.set('other', {
link: properties.searchLinkToResults,
params: this.routerHelper.createQueryParams(Object.keys(this.params.get('other')), HelperFunctions.getValues(this.params.get('other')))
});
this.links.set('project', {
link: properties.searchLinkToProjects,
params: this.routerHelper.createQueryParams(Object.keys(this.params.get('project')), HelperFunctions.getValues(this.params.get('project')))
});
this.links.set('datasource', {
link: properties.searchLinkToDataProviders,
params: this.routerHelper.createQueryParams(Object.keys(this.params.get('datasource')), HelperFunctions.getValues(this.params.get('datasource')))
});
}
}
init(getDatasetsLinked = false, getSoftwareLinked = false, getPublications = true, getDatasets = true,
getSoftware = true, getOther = true, getProjects = true, getDataProviders = true, refineValue: string = null) {
this.loading = true;
getSoftware = true, getOther = true, getProjects = true, getDataProviders = true, getOrganizations = true, refineValue: string = null) {
if (refineValue) {
this.refineValue = refineValue;
}
@ -263,7 +97,8 @@ export class NumbersComponent implements OnInit, OnDestroy {
(getSoftwareLinked) ? this.searchResearchResultsService.numOfSearchResultsLinkedToPub("software", this.properties) : this.empty,
(getOther) ? this.searchResearchResultsService.numOfSearchResults('other', '', this.properties, refineParams) : this.empty,
(getProjects) ? this.refineFieldResultsService.getRefineFieldsResultsByEntityName(['funder'], 'project', this.properties, refineParams) : this.empty,
(getDataProviders) ? this.searchDataprovidersService.numOfSearchDataproviders('', this.properties, refineParams) : this.empty
(getDataProviders) ? this.searchDataprovidersService.numOfSearchDataproviders('', this.properties, refineParams) : this.empty,
(getOrganizations) ? this._searchOrganizationsService.numOfSearchOrganizations2('', this.properties, refineParams) : this.empty
).subscribe((data: any[]) => {
if (data[0] && data[0] > 0) {
this.numbers.publicationsSize = NumberUtils.roundNumber(data[0]);
@ -292,11 +127,12 @@ export class NumbersComponent implements OnInit, OnDestroy {
if (data[7] && data[7] > 0) {
this.numbers.datasourcesSize = NumberUtils.roundNumber(data[7]);
}
this.results.emit(this.numbers);
this.loading = false;
if (data[8] && data[8] > 0) {
this.numbers.organizationsSize = NumberUtils.roundNumber(data[8]);
}
this.results.emit(this.numbers);
}, err => {
this.handleError('Error getting numbers', err);
this.loading = false;
}));
}
@ -314,5 +150,35 @@ export class NumbersComponent implements OnInit, OnDestroy {
private handleError(message: string, error) {
console.error('Numbers: ' + message, error);
}
public get showContentWithNumbers() {
if (this.numbers && (this.hasPublications || this.hasDatasets || this.hasSoftware || this.hasDatasources || this.hasProjects || this.hasOrganizations)) {
return true;
}
}
public get hasPublications() {
return this.showPublications && this.numbers.publicationsSize && this.numbers.publicationsSize.count >= this.numbersLimit;
}
public get hasDatasets() {
return this.showDatasets && this.numbers.datasetsSize && this.numbers.datasetsSize.count >= this.numbersLimit;
}
public get hasSoftware() {
return this.showSoftware && this.numbers.softwareSize && this.numbers.softwareSize.count >= this.numbersLimit;
}
public get hasDatasources() {
return this.showDataProviders && this.numbers.datasourcesSize && this.numbers.datasourcesSize.count >= this.numbersLimit;
}
public get hasProjects() {
return this.showProjects && this.numbers.projectsSize && this.numbers.projectsSize.count >= this.numbersLimit;
}
public get hasOrganizations() {
return this.showOrganizations && this.numbers.organizationsSize && this.numbers.organizationsSize.count >= this.numbersLimit;
}
}