monitor/src/app/curators/curators.component.ts

149 lines
5.4 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {CuratorService} from "../openaireLibrary/connect/curators/curator.service";
import {Curator} from "../openaireLibrary/utils/entities/CuratorInfo";
import {ActivatedRoute, Router} from "@angular/router";
import {CommunitiesService} from "../openaireLibrary/connect/communities/communities.service";
import {ConnectHelper} from "../openaireLibrary/connect/connectHelper";
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
import {Meta, Title} from "@angular/platform-browser";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
import {PiwikHelper} from "../utils/piwikHelper";
@Component({
selector: 'curators',
templateUrl: './curators.component.html'
})
export class CuratorsComponent {
@Input() managers: string[];
@Input() communityId = null;
@Input() longView = true;
public downloadUrl = null;
public showLoading = true;
public curators: Curator[];
public showMore = [];
public maxCharacters = 500;
public properties: EnvProperties;
public pageContents = null;
public divContents = null;
public piwiksub: any;
public url: string = null;
public pageTitle: string = "Curators";
constructor (private route: ActivatedRoute,
private curatorsService: CuratorService,
private communitiesService: CommunitiesService,
private _router: Router,
private helper: HelperService,
private _meta: Meta,
private _title: Title,
private seoService: SEOService,
private _piwikService: PiwikService) {}
ngOnInit() {
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
this.showLoading = true;
this.properties = data.envSpecific;
if(this.longView) {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
}
this.url = this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community");
}
this.downloadUrl = this.properties.utilsService + '/download/';
if(!this.longView) {
let emails = this.managers.join();
this.curatorsService.getCurators(this.properties,
this.properties.adminToolsAPIURL + '/curator?emails=' + emails).subscribe(curators => {
this.curators = curators;
for(let i = 0; i < this.curators.length; i++) {
this.showMore[i]= false;
}
this.showLoading = false;
HelperFunctions.scroll();
})
} else {
this.route.queryParams.subscribe(data => {
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if(!this.communityId) {
this.communityId = data['communityId'];
}
//this.getDivContents();
this.getPageContents();
this.communitiesService.getCommunities(this.properties,
this.properties.communityAPI + this.communityId).subscribe(community => {
this.managers = community[0].managers;
let emails = this.managers.join();
this.curatorsService.getCurators(this.properties,
this.properties.adminToolsAPIURL + '/curator?emails=' + emails).subscribe(curators => {
this.curators = curators;
for(let i = 0; i < this.curators.length; i++) {
this.showMore[i]= false;
}
this.showLoading = false;
HelperFunctions.scroll();
});
})
});
}
});
}
ngOnDestroy() {
if(this.piwiksub) {
this.piwiksub.unsubscribe();
}
}
private getPageContents() {
this.helper.getPageHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => {
this.pageContents = contents;
})
}
private getDivContents() {
this.helper.getDivHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => {
this.divContents = contents;
})
}
public toggle(index: number) {
this.showMore[index] = !this.showMore[index];
}
_format(name: string){
if(name) {
return (((name).length > this.maxCharacters) ? (name.substring(0, (this.maxCharacters - ('...').length)) + '...') : name);
} else {
return null;
}
}
private updateDescription(description: string) {
this._meta.updateTag({content: description}, "name='description'");
this._meta.updateTag({content: description}, "property='og:description'");
}
private updateTitle(title: string) {
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
this._title.setTitle(_title);
this._meta.updateTag({content: _title}, "property='og:title'");
}
private updateUrl(url: string) {
this._meta.updateTag({content: url}, "property='og:url'");
}
}