[Library | Trunk]: Create numbers component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60867 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
b78a463c5e
commit
dc9d1f3455
|
@ -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: `
|
||||
<div class="uk-margin-large-top uk-container uk-margin-bottom uk-text-center">
|
||||
<div class="uk-grid uk-grid-large uk-child-width-1-3@m" uk-grid>
|
||||
<div *ngIf="fundersSize">
|
||||
<h3>
|
||||
<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>
|
||||
</a>
|
||||
</h3>
|
||||
<span class="uk-text-uppercase uk-text-large">Funders</span>
|
||||
</div>
|
||||
<div *ngIf="datasourcesSize">
|
||||
<h3>
|
||||
<a href="https://explore.openaire.eu/search/find/dataproviders" target="_blank"
|
||||
class="uk-text-bold number">
|
||||
{{datasourcesSize.number|number}}<span class="number-size">{{datasourcesSize.size}}</span>
|
||||
</a>
|
||||
</h3>
|
||||
<span class="uk-text-uppercase uk-text-large">Content providers</span>
|
||||
</div>
|
||||
<div *ngIf="projectsSize">
|
||||
<h3>
|
||||
<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>
|
||||
</a>
|
||||
</h3>
|
||||
<span class="uk-text-uppercase uk-text-large">Projects</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-section" [ngClass]="backgroundClass">
|
||||
<div class="uk-container">
|
||||
<div class="uk-grid uk-margin-auto-left uk-margin-auto-right uk-grid-large" uk-grid>
|
||||
<div *ngIf="publicationsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width">
|
||||
<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>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
<icon name="book" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||
<span>publications</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="datasetsSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width">
|
||||
<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>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
<icon name="database" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||
<span>research data</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="softwareSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width">
|
||||
<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>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
<icon name="cog" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||
<span>software</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="otherSize" class="uk-width-1-2@m uk-flex uk-flex-center">
|
||||
<div class="number-width">
|
||||
<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>
|
||||
<div class="uk-text-uppercase uk-flex uk-flex-middle">
|
||||
<icon name="earth" ratio="1.5" [flex]="true" class="uk-margin-right" [customClass]="colorClass"></icon>
|
||||
<span>other research products</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`,
|
||||
})
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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])
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue