connect/src/app/community/community.component.ts

128 lines
4.9 KiB
TypeScript
Raw Normal View History

import {Component, Input, Output, EventEmitter, ViewChild, ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {ActivatedRoute, Router} from '@angular/router';
import {Location} from '@angular/common';
import "rxjs/add/observable/zip";
import { EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import { ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {Properties} from '../utils/properties';
import {CommunityService} from "./community.service";
import {CommunitiesService} from "../communities/communities.service";
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {Meta} from '../openaireLibrary/sharedComponents/metaService';
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
@Component({
selector: 'community',
templateUrl: 'community.component.html',
})
export class CommunityComponent {
public piwiksub: any;
public subfunders: any;
public pageTitle = "OpenAIRE"
public publicationTotal = null;
public researchDataTotal = null;
public softwareTotal = null;
params: any;
properties:EnvProperties;
public publicationResults = null;
public researchDataResults = null;
public softwareResults = null;
public communityId = null;
public community = null;
constructor (
private route: ActivatedRoute,
private _router: Router,
private location: Location, private _meta: Meta, private _piwikService:PiwikService,
private config: ConfigurationService,
private _communityService:CommunityService, private _communitiesService:CommunitiesService
) {
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
var title = "OpenAIRE";
this._meta.setTitle(title);
this._meta.updateMeta("description", description);
this._meta.updateProperty("og:description", description);
this._meta.updateProperty("og:title", title);
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
var url = data.envSpecific.baseLink+this._router.url
this._meta.updateProperty("og:url", url);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE").subscribe();
}
});
this.route.queryParams.subscribe(
communityId => {
this.communityId = communityId['communityId'];
});
this._communityService.getCommunity('https://dev-openaire.d4science.org/openaire/community/'+this.communityId).subscribe (
community => {
this.community = community;
this.params = {community: encodeURIComponent('"'+community.queryId+'"')};
console.log(community);
});
this._communityService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/publications/count?format=json&fq=communityid='+this.communityId).subscribe(
publicationTotal => {
this.publicationTotal = publicationTotal;
});
this._communityService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/datasets/count?format=json&fq=communityid='+this.communityId).subscribe(
researchDataTotal => {
this.researchDataTotal = researchDataTotal;
});
this._communityService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/software/count?format=json&fq=communityid='+this.communityId).subscribe(
softwareTotal => {
this.softwareTotal = softwareTotal;
});
this._communityService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/publications?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
publicationResults => {
this.publicationResults = publicationResults;
});
this._communityService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/datasets?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
researchDataResults => {
this.researchDataResults = researchDataResults;
});
this._communityService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/software?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
softwareResults => {
this.softwareResults = softwareResults;
});
}
public ngOnDestroy() {
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
}