92 lines
3.5 KiB
TypeScript
92 lines
3.5 KiB
TypeScript
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';
|
|
import {Subscriber, Subscription} from "rxjs";
|
|
import {properties} from "../../environments/environment";
|
|
|
|
@Component({
|
|
selector: 'openaire-search-deposit',
|
|
template: `
|
|
<deposit-search-dataproviders [piwikSiteId]=piwikSiteId [zenodoInformation]="zenodoInformation" [communityId]="communityId"></deposit-search-dataproviders>
|
|
`
|
|
})
|
|
|
|
export class OpenaireSearchDataprovidersToDepositComponent {
|
|
public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
|
|
properties:EnvProperties;
|
|
fetchZenodoInformation: FetchZenodoInformation;
|
|
|
|
piwikSiteId = null;
|
|
communityId: string = null;
|
|
|
|
subs: Subscription[] = [];
|
|
|
|
constructor ( private route: ActivatedRoute,
|
|
private _zenodoCommunitieService: ZenodoCommunitiesService,
|
|
private _communityService: CommunityService,private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService ) {
|
|
this.fetchZenodoInformation = new FetchZenodoInformation(this._zenodoCommunitieService, this._searchZenodoCommunitiesService);
|
|
}
|
|
|
|
public ngOnInit() {
|
|
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.communityId) {
|
|
|
|
if (this.communityId != '') {
|
|
|
|
this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI+this.communityId).subscribe (
|
|
community => {
|
|
let masterZenodoCommunityId = community.zenodoCommunity;
|
|
if (masterZenodoCommunityId) {
|
|
this.zenodoInformation.shareInZenodoUrl = this.properties.shareInZenodoPage;
|
|
} else {
|
|
this.zenodoInformation.url = this.properties.zenodo;
|
|
this.zenodoInformation.name = "Zenodo";
|
|
} },
|
|
error => {
|
|
this.handleError("Error getting community with id: "+this.communityId, error);
|
|
}
|
|
));
|
|
}
|
|
}
|
|
|
|
if (!this.zenodoInformation.shareInZenodoUrl) {
|
|
this.zenodoInformation.url = this.properties.zenodo;
|
|
}
|
|
if (!this.zenodoInformation.name) {
|
|
this.zenodoInformation.name = "Zenodo";
|
|
}
|
|
}));
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
for (let sub of this.subs) {
|
|
if(sub instanceof Subscriber) {
|
|
sub.unsubscribe();
|
|
}
|
|
}
|
|
this.fetchZenodoInformation.clearSubscriptions();
|
|
}
|
|
|
|
private handleError(message: string, error) {
|
|
console.error("Deposit Publications Page: "+message, error);
|
|
}
|
|
}
|