2019-04-24 14:02:11 +02:00
|
|
|
|
import {Component} from '@angular/core';
|
2018-11-23 10:52:51 +01:00
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2019-04-24 14:02:11 +02:00
|
|
|
|
import {Meta, Title} from '@angular/platform-browser';
|
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
2018-11-23 10:52:51 +01:00
|
|
|
|
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';
|
2019-04-24 14:02:11 +02:00
|
|
|
|
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
2019-07-22 12:08:25 +02:00
|
|
|
|
import {HelperService} from "../../openaireLibrary/utils/helper/helper.service";
|
2019-07-31 12:42:45 +02:00
|
|
|
|
import {RouterHelper} from "../../openaireLibrary/utils/routerHelper.class";
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
2019-04-24 14:02:11 +02:00
|
|
|
|
selector: 'share-in-zenodo',
|
|
|
|
|
templateUrl: './shareInZenodo.component.html'
|
2018-11-23 10:52:51 +01:00
|
|
|
|
})
|
|
|
|
|
export class ShareInZenodoComponent {
|
2019-04-24 14:02:11 +02:00
|
|
|
|
properties: EnvProperties;
|
|
|
|
|
private communityId: string = null;
|
|
|
|
|
private community: CommunityInfo = null;
|
2019-07-22 12:08:25 +02:00
|
|
|
|
public pageContents = null;
|
|
|
|
|
public divContents = null;
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
|
|
|
|
|
2019-04-24 14:02:11 +02:00
|
|
|
|
// public warningMessage = "";
|
|
|
|
|
// public infoMessage = "";
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
2019-04-24 14:02:11 +02:00
|
|
|
|
masterZenodoCommunityId = null;
|
|
|
|
|
masterZenodoCommunity = null;
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
2019-04-24 14:02:11 +02:00
|
|
|
|
CommunityIds = null;
|
|
|
|
|
communities = [];
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
2019-04-24 14:02:11 +02:00
|
|
|
|
zenodocommunitiesloadedCount = 0;
|
|
|
|
|
zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
|
errorCodes: ErrorCodes = new ErrorCodes();
|
|
|
|
|
depositLink = "https://zenodo.org/deposit/new?c=";
|
2019-07-31 12:42:45 +02:00
|
|
|
|
depositLearnHowPage: string = null;
|
|
|
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
2019-07-22 12:08:25 +02:00
|
|
|
|
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) {
|
2019-04-24 14:02:11 +02:00
|
|
|
|
}
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2019-04-24 14:02:11 +02:00
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
;
|
2018-11-23 10:52:51 +01:00
|
|
|
|
this.route.data
|
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
2019-04-24 14:02:11 +02:00
|
|
|
|
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 => {
|
2019-07-22 12:08:25 +02:00
|
|
|
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
|
|
|
|
if (!this.communityId) {
|
2019-07-03 12:16:58 +02:00
|
|
|
|
this.communityId = params['communityId'];
|
2019-04-24 14:02:11 +02:00
|
|
|
|
}
|
2019-07-31 12:42:45 +02:00
|
|
|
|
this.depositLearnHowPage = this.properties.depositLearnHowPage;
|
2019-07-22 12:08:25 +02:00
|
|
|
|
//this.getDivContents();
|
|
|
|
|
this.getPageContents();
|
2019-04-24 14:02:11 +02: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;
|
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
|
}
|
|
|
|
|
if (this.masterZenodoCommunityId) {
|
|
|
|
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.masterZenodoCommunityId, null).subscribe(
|
|
|
|
|
result => {
|
|
|
|
|
this.masterZenodoCommunity = result;
|
|
|
|
|
|
|
|
|
|
},
|
2018-11-23 10:52:51 +01:00
|
|
|
|
error => {
|
2019-04-24 14:02:11 +02:00
|
|
|
|
this.handleError("Error getting Master Zenodo community with id: " + this.masterZenodoCommunityId, error);
|
|
|
|
|
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|
|
|
|
|
);
|
2019-04-24 14:02:11 +02: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"]);
|
|
|
|
|
}
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
2019-04-24 14:02:11 +02:00
|
|
|
|
},
|
|
|
|
|
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;
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|
2019-04-24 14:02:11 +02:00
|
|
|
|
);
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-04-24 14:02:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-11-23 10:52:51 +01:00
|
|
|
|
});
|
2019-04-24 14:02:11 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2018-11-23 10:52:51 +01:00
|
|
|
|
|
|
|
|
|
|
2019-04-24 14:02:11 +02:00
|
|
|
|
private updateDescription(description: string) {
|
|
|
|
|
this._meta.updateTag({content: description}, "name='description'");
|
|
|
|
|
this._meta.updateTag({content: description}, "property='og:description'");
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|
2019-04-24 14:02:11 +02:00
|
|
|
|
|
|
|
|
|
private updateTitle(title: string) {
|
|
|
|
|
var _prefix = "OpenAIRE | ";
|
|
|
|
|
var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
|
2018-11-23 10:52:51 +01:00
|
|
|
|
this._title.setTitle(_title);
|
2019-04-24 14:02:11 +02:00
|
|
|
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|
2019-04-24 14:02:11 +02:00
|
|
|
|
|
|
|
|
|
private updateUrl(url: string) {
|
|
|
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 12:08:25 +02:00
|
|
|
|
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;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 14:02:11 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
//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) {
|
2019-04-24 14:02:11 +02:00
|
|
|
|
console.error("Share in Zenodo Page: " + message, error);
|
2019-02-19 13:17:53 +01:00
|
|
|
|
}
|
2018-11-23 10:52:51 +01:00
|
|
|
|
}
|