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 = properties;
|
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
|
this.url = properties.domain + properties.baseLink + this._router.url;
|
75
|
this.seoService.createLinkForCanonicalURL(this.url, false);
|
76
|
this.updateUrl(this.url);
|
77
|
this.updateTitle(this.title);
|
78
|
this.updateDescription("Zenodo, repository, deposit, share");
|
79
|
this.depositLearnHowPage = this.properties.depositLearnHowPage;
|
80
|
this.breadcrumbs.push({name: 'home', route: '/'}, {
|
81
|
name: "Deposit",
|
82
|
route: this.depositLearnHowPage
|
83
|
}, {name: "Deposit in zenodo", route: null});
|
84
|
//this.getDivContents();
|
85
|
this.getPageContents();
|
86
|
this.subs.push(this._communityService.getCommunityAsObservable().subscribe(
|
87
|
community => {
|
88
|
if (community) {
|
89
|
this.communityId = community.communityId;
|
90
|
this.piwikSiteId = PiwikHelper.getSiteId(this.communityId, this.properties.environment);
|
91
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
92
|
this.subs.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe());
|
93
|
}
|
94
|
this.community = community;
|
95
|
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
96
|
if (this.masterZenodoCommunityId) {
|
97
|
this.subs.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.masterZenodoCommunityId, null).subscribe(
|
98
|
result => {
|
99
|
this.masterZenodoCommunity = result;
|
100
|
|
101
|
},
|
102
|
error => {
|
103
|
this.handleError("Error getting Master Zenodo community with id: " + this.masterZenodoCommunityId, error);
|
104
|
|
105
|
}
|
106
|
));
|
107
|
}
|
108
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
109
|
this.subs.push(this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
|
110
|
result => {
|
111
|
this.communityIds = result;
|
112
|
this.zenodoSearchUtils.totalResults = this.communityIds.length;
|
113
|
if (this.communityIds.length == 0) {
|
114
|
this.zenodoSearchUtils.status = this.errorCodes.NONE;
|
115
|
}
|
116
|
this.getCommunities()
|
117
|
|
118
|
},
|
119
|
error => {
|
120
|
//console.error("list of zenodo communities couldn't be loaded");
|
121
|
this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
|
122
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
123
|
} //this.handleError('System error retrieving community profile', error)
|
124
|
));
|
125
|
}
|
126
|
}));
|
127
|
|
128
|
}
|
129
|
|
130
|
public ngOnDestroy() {
|
131
|
for (let sub of this.subs) {
|
132
|
if (sub instanceof Subscriber) {
|
133
|
sub.unsubscribe();
|
134
|
}
|
135
|
}
|
136
|
}
|
137
|
|
138
|
private updateDescription(description: string) {
|
139
|
this._meta.updateTag({content: description}, "name='description'");
|
140
|
this._meta.updateTag({content: description}, "property='og:description'");
|
141
|
}
|
142
|
|
143
|
private updateTitle(title: string) {
|
144
|
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
|
145
|
this._title.setTitle(_title);
|
146
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
147
|
}
|
148
|
|
149
|
private updateUrl(url: string) {
|
150
|
this._meta.updateTag({content: url}, "property='og:url'");
|
151
|
}
|
152
|
|
153
|
private getPageContents() {
|
154
|
this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
155
|
this.pageContents = contents;
|
156
|
}));
|
157
|
}
|
158
|
|
159
|
private getDivContents() {
|
160
|
this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
161
|
this.divContents = contents;
|
162
|
}));
|
163
|
}
|
164
|
|
165
|
getZenodoCommunityById(zenodoid, openaireId) {
|
166
|
this.subs.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + zenodoid, openaireId).subscribe(
|
167
|
result => {
|
168
|
this.communities[zenodoid] = result;
|
169
|
this.zenodoCommunitiesLoadedCount++;
|
170
|
if (this.zenodoCommunitiesLoadedCount >= this.communityIds.length || this.page * this.size) {
|
171
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
172
|
}
|
173
|
|
174
|
|
175
|
},
|
176
|
error => {
|
177
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
178
|
// emptyCommunity.id = zenodoid;
|
179
|
// emptyCommunity.openaireId = openaireId;
|
180
|
// emptyCommunity.title = zenodoid;
|
181
|
// this.communities.push(emptyCommunity);
|
182
|
this.zenodoCommunitiesLoadedCount++;
|
183
|
if (this.zenodoCommunitiesLoadedCount >= this.communityIds.length) {
|
184
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
185
|
}
|
186
|
//console.error("Zenodo community'"+zenodoid+"' couldn't be loaded");
|
187
|
this.handleError("Error getting Zenodo community with id: " + zenodoid + " and openaire id: " + openaireId, error);
|
188
|
|
189
|
}
|
190
|
));
|
191
|
}
|
192
|
|
193
|
private handleError(message: string, error) {
|
194
|
console.error("Share in Zenodo Page: " + message, error);
|
195
|
}
|
196
|
|
197
|
public getCommunities($event = {value: 1}) {
|
198
|
this.page = $event.value;
|
199
|
for (let i = (this.page - 1) * this.size; i < this.communityIds.length && i < this.page * this.size; i++) {
|
200
|
if (!this.communities[this.communityIds[i]["zenodoid"]]) {
|
201
|
this.getZenodoCommunityById(this.communityIds[i]["zenodoid"], this.communityIds[i]["id"]);
|
202
|
}
|
203
|
}
|
204
|
}
|
205
|
|
206
|
}
|