diff --git a/sharedComponents/numbers/numbers.component.ts b/sharedComponents/numbers/numbers.component.ts new file mode 100644 index 00000000..e99a1bb8 --- /dev/null +++ b/sharedComponents/numbers/numbers.component.ts @@ -0,0 +1,188 @@ +import {Component, Input, OnDestroy, OnInit} 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} from 'rxjs'; + +@Component({ + selector: 'numbers', + template: ` +
+
+
+

+ + {{fundersSize.number|number}}{{fundersSize.size}} + +

+ Funders +
+
+

+ + {{datasourcesSize.number|number}}{{datasourcesSize.size}} + +

+ Content providers +
+
+

+ + {{projectsSize.number|number}}{{projectsSize.size}} + +

+ Projects +
+
+
+
+
+
+
+
+ {{publicationsSize.count|number}} +
+ + publications +
+
+
+
+
+ {{datasetsSize.count|number}} +
+ + research data +
+
+
+
+
+ {{softwareSize.count|number}} +
+ + software +
+
+
+
+
+ {{otherSize.count|number}} +
+ + other research products +
+
+
+
+
+
`, +}) +export class NumbersComponent implements OnInit, OnDestroy { + @Input() colorClass = 'uk-text-secondary'; + @Input() backgroundClass = 'numbers-background'; + @Input() refineQuery = null; + 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; + private subs: any[] = []; + + constructor(private searchResearchResultsService: SearchResearchResultsService, + private searchDataprovidersService: SearchDataprovidersService, + private refineFieldResultsService: RefineFieldResultsService) { + } + + ngOnInit() { + this.subs.push(this.searchResearchResultsService.numOfSearchResults('publication', '', this.properties, this.refineQuery).subscribe( + data => { + if (data && data > 0) { + this.publicationsSize = NumberUtils.roundNumber(data); + } + }, + err => { + this.handleError('Error getting number of publications', err); + } + )); + this.subs.push(this.searchResearchResultsService.numOfSearchResults('dataset', '', this.properties, this.refineQuery).subscribe( + data => { + if (data && data > 0) { + this.datasetsSize = NumberUtils.roundNumber(data); + } + }, + err => { + this.handleError('Error getting number of research data', err); + } + )); + this.subs.push(this.searchResearchResultsService.numOfSearchResults('software', '', this.properties, this.refineQuery).subscribe( + data => { + if (data && data > 0) { + this.softwareSize = NumberUtils.roundNumber(data); + } + }, + err => { + this.handleError('Error getting number of software data', err); + } + )); + this.subs.push(this.searchResearchResultsService.numOfSearchResults('other', '', this.properties, this.refineQuery).subscribe( + data => { + if (data && data > 0) { + this.otherSize = NumberUtils.roundNumber(data); + } + }, + err => { + this.handleError('Error getting number of software data', err); + } + )); + this.subs.push(this.refineFieldResultsService.getRefineFieldsResultsByEntityName(['funder'], 'project', this.properties, this.refineQuery).subscribe( + data => { + if (data[0] && data[0] > 0) { + this.projectsSize = NumberUtils.roundNumber(data[0]); + } + if (data[1].length > 0 && data[1][0].filterId == 'funder' && data[1][0].values) { + this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length); + } + + }, + err => { + this.handleError('Error getting \'funder\' field results of projects', err); + }) + ); + + this.subs.push(this.searchDataprovidersService.numOfSearchDataproviders('', this.properties, this.refineQuery).subscribe( + data => { + if (data && data > 0) { + this.datasourcesSize = NumberUtils.roundNumber(data); + } + + }, + err => { + this.handleError('Error getting number of content providers', err); + } + )); + } + + ngOnDestroy() { + this.subs.forEach(sub => { + if (sub instanceof Subscription) { + sub.unsubscribe(); + } + }); + } + + private handleError(message: string, error) { + console.error("Numbers: " + message, error); + } +} diff --git a/sharedComponents/numbers/numbers.module.ts b/sharedComponents/numbers/numbers.module.ts new file mode 100644 index 00000000..f684ad7f --- /dev/null +++ b/sharedComponents/numbers/numbers.module.ts @@ -0,0 +1,21 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {NumbersComponent} from './numbers.component'; +import {IconsModule} from '../../utils/icons/icons.module'; +import {IconsService} from '../../utils/icons/icons.service'; +import {book, cog, database, earth} from '../../utils/icons/icons'; +import {SearchResearchResultsService} from '../../services/searchResearchResults.service'; +import {SearchDataprovidersService} from '../../services/searchDataproviders.service'; +import {RefineFieldResultsService} from '../../services/refineFieldResults.service'; + +@NgModule({ + imports: [CommonModule, IconsModule], + declarations: [NumbersComponent], + exports: [NumbersComponent], + providers: [SearchResearchResultsService, SearchDataprovidersService, RefineFieldResultsService] +}) +export class NumbersModule { + constructor(private iconsService: IconsService) { + this.iconsService.registerIcons([book, database, cog, earth]) + } +}