From a2fea9e32331de06ab2192e3e638662531b9f42f Mon Sep 17 00:00:00 2001 From: Alex Martzios Date: Tue, 8 Nov 2022 14:09:03 +0200 Subject: [PATCH] refactor numbersComponent file --- sharedComponents/numbers/numbers.component.ts | 270 +++++------------- 1 file changed, 68 insertions(+), 202 deletions(-) diff --git a/sharedComponents/numbers/numbers.component.ts b/sharedComponents/numbers/numbers.component.ts index c80d116a..cb163c7d 100644 --- a/sharedComponents/numbers/numbers.component.ts +++ b/sharedComponents/numbers/numbers.component.ts @@ -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: ` -
- -
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
- -
+
+
+ A comprehensive and open dataset of research information covering + {{numbers.publicationsSize.number|number}}{{numbers.publicationsSize.size}} {{openaireEntities.PUBLICATIONS.toLowerCase()}} + , + {{numbers.datasetsSize.number|number}}{{numbers.datasetsSize.size}} {{openaireEntities.DATASETS.toLowerCase()}} + , + {{numbers.softwareSize.number|number}}{{numbers.softwareSize.size}} {{openaireEntities.SOFTWARE.toLowerCase()}} items + , + from + {{numbers.datasourcesSize.number|number}}{{numbers.datasourcesSize.size}} {{openaireEntities.DATASOURCES.toLowerCase()}} + , linked to + {{numbers.projectsSize.number|number}}{{numbers.projectsSize.size}} grants + and + {{numbers.organizationsSize.number|number}}{{numbers.organizationsSize.size}} {{openaireEntities.ORGANIZATIONS.toLowerCase()}}. +
+
All linked together through citations and semantics.
+
`, }) 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 = new EventEmitter(); + @Output() results: EventEmitter = new EventEmitter(); + + 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 = new Map(); - private params: Map = new Map(); private emptySubject: BehaviorSubject = new BehaviorSubject(0); private subs: any[] = []; constructor(private searchResearchResultsService: SearchResearchResultsService, private searchDataprovidersService: SearchDataprovidersService, - private refineFieldResultsService: RefineFieldResultsService) { - this.links = new Map(); - this.params = new Map(); + private refineFieldResultsService: RefineFieldResultsService, + private _searchOrganizationsService: SearchOrganizationsService) { this.emptySubject = new BehaviorSubject(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; } }