connect/src/app/deposit/searchDataprovidersToDeposi...

82 lines
3.3 KiB
TypeScript
Raw Normal View History

import {Component, Input} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {PiwikHelper} from '../utils/piwikHelper';
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
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 {ZenodoInformationClass} from '../openaireLibrary/deposit/utils/zenodoInformation.class';
import {FetchZenodoInformation} from './utils/fetchZenodoInformation.class';
@Component({
selector: 'openaire-search-deposit',
template: `
<search-dataproviders [piwikSiteId]=piwikSiteId [zenodoInformation]="zenodoInformation"></search-dataproviders>
`
})
export class OpenaireSearchDataprovidersToDepositComponent {
public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
properties:EnvProperties;
fetchZenodoInformation: FetchZenodoInformation;
piwikSiteId = null;
constructor ( private route: ActivatedRoute,
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
private _communityService: CommunityService,private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService ) {
this.fetchZenodoInformation = new FetchZenodoInformation(this._ΖenodoCommunitieService, this._searchZenodoCommunitiesService);
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.route.queryParams.subscribe(params => {
let communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if(!communityId) {
communityId = params['communityId'];
}
this.piwikSiteId = PiwikHelper.siteIDs[communityId];
if(communityId) {
if (communityId != null && communityId != '') {
this._communityService.getCommunity(this.properties, this.properties.communityAPI+communityId).subscribe (
community => {
var community = community;
var masterZenodoCommunityId = community.zenodoCommunity;
if (masterZenodoCommunityId) {
this.zenodoInformation.shareInZenodoUrl = this.properties.shareInZenodoPage+communityId;
} else {
this.zenodoInformation.url = this.properties.zenodo;
this.zenodoInformation.name = "Zenodo";
} },
error => {
this.handleError("Error getting community with id: "+communityId, error);
}
);
}
}
if (!this.zenodoInformation.shareInZenodoUrl) {
this.zenodoInformation.url = this.properties.zenodo;
}
if (!this.zenodoInformation.name) {
this.zenodoInformation.name = "Zenodo";
}
});
});
}
private handleError(message: string, error) {
console.error("Deposit Publications Page: "+message, error);
}
}