1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {Meta, Title} from '@angular/platform-browser';
|
4
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
5
|
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
6
|
import {SearchZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
|
7
|
import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
|
8
|
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
|
9
|
|
10
|
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
|
11
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
12
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
13
|
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
14
|
import {HelperService} from "../../openaireLibrary/utils/helper/helper.service";
|
15
|
import {RouterHelper} from "../../openaireLibrary/utils/routerHelper.class";
|
16
|
import {SEOService} from "../../openaireLibrary/sharedComponents/SEO/SEO.service";
|
17
|
import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service";
|
18
|
import {PiwikHelper} from "../../utils/piwikHelper";
|
19
|
import {Breadcrumb} from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
|
20
|
import {properties} from "../../../environments/environment";
|
21
|
import {Subscriber, Subscription} from "rxjs";
|
22
|
|
23
|
@Component({
|
24
|
selector: 'share-in-zenodo',
|
25
|
templateUrl: './shareInZenodo.component.html'
|
26
|
})
|
27
|
export class ShareInZenodoComponent {
|
28
|
public url: string = null;
|
29
|
public title: string = "Share in Zenodo";
|
30
|
|
31
|
public piwikSiteId = null;
|
32
|
|
33
|
properties: EnvProperties;
|
34
|
communityId: string = null;
|
35
|
private community: CommunityInfo = null;
|
36
|
public pageContents = null;
|
37
|
public divContents = null;
|
38
|
|
39
|
|
40
|
// public warningMessage = "";
|
41
|
// public infoMessage = "";
|
42
|
|
43
|
masterZenodoCommunityId = null;
|
44
|
masterZenodoCommunity = null;
|
45
|
|
46
|
communityIds = null;
|
47
|
communities = [];
|
48
|
page = 1;
|
49
|
size = 5;
|
50
|
zenodoCommunitiesLoadedCount = 0;
|
51
|
zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
52
|
errorCodes: ErrorCodes = new ErrorCodes();
|
53
|
depositLink = "https://zenodo.org/deposit/new?c=";
|
54
|
depositLearnHowPage: string = null;
|
55
|
public routerHelper:RouterHelper = new RouterHelper();
|
56
|
breadcrumbs:Breadcrumb[] = [];
|
57
|
|
58
|
subs: Subscription[] = [];
|
59
|
|
60
|
constructor(private route: ActivatedRoute,
|
61
|
private _router: Router,
|
62
|
private _meta: Meta,
|
63
|
private _title: Title,
|
64
|
private _zenodoCommunitieService: ZenodoCommunitiesService,
|
65
|
private _communityService: CommunityService,
|
66
|
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
|
67
|
private helper: HelperService,
|
68
|
private _piwikService:PiwikService,
|
69
|
private seoService: SEOService) {
|
70
|
}
|
71
|
|
72
|
public ngOnInit() {
|
73
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
74
|
|
75
|
this.url = properties.domain + properties.baseLink + this._router.url;
|
76
|
|
77
|
this.seoService.createLinkForCanonicalURL(this.url, false);
|
78
|
this.updateUrl(this.url);
|
79
|
this.updateTitle(this.title);
|
80
|
this.updateDescription("Zenodo, repository, deposit, share");
|
81
|
|
82
|
this.properties = properties;
|
83
|
this.subs.push(this.route.queryParams.subscribe(params => {
|
84
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
85
|
if (!this.communityId) {
|
86
|
this.communityId = params['communityId'];
|
87
|
}
|
88
|
|
89
|
this.piwikSiteId = PiwikHelper.getSiteId(this.communityId,this.properties.environment);
|
90
|
|
91
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
92
|
this.subs.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe());
|
93
|
}
|
94
|
|
95
|
this.depositLearnHowPage = this.properties.depositLearnHowPage;
|
96
|
this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: this.depositLearnHowPage},{name:"Deposit in zenodo",route:null});
|
97
|
|
98
|
//this.getDivContents();
|
99
|
this.getPageContents();
|
100
|
if (this.communityId && this.communityId != '') {
|
101
|
this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI + this.communityId).subscribe(
|
102
|
community => {
|
103
|
this.community = community;
|
104
|
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
105
|
if (typeof document !== 'undefined') {
|
106
|
HelperFunctions.scroll();
|
107
|
}
|
108
|
if (this.masterZenodoCommunityId) {
|
109
|
this.subs.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.masterZenodoCommunityId, null).subscribe(
|
110
|
result => {
|
111
|
this.masterZenodoCommunity = result;
|
112
|
|
113
|
},
|
114
|
error => {
|
115
|
this.handleError("Error getting Master Zenodo community with id: " + this.masterZenodoCommunityId, error);
|
116
|
|
117
|
}
|
118
|
));
|
119
|
}
|
120
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
121
|
|
122
|
this.subs.push(this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
|
123
|
result => {
|
124
|
this.communityIds = result;
|
125
|
this.zenodoSearchUtils.totalResults = this.communityIds.length;
|
126
|
if (this.communityIds.length == 0) {
|
127
|
this.zenodoSearchUtils.status = this.errorCodes.NONE;
|
128
|
}
|
129
|
this.getCommunities()
|
130
|
|
131
|
},
|
132
|
error => {
|
133
|
//console.error("list of zenodo communities couldn't be loaded");
|
134
|
this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
|
135
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
136
|
} //this.handleError('System error retrieving community profile', error)
|
137
|
));
|
138
|
|
139
|
},
|
140
|
error => {
|
141
|
//console.error("Community couldn't be loaded");
|
142
|
this.handleError("Error getting community with id: " + this.communityId, error);
|
143
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
144
|
}
|
145
|
));
|
146
|
}
|
147
|
}));
|
148
|
}
|
149
|
|
150
|
public ngOnDestroy() {
|
151
|
for (let sub of this.subs) {
|
152
|
if(sub instanceof Subscriber) {
|
153
|
sub.unsubscribe();
|
154
|
}
|
155
|
}
|
156
|
}
|
157
|
|
158
|
private updateDescription(description: string) {
|
159
|
this._meta.updateTag({content: description}, "name='description'");
|
160
|
this._meta.updateTag({content: description}, "property='og:description'");
|
161
|
}
|
162
|
|
163
|
private updateTitle(title: string) {
|
164
|
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
|
165
|
this._title.setTitle(_title);
|
166
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
167
|
}
|
168
|
|
169
|
private updateUrl(url: string) {
|
170
|
this._meta.updateTag({content: url}, "property='og:url'");
|
171
|
}
|
172
|
|
173
|
private getPageContents() {
|
174
|
this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
175
|
this.pageContents = contents;
|
176
|
}));
|
177
|
}
|
178
|
|
179
|
private getDivContents() {
|
180
|
this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
181
|
this.divContents = contents;
|
182
|
}));
|
183
|
}
|
184
|
|
185
|
getZenodoCommunityById(zenodoid, openaireId) {
|
186
|
this.subs.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + zenodoid, openaireId).subscribe(
|
187
|
result => {
|
188
|
this.communities[zenodoid] = result;
|
189
|
this.zenodoCommunitiesLoadedCount++;
|
190
|
if (this.zenodoCommunitiesLoadedCount >= this.communityIds.length || this.page * this.size) {
|
191
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
192
|
}
|
193
|
|
194
|
|
195
|
},
|
196
|
error => {
|
197
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
198
|
// emptyCommunity.id = zenodoid;
|
199
|
// emptyCommunity.openaireId = openaireId;
|
200
|
// emptyCommunity.title = zenodoid;
|
201
|
// this.communities.push(emptyCommunity);
|
202
|
this.zenodoCommunitiesLoadedCount++;
|
203
|
if (this.zenodoCommunitiesLoadedCount >= this.communityIds.length) {
|
204
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
205
|
}
|
206
|
//console.error("Zenodo community'"+zenodoid+"' couldn't be loaded");
|
207
|
this.handleError("Error getting Zenodo community with id: " + zenodoid + " and openaire id: " + openaireId, error);
|
208
|
|
209
|
}
|
210
|
));
|
211
|
}
|
212
|
|
213
|
private handleError(message: string, error) {
|
214
|
console.error("Share in Zenodo Page: " + message, error);
|
215
|
}
|
216
|
public getCommunities($event = {value:1}) {
|
217
|
this.page = $event.value;
|
218
|
for (let i = (this.page - 1 ) * this.size; i < this.communityIds.length && i< this.page * this.size; i++) {
|
219
|
if(!this.communities[this.communityIds[i]["zenodoid"]]) {
|
220
|
this.getZenodoCommunityById(this.communityIds[i]["zenodoid"], this.communityIds[i]["id"]);
|
221
|
}
|
222
|
}
|
223
|
}
|
224
|
|
225
|
}
|