diff --git a/sharedComponents/numbers/numbers.component.ts b/sharedComponents/numbers/numbers.component.ts index dfdd07e4..b1697efa 100644 --- a/sharedComponents/numbers/numbers.component.ts +++ b/sharedComponents/numbers/numbers.component.ts @@ -6,6 +6,7 @@ import {EnvProperties} from '../../utils/properties/env-properties'; 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"; export interface Numbers { publicationsSize?: NumberSize; @@ -19,6 +20,13 @@ export interface Numbers { datasourcesSize?: NumberSize; } +type Entity = 'publication' | 'dataset' | 'software' | 'other' | 'project' | 'datasource'; + +interface Link { + link: string, + params?: any +} + @Component({ selector: 'numbers', template: ` @@ -26,8 +34,11 @@ export interface Numbers {
-

- +

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

@@ -35,8 +46,10 @@ export interface Numbers {

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

@@ -44,7 +57,10 @@ export interface Numbers {

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

@@ -57,8 +73,10 @@ export interface Numbers {
- {{numbers.publicationsSize.count|number}} + {{numbers.publicationsSize.count|number}} + {{numbers.publicationsSize.count|number}}
publications @@ -67,8 +85,10 @@ export interface Numbers {
- {{numbers.datasetsSize.count|number}} + {{numbers.datasetsSize.count|number}} + {{numbers.datasetsSize.count|number}}
research data @@ -77,8 +97,10 @@ export interface Numbers {
- {{numbers.softwareSize.count|number}} + {{numbers.softwareSize.count|number}} + {{numbers.softwareSize.count|number}}
software @@ -87,8 +109,10 @@ export interface Numbers {
- {{numbers.otherSize.count|number}} + {{numbers.otherSize.count|number}} + {{numbers.otherSize.count|number}}
other research products @@ -107,13 +131,22 @@ export interface Numbers { export class NumbersComponent implements OnInit, OnDestroy { @Input() colorClass = 'portal-color'; @Input() backgroundClass = null; - @Input() refineQuery = 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(); - private emptySubject: BehaviorSubject = new BehaviorSubject(0); public properties: EnvProperties = properties; + 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, @@ -125,20 +158,79 @@ export class NumbersComponent implements OnInit, OnDestroy { if(this.defaultInit) { this.init(); } + this.setLinks(); + } + + setParams() { + this.params.set('publication', {type: 'publications', qf: 'false'}); + this.params.set('dataset', {type: 'datasets', qf: 'false'}); + this.params.set('software', {type: 'software', qf: 'false'}); + this.params.set('other', {type: 'other', qf: 'false'}); + 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')), Object.values(this.params.get('publication')))}); + this.links.set('dataset', {link: this.externalLink + properties.searchLinkToResults + + this.routerHelper.createQueryParamsString(Object.keys(this.params.get('dataset')), Object.values(this.params.get('dataset')))}); + this.links.set('software', {link: this.externalLink + properties.searchLinkToResults + + this.routerHelper.createQueryParamsString(Object.keys(this.params.get('software')), Object.values(this.params.get('software')))}); + this.links.set('other', {link: this.externalLink + properties.searchLinkToResults + + this.routerHelper.createQueryParamsString(Object.keys(this.params.get('other')), Object.values(this.params.get('other')))}); + this.links.set('project', {link: this.externalLink + properties.searchLinkToProjects + + this.routerHelper.createQueryParamsString(Object.keys(this.params.get('project')), Object.values(this.params.get('project')))}); + this.links.set('datasource', {link: this.externalLink + properties.searchLinkToDataProviders + + this.routerHelper.createQueryParamsString(Object.keys(this.params.get('datasource')), Object.values(this.params.get('datasource')))}); + } else { + this.links.set('publication', { + link: properties.searchLinkToResults, + params: this.routerHelper.createQueryParams(Object.keys(this.params.get('publication')), Object.values(this.params.get('publication'))) + }); + this.links.set('dataset', { + link: properties.searchLinkToResults, + params: this.routerHelper.createQueryParams(Object.keys(this.params.get('dataset')), Object.values(this.params.get('dataset'))) + }); + this.links.set('software', { + link: properties.searchLinkToResults, + params: this.routerHelper.createQueryParams(Object.keys(this.params.get('software')), Object.values(this.params.get('software'))) + }); + this.links.set('other', { + link: properties.searchLinkToResults, + params: this.routerHelper.createQueryParams(Object.keys(this.params.get('other')), Object.values(this.params.get('other'))) + }); + this.links.set('project', { + link: properties.searchLinkToProjects, + params: this.routerHelper.createQueryParams(Object.keys(this.params.get('project')), Object.values(this.params.get('project'))) + }); + this.links.set('datasource', { + link: properties.searchLinkToDataProviders, + params: this.routerHelper.createQueryParams(Object.keys(this.params.get('datasource')), Object.values(this.params.get('datasource'))) + }); + } } init(getDatasetsLinked = false, getSoftwareLinked = false, getPublications = true, getDatasets = true, getSoftware = true, getOther = true, getProjects = true, getDataProviders = true) { this.loading = true; + let refineParams = (this.refineValue)?('&fq=' + this.refineValue):null; this.subs.push(zip( - (getPublications)?this.searchResearchResultsService.numOfSearchResults('publication', '', this.properties, this.refineQuery):this.empty, - (getDatasets)?this.searchResearchResultsService.numOfSearchResults('dataset', '', this.properties, this.refineQuery):this.empty, + (getPublications)?this.searchResearchResultsService.numOfSearchResults('publication', '', this.properties, refineParams):this.empty, + (getDatasets)?this.searchResearchResultsService.numOfSearchResults('dataset', '', this.properties, refineParams):this.empty, (getDatasetsLinked)?this.searchResearchResultsService.numOfSearchResultsLinkedToPub("dataset", this.properties):this.empty, - (getSoftware)?this.searchResearchResultsService.numOfSearchResults('software', '', this.properties, this.refineQuery):this.empty, + (getSoftware)?this.searchResearchResultsService.numOfSearchResults('software', '', this.properties, refineParams):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 + (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 ).subscribe((data: any[]) => { if (data[0] && data[0] > 0) { this.numbers.publicationsSize = NumberUtils.roundNumber(data[0]); diff --git a/sharedComponents/numbers/numbers.module.ts b/sharedComponents/numbers/numbers.module.ts index e88ec50d..72d30e26 100644 --- a/sharedComponents/numbers/numbers.module.ts +++ b/sharedComponents/numbers/numbers.module.ts @@ -8,9 +8,10 @@ import {SearchResearchResultsService} from '../../services/searchResearchResults import {SearchDataprovidersService} from '../../services/searchDataproviders.service'; import {RefineFieldResultsService} from '../../services/refineFieldResults.service'; import {LoadingModule} from '../../utils/loading/loading.module'; +import {RouterModule} from "@angular/router"; @NgModule({ - imports: [CommonModule, IconsModule, LoadingModule], + imports: [CommonModule, IconsModule, LoadingModule, RouterModule], declarations: [NumbersComponent], exports: [NumbersComponent], providers: [SearchResearchResultsService, SearchDataprovidersService, RefineFieldResultsService]