2018-11-23 10:52:51 +01:00
|
|
|
|
import {Component, Input, Output, EventEmitter, ViewChild, ElementRef} from '@angular/core';
|
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
|
import {Title, Meta} 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 {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo';
|
|
|
|
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'share-in-zenodo',
|
|
|
|
|
templateUrl: './shareInZenodo.component.html'
|
|
|
|
|
})
|
|
|
|
|
export class ShareInZenodoComponent {
|
|
|
|
|
properties:EnvProperties;
|
|
|
|
|
private communityId: string = null;
|
|
|
|
|
private community:CommunityInfo = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public warningMessage = "";
|
|
|
|
|
// public infoMessage = "";
|
|
|
|
|
|
|
|
|
|
masterZenodoCommunityId = null;
|
|
|
|
|
masterZenodoCommunity = null;
|
|
|
|
|
|
|
|
|
|
CommunityIds = null;
|
|
|
|
|
communities = [];
|
|
|
|
|
|
|
|
|
|
zenodocommunitiesloadedCount = 0;
|
|
|
|
|
zenodoSearchUtils:SearchUtilsClass = new SearchUtilsClass();
|
2018-11-29 12:40:38 +01:00
|
|
|
|
errorCodes: ErrorCodes = new ErrorCodes();;
|
2018-11-23 10:52:51 +01:00
|
|
|
|
depositLink = "https://zenodo.org/deposit/new?c=";
|
|
|
|
|
|
|
|
|
|
|
2019-04-15 16:08:37 +02:00
|
|
|
|
constructor (private element: ElementRef, private route: ActivatedRoute, private _router: Router,
|
2018-11-23 10:52:51 +01:00
|
|
|
|
private _meta: Meta, private _title: Title, private _ΖenodoCommunitieService: ZenodoCommunitiesService,private _communityService: CommunityService,private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService) {}
|
|
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;;
|
|
|
|
|
this.route.data
|
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
|
|
|
|
this.updateTitle("Share in Zenodo");
|
|
|
|
|
this.updateDescription("Zenodo, repository, deposit, share");
|
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
|
this.route.queryParams.subscribe(params => {
|
|
|
|
|
this.communityId = params['communityId'];
|
2019-03-01 12:34:19 +01:00
|
|
|
|
if(!this.communityId){
|
|
|
|
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.communityId) {
|
|
|
|
|
|
|
|
|
|
if (this.communityId != null && this.communityId != '') {
|
|
|
|
|
|
|
|
|
|
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
|
|
|
|
|
community => {
|
|
|
|
|
this.community = community;
|
|
|
|
|
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
2019-04-15 16:08:37 +02:00
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
|
this.element.nativeElement.scrollIntoView();
|
|
|
|
|
}
|
2018-11-23 10:52:51 +01:00
|
|
|
|
if(this.masterZenodoCommunityId){
|
|
|
|
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+this.masterZenodoCommunityId, null).subscribe(
|
|
|
|
|
result => {
|
|
|
|
|
this.masterZenodoCommunity = result;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
|
|
|
|
// emptyCommunity.id = this.masterZenodoCommunityId;
|
|
|
|
|
// emptyCommunity.title = this.masterZenodoCommunityId;
|
|
|
|
|
// this.masterZenodoCommunity = emptyCommunity;
|
2019-02-19 13:17:53 +01:00
|
|
|
|
//console.error("Master Zenodo community'"+this.masterZenodoCommunityId+"' couldn't be loaded");
|
|
|
|
|
this.handleError("Error getting Master Zenodo community with id: "+this.masterZenodoCommunityId, error);
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;;
|
|
|
|
|
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 => {
|
2019-02-19 13:17:53 +01:00
|
|
|
|
//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);
|
2018-11-23 10:52:51 +01:00
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
|
|
|
|
} //this.handleError('System error retrieving community profile', error)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error => {
|
2019-02-19 13:17:53 +01:00
|
|
|
|
//console.error("Community couldn't be loaded");
|
|
|
|
|
this.handleError("Error getting community with id: "+this.communityId, error);
|
2018-11-23 10:52:51 +01:00
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private updateDescription(description:string){
|
|
|
|
|
this._meta.updateTag({content:description},"name='description'");
|
|
|
|
|
this._meta.updateTag({content:description},"property='og:description'");
|
|
|
|
|
}
|
|
|
|
|
private updateTitle(title:string){
|
|
|
|
|
var _prefix ="OpenAIRE | ";
|
|
|
|
|
var _title = _prefix + ((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'");
|
|
|
|
|
}
|
|
|
|
|
getZenodoCommunityById(zenodoid, openaireId){
|
|
|
|
|
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;
|
|
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
|
//console.error("Zenodo community'"+zenodoid+"' couldn't be loaded");
|
|
|
|
|
this.handleError("Error getting Zenodo community with id: "+zenodoid+" and openaire id: "+openaireId, error);
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
|
console.error("Share in Zenodo Page: "+message, error);
|
|
|
|
|
}
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|