1
|
import {Component} 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 {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service';
|
6
|
import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service';
|
7
|
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
|
8
|
|
9
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
10
|
import {Session} from '../openaireLibrary/login/utils/helper.class';
|
11
|
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
12
|
|
13
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
14
|
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
|
15
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
16
|
|
17
|
@Component({
|
18
|
selector: 'communities',
|
19
|
templateUrl: 'communities.component.html',
|
20
|
})
|
21
|
|
22
|
export class CommunitiesComponent {
|
23
|
public piwiksub: any;
|
24
|
|
25
|
public pageTitle = "OpenAIRE"
|
26
|
// TODO remove initiatives
|
27
|
public researchCommunities = [];
|
28
|
public researchInitiatives = [];
|
29
|
public subscriberOfCommunities = [];
|
30
|
public managerOfCommunities = [];
|
31
|
public gifs: { "gif": string, "header": string, "text" }[] = [];
|
32
|
public pageContents = null;
|
33
|
public divContents = null;
|
34
|
// Message variables
|
35
|
public status: number;
|
36
|
public loading: boolean = true;
|
37
|
public subscriberErrorMessage: string = "";
|
38
|
public errorCodes: ErrorCodes;
|
39
|
private errorMessages: ErrorMessagesComponent;
|
40
|
|
41
|
properties: EnvProperties;
|
42
|
public keyword: string = "";
|
43
|
public type: string = "all";
|
44
|
|
45
|
constructor(
|
46
|
private route: ActivatedRoute,
|
47
|
private _router: Router,
|
48
|
private _meta: Meta,
|
49
|
private _title: Title,
|
50
|
private _piwikService: PiwikService,
|
51
|
private _communitiesService: CommunitiesService,
|
52
|
private _subscribeService: SubscribeService,
|
53
|
private helper: HelperService) {
|
54
|
|
55
|
var description = "OpenAIRE - Connect, Community Dashboard, research community";
|
56
|
var title = "OpenAIRE - Connect";
|
57
|
|
58
|
this._meta.updateTag({content: description}, "name='description'");
|
59
|
this._meta.updateTag({content: description}, "property='og:description'");
|
60
|
this._meta.updateTag({content: title}, "property='og:title'");
|
61
|
this._title.setTitle(title);
|
62
|
|
63
|
this.errorCodes = new ErrorCodes();
|
64
|
this.errorMessages = new ErrorMessagesComponent();
|
65
|
this.status = this.errorCodes.LOADING;
|
66
|
}
|
67
|
|
68
|
public ngOnInit() {
|
69
|
this.route.data
|
70
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
71
|
this.properties = data.envSpecific;
|
72
|
var url = data.envSpecific.baseLink + this._router.url
|
73
|
this._meta.updateTag({content: url}, "property='og:url'");
|
74
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
75
|
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
|
76
|
}
|
77
|
this.getCommunities();
|
78
|
this.createGifs();
|
79
|
//this.getDivContents();
|
80
|
this.getPageContents();
|
81
|
});
|
82
|
}
|
83
|
|
84
|
private getPageContents() {
|
85
|
this.helper.getPageHelpContents(this._router.url.split('?')[0].substring(0), this.properties, 'connect').subscribe(contents => {
|
86
|
this.pageContents = contents;
|
87
|
})
|
88
|
}
|
89
|
|
90
|
private getDivContents() {
|
91
|
this.helper.getDivHelpContents(this._router.url.split('?')[0].substring(0), this.properties, 'connect').subscribe(contents => {
|
92
|
this.divContents = contents;
|
93
|
})
|
94
|
}
|
95
|
|
96
|
public getCommunities() {
|
97
|
this.loading = true;
|
98
|
this.status = this.errorCodes.LOADING;
|
99
|
this.subscriberErrorMessage = "";
|
100
|
|
101
|
this.researchCommunities = [];
|
102
|
this.researchInitiatives = [];
|
103
|
this.subscriberOfCommunities = [];
|
104
|
this.managerOfCommunities = [];
|
105
|
|
106
|
this._communitiesService.getCommunitiesState().subscribe(
|
107
|
communitiesResults => {
|
108
|
//this.communitiesResults = communitiesResults;
|
109
|
//this.communitiesToShow = this.communitiesResults.slice();
|
110
|
//console.log(communitiesResults);
|
111
|
this.sort(communitiesResults);
|
112
|
|
113
|
var subscribedLoading = communitiesResults.length;
|
114
|
var mail = Session.getUserEmail();
|
115
|
communitiesResults.forEach((community, index) => {
|
116
|
let showCommunity: boolean = true;
|
117
|
let isManager: boolean = false;
|
118
|
let isSubscriber: boolean = false;
|
119
|
|
120
|
if (community['status'] == "hidden") {
|
121
|
showCommunity = false;
|
122
|
} else {
|
123
|
if (mail == null && community['status'] == "manager") { // no user
|
124
|
showCommunity = false;
|
125
|
} else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
|
126
|
isManager = true;
|
127
|
} else if (community.managers.indexOf(mail) != -1) {
|
128
|
isManager = true;
|
129
|
} else if (community['status'] == "manager") {
|
130
|
showCommunity = false;
|
131
|
}
|
132
|
}
|
133
|
|
134
|
if (showCommunity) {
|
135
|
// TODO remove
|
136
|
/*if(community.type == "community"){
|
137
|
this.researchCommunities.push(community);
|
138
|
} else if(community.type == "ri") {
|
139
|
this.researchInitiatives.push(community);
|
140
|
}*/
|
141
|
this.researchCommunities.push(community);
|
142
|
if (isManager) {
|
143
|
community.isManager = true;
|
144
|
this.managerOfCommunities.push(community);
|
145
|
}
|
146
|
}
|
147
|
|
148
|
this.status = this.errorCodes.DONE;
|
149
|
|
150
|
if (mail != null && showCommunity) {
|
151
|
this._subscribeService.isSubscribedToCommunity(this.properties, community.communityId, mail).subscribe(
|
152
|
res => {
|
153
|
isSubscriber = res;
|
154
|
if (isSubscriber) {
|
155
|
community.isSubscribed = true;
|
156
|
if (isManager) {
|
157
|
this.subscriberOfCommunities.push(community);
|
158
|
} else {
|
159
|
this.subscriberOfCommunities.unshift(community);
|
160
|
}
|
161
|
}
|
162
|
|
163
|
subscribedLoading--;
|
164
|
if (subscribedLoading == 0) {
|
165
|
this.loading = false;
|
166
|
}
|
167
|
},
|
168
|
error => {
|
169
|
// if(this.properties.environment == "development") {
|
170
|
// this.subscriberErrorMessage = "Error fetching communities you are subscribed to";
|
171
|
// }
|
172
|
this.handleError("Error getting response if email: " + mail + " is subscribed to community with id: " + community.communityId, error);
|
173
|
subscribedLoading--;
|
174
|
if (subscribedLoading == 0) {
|
175
|
this.loading = false;
|
176
|
}
|
177
|
});
|
178
|
} else {
|
179
|
subscribedLoading--;
|
180
|
if (subscribedLoading == 0) {
|
181
|
this.loading = false;
|
182
|
}
|
183
|
}
|
184
|
});
|
185
|
},
|
186
|
error => {
|
187
|
this.status = this.handleError("Error getting communities", error);
|
188
|
this.loading = false;
|
189
|
}
|
190
|
);
|
191
|
}
|
192
|
|
193
|
private createGifs() {
|
194
|
this.gifs.push({
|
195
|
gif: "assets/home/gifs/deposit.gif",
|
196
|
header: "Find a repository to deposit your research outcome",
|
197
|
text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
|
198
|
});
|
199
|
this.gifs.push({
|
200
|
gif: "assets/home/gifs/link.gif",
|
201
|
header: "Link your research output with your community, funding, and other research products",
|
202
|
text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
|
203
|
});
|
204
|
this.gifs.push({
|
205
|
gif: "assets/home/gifs/overview.gif",
|
206
|
header: "View community's overview at a glance",
|
207
|
text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
|
208
|
});
|
209
|
this.gifs.push({
|
210
|
gif: "assets/home/gifs/results.gif",
|
211
|
header: "Search & browse your community's research products. ",
|
212
|
text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
|
213
|
});
|
214
|
this.gifs.push({
|
215
|
gif: "assets/home/gifs/graph-analysis.gif",
|
216
|
header: "View statistics for your community's research products.",
|
217
|
text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
|
218
|
});
|
219
|
}
|
220
|
|
221
|
private sort(results: CommunityInfo[]) {
|
222
|
results.sort((left, right): number => {
|
223
|
if (!right.date || left.date > right.date) {
|
224
|
return -1;
|
225
|
} else if (!left.date || left.date < right.date) {
|
226
|
return 1;
|
227
|
} else {
|
228
|
if (left.title > right.title) {
|
229
|
return 1;
|
230
|
} else if (left.title < right.title) {
|
231
|
return -1;
|
232
|
} else {
|
233
|
return 0;
|
234
|
}
|
235
|
}
|
236
|
})
|
237
|
}
|
238
|
|
239
|
public quote(param: string): string {
|
240
|
return StringUtils.quote(param);
|
241
|
}
|
242
|
|
243
|
public ngOnDestroy() {
|
244
|
if (this.piwiksub) {
|
245
|
this.piwiksub.unsubscribe();
|
246
|
}
|
247
|
}
|
248
|
|
249
|
private handleError(message: string, error): number {
|
250
|
var code = "";
|
251
|
if (!error.status) {
|
252
|
var error = error.json();
|
253
|
code = error.code;
|
254
|
} else {
|
255
|
code = error.status;
|
256
|
}
|
257
|
|
258
|
console.error("Communities (component): " + message, error);
|
259
|
|
260
|
return this.errorMessages.getErrorCode(code);
|
261
|
}
|
262
|
}
|