monitor/src/app/community/community.component.ts

368 lines
15 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Location} from '@angular/common';
import {Meta, Title} from '@angular/platform-browser';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
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 {SearchZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
import {ZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
import {Session, User} from '../openaireLibrary/login/utils/helper.class';
import {StatisticsForDashboardComponent} from '../statistics/statistics.component';
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
import {PiwikHelper} from '../utils/piwikHelper';
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
import {SearchCommunityDataprovidersService} from "../openaireLibrary/connect/contentProviders/searchDataproviders.service";
import {SearchCommunityProjectsService} from "../openaireLibrary/connect/projects/searchProjects.service";
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({
selector: 'community',
templateUrl: 'community.component.html',
})
export class CommunityComponent {
public url: string = null;
public sub: any;
public piwiksub: any;
public subfunders: any;
public publicationTotal = null;
public researchDataTotal = null;
public softwareTotal = null;
public orpTotal = null;
public projectTotal = null;
public contentProviderTotal = null;
public organizationTotal = null;
params: any = {};
properties: EnvProperties;
public publicationResults = null;
public researchDataResults = null;
public softwareResults = null;
public orpResults = null;
@Input() communityId = null;
public community = null;
public communityInfo = null;
public showLoading: boolean = true;
masterZenodoCommunity = null;
zenodoCommunityIdS = [];
showAllSubjects = false;
showAllDescription = false;
// TODO Unsubscribe
public subPublications;
public subResearchData;
public subSoftware;
public subOrps;
@ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
public activeTab = "publication";
public show: string = 'overview';
searchLinkToPublications: string = null;
searchLinkToDatasets: string = null;
searchLinkToSoftware: string = null;
searchLinkToOrps: string = null;
searchLinkToProjects: string = null;
searchLinkToDataProviders: string = null;
searchLinkToAdvancedPublications: string = null;
shareInZenodoPage: string = null;
public routerHelper:RouterHelper = new RouterHelper();
private user: User;
private loginCheck: boolean = false;
constructor(
private element: ElementRef,
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 _searchCommunityDataprovidersService:SearchCommunityDataprovidersService,
private _searchCommunityProjectsService: SearchCommunityProjectsService,
private _searchResearchResultsService: SearchResearchResultsService,
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
private seoService: SEOService,
private userManagementService: UserManagementService) {
var description = "OpenAIRE - Connect, Community Dashboard, research community";
var title = "OpenAIRE - Connect";
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;
this.searchLinkToPublications = this.properties.searchLinkToPublications;
this.searchLinkToDatasets = this.properties.searchLinkToDatasets;
this.searchLinkToSoftware = this.properties.searchLinkToSoftware;
this.searchLinkToOrps = this.properties.searchLinkToOrps;
this.searchLinkToProjects = this.properties.searchLinkToProjects;
this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
this.searchLinkToAdvancedPublications = this.properties.searchLinkToAdvancedPublications;
this.shareInZenodoPage = this.properties.shareInZenodoPage;
this.url = data.envSpecific.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url, false);
this._meta.updateTag({content: this.url}, "property='og:url'");
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.user = user;
this.loginCheck = true;
})
if (this.communityId != null && this.communityId != '') {
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {
if (typeof document !== 'undefined') {
HelperFunctions.scroll();
}
this.community = community;
if (this.properties.environment == "development") {
this.params = {communityId: community.communityId};
}
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.getSiteId(this.communityId,this.properties.environment)).subscribe();
}
if (this.community.zenodoCommunity) {
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
result => {
this.masterZenodoCommunity = result;
},
error => {
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
// emptyCommunity.id = this.masterZenodoCommunityId;
// emptyCommunity.title = this.masterZenodoCommunityId;
// this.masterZenodoCommunity = emptyCommunity;
//console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
}
);
}
this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
result => {
this.zenodoCommunityIdS = result;
},
error => {
//console.error("list of zenodo communities couldn't be loaded");
this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
} //this.handleError('System error retrieving community profile', error)
);
//console.log(community);
});
this.countResearchResults("publication");
this.countResearchResults("dataset");
this.countResearchResults("software");
this.countResearchResults("other");
this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId ).subscribe(
projectTotal => {
this.projectTotal = projectTotal;
//console.log(projectTotal);
},
error => {
this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
}
);
this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId ).subscribe(
contentProviderTotal => {
this.contentProviderTotal = contentProviderTotal;
//console.log(contentProviderTotal);
},
error => {
this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
}
);
// this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
// organizationTotal => {
// this.organizationTotal = organizationTotal;
// console.log(organizationTotal);
// });
/**/
this.config.getCommunityInformation(this.properties, this.communityId).subscribe(
res => {
this.communityInfo = res;
},
error => {
//console.log(error)
this.handleError("Error getting community with id: " + this.communityId, error);
}
);
}
});
}
public countResearchResults(resultType: string) {
this._searchResearchResultsService.countTotalResults(resultType, this.properties,"&fq=communityid=" + this.communityId).subscribe(
researchResultsTotal => {
this.setTotal(resultType, researchResultsTotal);
if(resultType == "publication") {
this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults);
}
},
error => {
this.handleError("Error getting number of "+this.getEntityName(resultType, true, true)+" for community with id: " + this.communityId, error);
}
);
}
public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
this.setActiveTab(resultType);
if (resultsTotal > 0 && results == null) {
this.showLoading = true;
this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe(
researchResults => {
this.setResults(resultType, researchResults[1]);
this.showLoading = false;
},
error => {
this.handleError("Error getting "+this.getEntityName(resultType, true, true)+" for community with id: " + this.communityId, error);
}
);
}
}
public ngOnDestroy() {
if (this.piwiksub) {
this.piwiksub.unsubscribe();
}
}
isEntityEnabled(entity: string) {
return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
}
isRouteEnabled(route: string) {
return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
}
showInvite() {
return this.loginCheck && this.isManager();
}
isManager() {
if(!this.user) {
return false;
}
var email = this.user.email;
var index = -1;
if (email && this.community != null && this.community.managers != null) {
index = this.community.managers.indexOf(email);
}
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
}
private handleError(message: string, error) {
console.error("Community (component): " + message, error);
}
getSearchPlaceHolder() {
var entities = [];
if (this.isEntityEnabled("publication")) {
entities.push("publications");
}
if (this.isEntityEnabled("dataset")) {
entities.push("research data");
}
if (this.isEntityEnabled("software")) {
entities.push("software");
}
if (this.isEntityEnabled("orp")) {
entities.push("other research products");
}
return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
}
countOtherGraphs() {
var count = 0;
if (this.statistics && this.statistics.allowedEntities) {
for (var entity of this.statistics.allowedEntities) {
if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
count += this.statistics.allowedCharts[entity].length;
}
}
}
return count;
}
createParams(param) {
return StringUtils.quote(StringUtils.URIEncode(param));
}
private setActiveTab(entityType: string) {
if(entityType == "other") {
this.activeTab = "orp";
} else {
this.activeTab = entityType;
}
}
private setResults(entityType: string, results: Array<any>) {
if(entityType == "publication") {
this.publicationResults = results;
} else if(entityType == "dataset") {
this.researchDataResults = results;
} else if(entityType == "software") {
this.softwareResults = results;
} else if(entityType == "other") {
this.orpResults = results;
}
}
private setTotal(entityType: string, total: number) {
if(entityType == "publication") {
this.publicationTotal = total;
} else if(entityType == "dataset") {
this.researchDataTotal = total;
} else if(entityType == "software") {
this.softwareTotal = total;
} else if(entityType == "other") {
this.orpTotal = total;
}
}
private getEntityName (entityType:string, plural:boolean, full:boolean): string {
if(entityType == "publication") {
return "publication" + (plural ? "s" : "");
} else if(entityType == "dataset") {
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
} else if(entityType == "software") {
return "software";
} else if(entityType == "other") {
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
}
}
}