import {Component, Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Meta, Title} from '@angular/platform-browser'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service'; import {SearchZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service'; import {CommunityService} from '../../openaireLibrary/connect/community/community.service'; import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper'; import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo'; import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class'; import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes'; import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class"; import {HelperService} from "../../openaireLibrary/utils/helper/helper.service"; import {RouterHelper} from "../../openaireLibrary/utils/routerHelper.class"; import {SEOService} from "../../openaireLibrary/sharedComponents/SEO/SEO.service"; import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service"; import {PiwikHelper} from "../../utils/piwikHelper"; import {Breadcrumb} from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component"; import {properties} from "../../../environments/environment"; import {Subscription} from "rxjs"; @Component({ selector: 'share-in-zenodo', templateUrl: './shareInZenodo.component.html' }) export class ShareInZenodoComponent { public url: string = null; public title: string = "Share in Zenodo"; public piwikSiteId = null; properties: EnvProperties; communityId: string = null; private community: CommunityInfo = null; public pageContents = null; public divContents = null; // public warningMessage = ""; // public infoMessage = ""; masterZenodoCommunityId = null; masterZenodoCommunity = null; CommunityIds = null; communities = []; zenodocommunitiesloadedCount = 0; zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass(); errorCodes: ErrorCodes = new ErrorCodes(); depositLink = "https://zenodo.org/deposit/new?c="; depositLearnHowPage: string = null; public routerHelper:RouterHelper = new RouterHelper(); breadcrumbs:Breadcrumb[] = []; subs: Subscription[] = []; constructor(private route: ActivatedRoute, private _router: Router, private _meta: Meta, private _title: Title, private _ΖenodoCommunitieService: ZenodoCommunitiesService, private _communityService: CommunityService, private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService, private helper: HelperService, private _piwikService:PiwikService, private seoService: SEOService) { } public ngOnInit() { this.zenodoSearchUtils.status = this.errorCodes.LOADING; this.url = properties.domain + properties.baseLink + this._router.url; this.seoService.createLinkForCanonicalURL(this.url, false); this.updateUrl(this.url); this.updateTitle(this.title); this.updateDescription("Zenodo, repository, deposit, share"); this.properties = properties; this.subs.push(this.route.queryParams.subscribe(params => { this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); if (!this.communityId) { this.communityId = params['communityId']; } this.piwikSiteId = PiwikHelper.getSiteId(this.communityId,this.properties.environment); if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ this.subs.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe()); } this.depositLearnHowPage = this.properties.depositLearnHowPage; this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: this.depositLearnHowPage},{name:"Deposit in zenodo",route:null}); //this.getDivContents(); this.getPageContents(); if (this.communityId && this.communityId != '') { this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI + this.communityId).subscribe( community => { this.community = community; this.masterZenodoCommunityId = this.community.zenodoCommunity; if (typeof document !== 'undefined') { HelperFunctions.scroll(); } if (this.masterZenodoCommunityId) { this.subs.push(this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.masterZenodoCommunityId, null).subscribe( result => { this.masterZenodoCommunity = result; }, error => { this.handleError("Error getting Master Zenodo community with id: " + this.masterZenodoCommunityId, error); } )); } this.zenodoSearchUtils.status = this.errorCodes.LOADING; this.subs.push(this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe( result => { this.CommunityIds = result; this.zenodoSearchUtils.totalResults = this.CommunityIds.length; if (this.CommunityIds.length == 0) { this.zenodoSearchUtils.status = this.errorCodes.NONE; } for (let i = 0; i < this.CommunityIds.length; i++) { this.getZenodoCommunityById(this.CommunityIds[i]["zenodoid"], this.CommunityIds[i]["id"]); } }, 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.zenodoSearchUtils.status = this.errorCodes.ERROR; } //this.handleError('System error retrieving community profile', error) )); }, error => { //console.error("Community couldn't be loaded"); this.handleError("Error getting community with id: " + this.communityId, error); this.zenodoSearchUtils.status = this.errorCodes.ERROR; } )); } })); } public ngOnDestroy() { for (let sub of this.subs) { sub.unsubscribe(); } } 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'"); } private getPageContents() { this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => { this.pageContents = contents; })); } private getDivContents() { this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => { this.divContents = contents; })); } getZenodoCommunityById(zenodoid, openaireId) { this.subs.push(this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + zenodoid, openaireId).subscribe( result => { this.communities.push(result); this.zenodocommunitiesloadedCount++; if (this.zenodocommunitiesloadedCount >= this.CommunityIds.length) { this.zenodoSearchUtils.status = this.errorCodes.DONE; } }, error => { // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo(); // emptyCommunity.id = zenodoid; // emptyCommunity.openaireId = openaireId; // emptyCommunity.title = zenodoid; // this.communities.push(emptyCommunity); this.zenodocommunitiesloadedCount++; if (this.zenodocommunitiesloadedCount >= this.CommunityIds.length) { this.zenodoSearchUtils.status = this.errorCodes.DONE; } //console.error("Zenodo community'"+zenodoid+"' couldn't be loaded"); this.handleError("Error getting Zenodo community with id: " + zenodoid + " and openaire id: " + openaireId, error); } )); } private handleError(message: string, error) { console.error("Share in Zenodo Page: " + message, error); } }