[Library | Trunk]: Numbers: Add init function. Create numberSize interface
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60895 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
4dda29f37a
commit
3d896b8c9e
|
@ -1,83 +1,95 @@
|
|||
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
|
||||
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
|
||||
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
||||
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||
import {properties} from '../../../../environments/environment';
|
||||
import {NumberUtils} from '../../utils/number-utils.class';
|
||||
import {Subscription, zip} from 'rxjs';
|
||||
import {NumberSize, NumberUtils} from '../../utils/number-utils.class';
|
||||
import {BehaviorSubject, Observable, Subscription, zip} from 'rxjs';
|
||||
|
||||
export interface Numbers {
|
||||
publicationsSize?: NumberSize;
|
||||
datasetsSize?: NumberSize;
|
||||
datasetsLinkedSize?: NumberSize;
|
||||
softwareLinkedSize?: NumberSize;
|
||||
softwareSize?: NumberSize;
|
||||
otherSize?: NumberSize;
|
||||
fundersSize?: NumberSize;
|
||||
projectsSize?: NumberSize;
|
||||
datasourcesSize?: NumberSize;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'numbers',
|
||||
template: `
|
||||
<div *ngIf="!loading">
|
||||
<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="fundersSize">
|
||||
<div *ngIf="numbers.fundersSize">
|
||||
<h3>
|
||||
<a href="https://explore.openaire.eu/search/find/projects" target="_blank" class="uk-text-bold number">
|
||||
{{fundersSize.number|number}}<span class="number-size">{{fundersSize.size}}</span>
|
||||
{{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="datasourcesSize">
|
||||
<div *ngIf="numbers.datasourcesSize">
|
||||
<h3>
|
||||
<a href="https://explore.openaire.eu/search/find/dataproviders" target="_blank"
|
||||
class="uk-text-bold number">
|
||||
{{datasourcesSize.number|number}}<span class="number-size">{{datasourcesSize.size}}</span>
|
||||
{{numbers.datasourcesSize.number|number}}<span class="number-size">{{numbers.datasourcesSize.size}}</span>
|
||||
</a>
|
||||
</h3>
|
||||
<span class="uk-text-uppercase uk-text-large">Content providers</span>
|
||||
</div>
|
||||
<div *ngIf="projectsSize">
|
||||
<div *ngIf="numbers.projectsSize">
|
||||
<h3>
|
||||
<a href="https://explore.openaire.eu/search/find/projects" target="_blank" class="uk-text-bold number">
|
||||
{{projectsSize.number|number}}<span class="number-size">{{projectsSize.size}}</span>
|
||||
{{numbers.projectsSize.number|number}}<span class="number-size">{{numbers.projectsSize.size}}</span>
|
||||
</a>
|
||||
</h3>
|
||||
<span class="uk-text-uppercase uk-text-large">Projects</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-section" [ngClass]="backgroundClass">
|
||||
<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="publicationsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-wrap uk-flex-center uk-flex-left@m">
|
||||
<div *ngIf="numbers.publicationsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-column">
|
||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=publications&qf=false"
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom">{{publicationsSize.count|number}} </a>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m">{{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>publications</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="datasetsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-wrap uk-flex-center uk-flex-left@m">
|
||||
<div *ngIf="numbers.datasetsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-column">
|
||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=datasets&qf=false"
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom">{{datasetsSize.count|number}} </a>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m">{{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>research data</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="softwareSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-wrap uk-flex-center uk-flex-left@m">
|
||||
<div *ngIf="numbers.softwareSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-column">
|
||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=software&qf=false"
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom">{{softwareSize.count|number}} </a>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m">{{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>software</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="otherSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-wrap uk-flex-center uk-flex-left@m">
|
||||
<div *ngIf="numbers.otherSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width uk-flex uk-flex-column">
|
||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=other&qf=false"
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom">{{otherSize.count|number}} </a>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
target="_blank" class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m">{{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>other research products</span>
|
||||
</div>
|
||||
|
@ -96,14 +108,11 @@ export class NumbersComponent implements OnInit, OnDestroy {
|
|||
@Input() colorClass = 'portal-color';
|
||||
@Input() backgroundClass = null;
|
||||
@Input() refineQuery = null;
|
||||
@Input() defaultInit = true;
|
||||
@Output() results: EventEmitter<Numbers> = new EventEmitter<Numbers>();
|
||||
private emptySubject: BehaviorSubject<number> = new BehaviorSubject<number>(0);
|
||||
public properties: EnvProperties = properties;
|
||||
public publicationsSize: any = null;
|
||||
public datasetsSize: any = null;
|
||||
public softwareSize: any = null;
|
||||
public otherSize: any = null;
|
||||
public fundersSize: any = null;
|
||||
public projectsSize: any = null;
|
||||
public datasourcesSize: any = null;
|
||||
public numbers: Numbers = {};
|
||||
public loading: boolean = true;
|
||||
private subs: any[] = [];
|
||||
|
||||
|
@ -113,35 +122,53 @@ export class NumbersComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
if(this.defaultInit) {
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
|
||||
init(getDatasetsLinked = false, getSoftwareLinked = false, getPublications = true, getDatasets = true,
|
||||
getSoftware = true, getOther = true, getProjects = true, getDataProviders = true) {
|
||||
this.loading = true;
|
||||
this.subs.push(zip(
|
||||
this.searchResearchResultsService.numOfSearchResults('publication', '', this.properties, this.refineQuery),
|
||||
this.searchResearchResultsService.numOfSearchResults('dataset', '', this.properties, this.refineQuery),
|
||||
this.searchResearchResultsService.numOfSearchResults('software', '', this.properties, this.refineQuery),
|
||||
this.searchResearchResultsService.numOfSearchResults('other', '', this.properties, this.refineQuery),
|
||||
this.refineFieldResultsService.getRefineFieldsResultsByEntityName(['funder'], 'project', this.properties, this.refineQuery),
|
||||
this.searchDataprovidersService.numOfSearchDataproviders('', this.properties, this.refineQuery)
|
||||
(getPublications)?this.searchResearchResultsService.numOfSearchResults('publication', '', this.properties, this.refineQuery):this.empty,
|
||||
(getDatasets)?this.searchResearchResultsService.numOfSearchResults('dataset', '', this.properties, this.refineQuery):this.empty,
|
||||
(getDatasetsLinked)?this.searchResearchResultsService.numOfSearchResultsLinkedToPub("dataset", this.properties):this.empty,
|
||||
(getSoftware)?this.searchResearchResultsService.numOfSearchResults('software', '', this.properties, this.refineQuery):this.empty,
|
||||
(getSoftwareLinked)?this.searchResearchResultsService.numOfSearchResultsLinkedToPub("software", this.properties):this.empty,
|
||||
(getOther)?this.searchResearchResultsService.numOfSearchResults('other', '', this.properties, this.refineQuery):this.empty,
|
||||
(getProjects)?this.refineFieldResultsService.getRefineFieldsResultsByEntityName(['funder'], 'project', this.properties, this.refineQuery):this.empty,
|
||||
(getDataProviders)?this.searchDataprovidersService.numOfSearchDataproviders('', this.properties, this.refineQuery):this.empty
|
||||
).subscribe((data: any[]) => {
|
||||
console.log(data)
|
||||
if (data[0] && data[0] > 0) {
|
||||
this.publicationsSize = NumberUtils.roundNumber(data[0]);
|
||||
this.numbers.publicationsSize = NumberUtils.roundNumber(data[0]);
|
||||
}
|
||||
if (data[1] && data[1] > 0) {
|
||||
this.datasetsSize = NumberUtils.roundNumber(data[1]);
|
||||
this.numbers.datasetsSize = NumberUtils.roundNumber(data[1]);
|
||||
}
|
||||
if (data[2] && data[2] > 0) {
|
||||
this.softwareSize = NumberUtils.roundNumber(data[2]);
|
||||
this.numbers.datasetsLinkedSize = NumberUtils.roundNumber(data[2]);
|
||||
}
|
||||
if (data[3] && data[3] > 0) {
|
||||
this.otherSize = NumberUtils.roundNumber(data[3]);
|
||||
this.numbers.softwareSize = NumberUtils.roundNumber(data[3]);
|
||||
}
|
||||
if (data[4][0] && data[4][0] > 0) {
|
||||
this.projectsSize = NumberUtils.roundNumber(data[4][0]);
|
||||
}
|
||||
if (data[4][1] && data[4][1].length > 0 && data[4][1][0].filterId == 'funder' && data[4][1][0].values) {
|
||||
this.fundersSize = NumberUtils.roundNumber(data[4][1][0].values.length);
|
||||
if (data[4] && data[4] > 0) {
|
||||
this.numbers.softwareLinkedSize = NumberUtils.roundNumber(data[4]);
|
||||
}
|
||||
if (data[5] && data[5] > 0) {
|
||||
this.datasourcesSize = NumberUtils.roundNumber(data[5]);
|
||||
this.numbers.otherSize = NumberUtils.roundNumber(data[5]);
|
||||
}
|
||||
if (data[6][0] && data[6][0] > 0) {
|
||||
this.numbers.projectsSize = NumberUtils.roundNumber(data[6][0]);
|
||||
}
|
||||
if (data[6][1] && data[6][1].length > 0 && data[6][1][0].filterId == 'funder' && data[6][1][0].values) {
|
||||
this.numbers.fundersSize = NumberUtils.roundNumber(data[6][1][0].values.length);
|
||||
}
|
||||
if (data[7] && data[7] > 0) {
|
||||
this.numbers.datasourcesSize = NumberUtils.roundNumber(data[7]);
|
||||
}
|
||||
this.results.emit(this.numbers);
|
||||
this.loading = false;
|
||||
}, err => {
|
||||
this.handleError('Error getting numbers', err);
|
||||
|
@ -157,6 +184,10 @@ export class NumbersComponent implements OnInit, OnDestroy {
|
|||
});
|
||||
}
|
||||
|
||||
get empty(): Observable<number> {
|
||||
return this.emptySubject.asObservable();
|
||||
}
|
||||
|
||||
private handleError(message: string, error) {
|
||||
console.error('Numbers: ' + message, error);
|
||||
}
|
||||
|
|
|
@ -1,29 +1,31 @@
|
|||
export interface NumberSize {
|
||||
number: number;
|
||||
size: "M" | "K" | "";
|
||||
count: number;
|
||||
}
|
||||
|
||||
export class NumberUtils{
|
||||
|
||||
|
||||
|
||||
|
||||
public static roundNumber(num: number):any {
|
||||
//console.log("Trying to round number: "+ num);
|
||||
var roundNum = null;
|
||||
var roundNum: NumberSize = null;
|
||||
var initialNum = num;
|
||||
if(num >= 1000000){
|
||||
num=num/1000000;
|
||||
num= Math.round(num);
|
||||
roundNum = { "number": num, "size": "M", count: initialNum};
|
||||
roundNum = { number: num, size: "M", count: initialNum};
|
||||
}else if( num >= 1000){
|
||||
num=num/1000;
|
||||
num= Math.round(num);
|
||||
roundNum = { "number": num, "size": "K", count: initialNum};
|
||||
roundNum = { number: num, size: "K", count: initialNum};
|
||||
}else if (num >= 100) {
|
||||
num=num/100;
|
||||
num= Math.round(num);
|
||||
num=num*100;
|
||||
roundNum = { "number": num, "size": "" , count: initialNum};
|
||||
roundNum = { number: num, size: "" , count: initialNum};
|
||||
}else{
|
||||
roundNum = { "number": num, "size": "" , count: initialNum};
|
||||
roundNum = { number: num, size: "" , count: initialNum};
|
||||
}
|
||||
//console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
|
||||
return roundNum;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue