[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 {SearchResearchResultsService} from '../../services/searchResearchResults.service';
|
||||||
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
||||||
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
||||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||||
import {properties} from '../../../../environments/environment';
|
import {properties} from '../../../../environments/environment';
|
||||||
import {NumberUtils} from '../../utils/number-utils.class';
|
import {NumberSize, NumberUtils} from '../../utils/number-utils.class';
|
||||||
import {Subscription, zip} from 'rxjs';
|
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({
|
@Component({
|
||||||
selector: 'numbers',
|
selector: 'numbers',
|
||||||
template: `
|
template: `
|
||||||
<div *ngIf="!loading">
|
<div *ngIf="!loading && numbers">
|
||||||
<div class="uk-container uk-section uk-padding-remove-bottom uk-text-center">
|
<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 class="uk-grid uk-grid-large uk-child-width-1-3@m" uk-grid>
|
||||||
<div *ngIf="fundersSize">
|
<div *ngIf="numbers.fundersSize">
|
||||||
<h3>
|
<h3>
|
||||||
<a href="https://explore.openaire.eu/search/find/projects" target="_blank" class="uk-text-bold number">
|
<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>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
<span class="uk-text-uppercase uk-text-large">Funders</span>
|
<span class="uk-text-uppercase uk-text-large">Funders</span>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="datasourcesSize">
|
<div *ngIf="numbers.datasourcesSize">
|
||||||
<h3>
|
<h3>
|
||||||
<a href="https://explore.openaire.eu/search/find/dataproviders" target="_blank"
|
<a href="https://explore.openaire.eu/search/find/dataproviders" target="_blank"
|
||||||
class="uk-text-bold number">
|
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>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
<span class="uk-text-uppercase uk-text-large">Content providers</span>
|
<span class="uk-text-uppercase uk-text-large">Content providers</span>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="projectsSize">
|
<div *ngIf="numbers.projectsSize">
|
||||||
<h3>
|
<h3>
|
||||||
<a href="https://explore.openaire.eu/search/find/projects" target="_blank" class="uk-text-bold number">
|
<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>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
<span class="uk-text-uppercase uk-text-large">Projects</span>
|
<span class="uk-text-uppercase uk-text-large">Projects</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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-container">
|
||||||
<div class="uk-grid uk-flex-center uk-margin-auto-left@m uk-margin-auto-right@m uk-grid-large" uk-grid>
|
<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 *ngIf="numbers.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 class="number-width uk-flex uk-flex-column">
|
||||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=publications&qf=false"
|
<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>
|
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">
|
<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>
|
<icon name="book" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||||
<span>publications</span>
|
<span>publications</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="datasetsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
<div *ngIf="numbers.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 class="number-width uk-flex uk-flex-column">
|
||||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=datasets&qf=false"
|
<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>
|
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">
|
<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>
|
<icon name="database" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||||
<span>research data</span>
|
<span>research data</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="softwareSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
<div *ngIf="numbers.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 class="number-width uk-flex uk-flex-column">
|
||||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=software&qf=false"
|
<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>
|
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">
|
<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>
|
<icon name="cog" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||||
<span>software</span>
|
<span>software</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="otherSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
<div *ngIf="numbers.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 class="number-width uk-flex uk-flex-column">
|
||||||
<a href="https://explore.openaire.eu/search/find/research-outcomes?type=other&qf=false"
|
<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>
|
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">
|
<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>
|
<icon name="earth" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||||
<span>other research products</span>
|
<span>other research products</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -96,14 +108,11 @@ export class NumbersComponent implements OnInit, OnDestroy {
|
||||||
@Input() colorClass = 'portal-color';
|
@Input() colorClass = 'portal-color';
|
||||||
@Input() backgroundClass = null;
|
@Input() backgroundClass = null;
|
||||||
@Input() refineQuery = 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 properties: EnvProperties = properties;
|
||||||
public publicationsSize: any = null;
|
public numbers: Numbers = {};
|
||||||
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 loading: boolean = true;
|
public loading: boolean = true;
|
||||||
private subs: any[] = [];
|
private subs: any[] = [];
|
||||||
|
|
||||||
|
@ -113,35 +122,53 @@ export class NumbersComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
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.subs.push(zip(
|
||||||
this.searchResearchResultsService.numOfSearchResults('publication', '', this.properties, this.refineQuery),
|
(getPublications)?this.searchResearchResultsService.numOfSearchResults('publication', '', this.properties, this.refineQuery):this.empty,
|
||||||
this.searchResearchResultsService.numOfSearchResults('dataset', '', this.properties, this.refineQuery),
|
(getDatasets)?this.searchResearchResultsService.numOfSearchResults('dataset', '', this.properties, this.refineQuery):this.empty,
|
||||||
this.searchResearchResultsService.numOfSearchResults('software', '', this.properties, this.refineQuery),
|
(getDatasetsLinked)?this.searchResearchResultsService.numOfSearchResultsLinkedToPub("dataset", this.properties):this.empty,
|
||||||
this.searchResearchResultsService.numOfSearchResults('other', '', this.properties, this.refineQuery),
|
(getSoftware)?this.searchResearchResultsService.numOfSearchResults('software', '', this.properties, this.refineQuery):this.empty,
|
||||||
this.refineFieldResultsService.getRefineFieldsResultsByEntityName(['funder'], 'project', this.properties, this.refineQuery),
|
(getSoftwareLinked)?this.searchResearchResultsService.numOfSearchResultsLinkedToPub("software", this.properties):this.empty,
|
||||||
this.searchDataprovidersService.numOfSearchDataproviders('', this.properties, this.refineQuery)
|
(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[]) => {
|
).subscribe((data: any[]) => {
|
||||||
|
console.log(data)
|
||||||
if (data[0] && data[0] > 0) {
|
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) {
|
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) {
|
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) {
|
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) {
|
if (data[4] && data[4] > 0) {
|
||||||
this.projectsSize = NumberUtils.roundNumber(data[4][0]);
|
this.numbers.softwareLinkedSize = NumberUtils.roundNumber(data[4]);
|
||||||
}
|
|
||||||
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[5] && data[5] > 0) {
|
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;
|
this.loading = false;
|
||||||
}, err => {
|
}, err => {
|
||||||
this.handleError('Error getting numbers', 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) {
|
private handleError(message: string, error) {
|
||||||
console.error('Numbers: ' + message, error);
|
console.error('Numbers: ' + message, error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,31 @@
|
||||||
|
export interface NumberSize {
|
||||||
|
number: number;
|
||||||
|
size: "M" | "K" | "";
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class NumberUtils{
|
export class NumberUtils{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static roundNumber(num: number):any {
|
public static roundNumber(num: number):any {
|
||||||
//console.log("Trying to round number: "+ num);
|
//console.log("Trying to round number: "+ num);
|
||||||
var roundNum = null;
|
var roundNum: NumberSize = null;
|
||||||
var initialNum = num;
|
var initialNum = num;
|
||||||
if(num >= 1000000){
|
if(num >= 1000000){
|
||||||
num=num/1000000;
|
num=num/1000000;
|
||||||
num= Math.round(num);
|
num= Math.round(num);
|
||||||
roundNum = { "number": num, "size": "M", count: initialNum};
|
roundNum = { number: num, size: "M", count: initialNum};
|
||||||
}else if( num >= 1000){
|
}else if( num >= 1000){
|
||||||
num=num/1000;
|
num=num/1000;
|
||||||
num= Math.round(num);
|
num= Math.round(num);
|
||||||
roundNum = { "number": num, "size": "K", count: initialNum};
|
roundNum = { number: num, size: "K", count: initialNum};
|
||||||
}else if (num >= 100) {
|
}else if (num >= 100) {
|
||||||
num=num/100;
|
num=num/100;
|
||||||
num= Math.round(num);
|
num= Math.round(num);
|
||||||
num=num*100;
|
num=num*100;
|
||||||
roundNum = { "number": num, "size": "" , count: initialNum};
|
roundNum = { number: num, size: "" , count: initialNum};
|
||||||
}else{
|
}else{
|
||||||
roundNum = { "number": num, "size": "" , count: initialNum};
|
roundNum = { number: num, size: "" , count: initialNum};
|
||||||
}
|
}
|
||||||
//console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
|
|
||||||
return roundNum;
|
return roundNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue