+ target="_blank" class="number uk-text-bold uk-margin-bottom uk-text-center uk-text-left@m">{{numbers.otherSize.count|number}}
+
other research products
@@ -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
= new EventEmitter();
+ private emptySubject: BehaviorSubject = new BehaviorSubject(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 {
+ return this.emptySubject.asObservable();
+ }
+
private handleError(message: string, error) {
console.error('Numbers: ' + message, error);
}
diff --git a/utils/number-utils.class.ts b/utils/number-utils.class.ts
index fc3d6e93..4fc2964f 100644
--- a/utils/number-utils.class.ts
+++ b/utils/number-utils.class.ts
@@ -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;
}