1
|
import {Component, Input, Output, EventEmitter, ViewChild, ElementRef} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import {ActivatedRoute, Router} from '@angular/router';
|
4
|
import {Title, Meta} from '@angular/platform-browser';
|
5
|
import{EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
6
|
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
7
|
import {SearchZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
|
8
|
import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
|
9
|
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
|
10
|
|
11
|
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
|
12
|
import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo';
|
13
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
14
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
15
|
|
16
|
@Component({
|
17
|
selector: 'share-in-zenodo',
|
18
|
templateUrl: './shareInZenodo.component.html'
|
19
|
})
|
20
|
export class ShareInZenodoComponent {
|
21
|
properties:EnvProperties;
|
22
|
private communityId: string = null;
|
23
|
private community:CommunityInfo = null;
|
24
|
|
25
|
|
26
|
// public warningMessage = "";
|
27
|
// public infoMessage = "";
|
28
|
|
29
|
masterZenodoCommunityId = null;
|
30
|
masterZenodoCommunity = null;
|
31
|
|
32
|
CommunityIds = null;
|
33
|
communities = [];
|
34
|
|
35
|
zenodocommunitiesloadedCount = 0;
|
36
|
zenodoSearchUtils:SearchUtilsClass = new SearchUtilsClass();
|
37
|
private errorCodes: ErrorCodes = new ErrorCodes();;
|
38
|
depositLink = "https://zenodo.org/deposit/new?c=";
|
39
|
|
40
|
|
41
|
constructor ( private route: ActivatedRoute, private _router: Router,
|
42
|
private _meta: Meta, private _title: Title, private _ΖenodoCommunitieService: ZenodoCommunitiesService,private _communityService: CommunityService,private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService) {}
|
43
|
|
44
|
public ngOnInit() {
|
45
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;;
|
46
|
this.route.data
|
47
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
48
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
49
|
this.updateTitle("Share in Zenodo");
|
50
|
this.updateDescription("Zenodo, repository, deposit, share");
|
51
|
this.properties = data.envSpecific;
|
52
|
this.route.queryParams.subscribe(params => {
|
53
|
this.communityId = params['communityId'];
|
54
|
if(!this.communityId){
|
55
|
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
56
|
}
|
57
|
|
58
|
if(this.communityId) {
|
59
|
|
60
|
if (this.communityId != null && this.communityId != '') {
|
61
|
|
62
|
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
|
63
|
community => {
|
64
|
this.community = community;
|
65
|
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
66
|
if(this.masterZenodoCommunityId){
|
67
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+this.masterZenodoCommunityId, null).subscribe(
|
68
|
result => {
|
69
|
this.masterZenodoCommunity = result;
|
70
|
|
71
|
},
|
72
|
error => {
|
73
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
74
|
// emptyCommunity.id = this.masterZenodoCommunityId;
|
75
|
// emptyCommunity.title = this.masterZenodoCommunityId;
|
76
|
// this.masterZenodoCommunity = emptyCommunity;
|
77
|
console.log("Master Zenodo community'"+this.masterZenodoCommunityId+"' couldn't be loaded");
|
78
|
|
79
|
|
80
|
}
|
81
|
);
|
82
|
}
|
83
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;;
|
84
|
this._searchZenodoCommunitiesService.searchZCommunities(this.properties,this.communityId).subscribe (
|
85
|
result => {
|
86
|
this.CommunityIds = result;
|
87
|
this.zenodoSearchUtils.totalResults = this.CommunityIds.length;
|
88
|
if(this.CommunityIds.length == 0){
|
89
|
this.zenodoSearchUtils.status = this.errorCodes.NONE;
|
90
|
}
|
91
|
for(let i=0; i< this.CommunityIds.length; i++){
|
92
|
this.getZenodoCommunityById(this.CommunityIds[i]["zenodoid"], this.CommunityIds[i]["id"]);
|
93
|
}
|
94
|
|
95
|
},
|
96
|
error => {
|
97
|
console.log("list of zenodo communities couldn't be loaded");
|
98
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
99
|
} //this.handleError('System error retrieving community profile', error)
|
100
|
);
|
101
|
|
102
|
},
|
103
|
error => {
|
104
|
console.log("Community couldn't be loaded");
|
105
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
106
|
}
|
107
|
);
|
108
|
|
109
|
|
110
|
}
|
111
|
|
112
|
|
113
|
}
|
114
|
});
|
115
|
});
|
116
|
}
|
117
|
|
118
|
|
119
|
private updateDescription(description:string){
|
120
|
this._meta.updateTag({content:description},"name='description'");
|
121
|
this._meta.updateTag({content:description},"property='og:description'");
|
122
|
}
|
123
|
private updateTitle(title:string){
|
124
|
var _prefix ="OpenAIRE | ";
|
125
|
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
|
126
|
this._title.setTitle(_title);
|
127
|
this._meta.updateTag({content:_title},"property='og:title'");
|
128
|
}
|
129
|
private updateUrl(url:string){
|
130
|
this._meta.updateTag({content:url},"property='og:url'");
|
131
|
}
|
132
|
getZenodoCommunityById(zenodoid, openaireId){
|
133
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+zenodoid, openaireId).subscribe(
|
134
|
result => {
|
135
|
this.communities.push(result);
|
136
|
this.zenodocommunitiesloadedCount++;
|
137
|
if(this.zenodocommunitiesloadedCount >= this.CommunityIds.length){
|
138
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
139
|
}
|
140
|
|
141
|
|
142
|
},
|
143
|
error => {
|
144
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
145
|
// emptyCommunity.id = zenodoid;
|
146
|
// emptyCommunity.openaireId = openaireId;
|
147
|
// emptyCommunity.title = zenodoid;
|
148
|
// this.communities.push(emptyCommunity);
|
149
|
this.zenodocommunitiesloadedCount++;
|
150
|
if(this.zenodocommunitiesloadedCount >= this.CommunityIds.length){
|
151
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
152
|
}
|
153
|
console.log("Zenodo community'"+zenodoid+"' couldn't be loaded");
|
154
|
|
155
|
|
156
|
}
|
157
|
);
|
158
|
}
|
159
|
}
|