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

172 lines
8.0 KiB
TypeScript
Raw Normal View History

import {Component, Input, Output} from '@angular/core';
import {EventEmitter, ViewChild} from '@angular/core';
import {ChangeDetectionStrategy} from '@angular/core';
import {ViewEncapsulation} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Location} from '@angular/common';
import {Title, Meta} from '@angular/platform-browser';
import {Observable} from 'rxjs/Observable';
import "rxjs/add/observable/zip";
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {CommunityService} from "../openaireLibrary/connect/community/community.service";
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {SearchEntriesService} from '../searchEntries/searchEntries.service';
import {PiwikHelper} from '../utils/piwikHelper';
@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;
public projectTotal = null;
public contentProviderTotal = null;
public organizationTotal = null;
params: any;
properties:EnvProperties;
public publicationResults = null;
public researchDataResults = null;
public softwareResults = null;
@Input() communityId = null;
public community = null;
constructor (
private route: ActivatedRoute,
private _router: Router,
private location: Location,
private _meta: Meta,
private _title: Title,
private _piwikService:PiwikService,
private config: ConfigurationService,
private _communityService:CommunityService,
private _searchEntriesService:SearchEntriesService) {
var description = "Community Dashboard";
var title = "Community Dashboard";
this._meta.updateTag({content:description},"name='description'");
this._meta.updateTag({content:description},"property='og:description'");
this._meta.updateTag({content:title},"property='og:title'");
this._title.setTitle(title);
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
var url = data.envSpecific.baseLink+this._router.url;
this._meta.updateTag({content:url},"property='og:url'");
// this.route.queryParams.subscribe(
// communityId => {
// this.communityId = communityId['communityId'];
// if(!this.communityId){
// this.communityId = this.route.snapshot.paramMap.get('id');
// }
// });
if (this.communityId != null && this.communityId != '') {
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
community => {
this.community = community;
this.params = {community: encodeURIComponent('"'+community.queryId+'"')};
this._meta.updateTag({content:community.description},"name='description'");
this._meta.updateTag({content:community.description},"property='og:description'");
this._meta.updateTag({content:community.title},"property='og:title'");
this._title.setTitle(community.title);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.piwiksub = this._piwikService.trackView(this.properties, community.title,PiwikHelper.siteIDs[this.communityId]).subscribe();
}
//console.log(community);
});
// 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._searchEntriesService.getTotal(this.properties.searchAPIURLLAst+'publications/count?format=json&fq=communityid='+this.communityId).subscribe(
publicationTotal => {
this.publicationTotal = publicationTotal;
if (this.publicationTotal > 0) {
this._searchEntriesService.getResults(this.properties.searchAPIURLLAst+'publications?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
publicationResults => {
this.publicationResults = publicationResults;
//console.log(publicationResults);
});
}
});
this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst+'datasets/count?format=json&fq=communityid='+this.communityId).subscribe(
researchDataTotal => {
this.researchDataTotal = researchDataTotal;
if (this.researchDataTotal > 0) {
this._searchEntriesService.getResults(this.properties.searchAPIURLLAst+'datasets?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
researchDataResults => {
this.researchDataResults = researchDataResults;
});
}
});
this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst+'software/count?format=json&fq=communityid='+this.communityId).subscribe(
softwareTotal => {
this.softwareTotal = softwareTotal;
if (this.softwareTotal > 0) {
this._searchEntriesService.getResults(this.properties.searchAPIURLLAst+'software?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
softwareResults => {
this.softwareResults = softwareResults;
});
}
});
this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/projects').subscribe(
projectTotal => {
this.projectTotal = projectTotal;
//console.log(projectTotal);
});
this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/contentproviders').subscribe(
contentProviderTotal => {
this.contentProviderTotal = contentProviderTotal;
//console.log(contentProviderTotal);
});
// this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
// organizationTotal => {
// this.organizationTotal = organizationTotal;
// console.log(organizationTotal);
// });
}
});
}
public ngOnDestroy() {
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
}