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 {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
|
7
|
|
8
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
9
|
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
10
|
|
11
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
12
|
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
|
13
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
14
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
15
|
import {properties} from "../../environments/environment";
|
16
|
import {Subscriber} from "rxjs";
|
17
|
|
18
|
@Component({
|
19
|
selector: 'communities',
|
20
|
templateUrl: 'communities.component.html',
|
21
|
})
|
22
|
|
23
|
export class CommunitiesComponent {
|
24
|
private subscriptions = [];
|
25
|
|
26
|
public pageTitle = "OpenAIRE"
|
27
|
public researchCommunities = [];
|
28
|
public gifs: { "gif": string, "header": string, "text" }[] = [];
|
29
|
public pageContents = null;
|
30
|
public divContents = null;
|
31
|
// Message variables
|
32
|
public status: number;
|
33
|
public loading: boolean = true;
|
34
|
public subscriberErrorMessage: string = "";
|
35
|
public errorCodes: ErrorCodes;
|
36
|
private errorMessages: ErrorMessagesComponent;
|
37
|
|
38
|
properties: EnvProperties;
|
39
|
public keyword: string = "";
|
40
|
public type: string = "all";
|
41
|
|
42
|
constructor(
|
43
|
private route: ActivatedRoute,
|
44
|
private _router: Router,
|
45
|
private _meta: Meta,
|
46
|
private _title: Title,
|
47
|
private _piwikService: PiwikService,
|
48
|
private _communitiesService: CommunitiesService,
|
49
|
private helper: HelperService,
|
50
|
private seoService: SEOService) {
|
51
|
|
52
|
var description = "OpenAIRE - Connect, Community Dashboard, research community";
|
53
|
var title = "OpenAIRE - Connect";
|
54
|
|
55
|
this._meta.updateTag({content: description}, "name='description'");
|
56
|
this._meta.updateTag({content: description}, "property='og:description'");
|
57
|
this._meta.updateTag({content: title}, "property='og:title'");
|
58
|
this._title.setTitle(title);
|
59
|
|
60
|
this.errorCodes = new ErrorCodes();
|
61
|
this.errorMessages = new ErrorMessagesComponent();
|
62
|
this.status = this.errorCodes.LOADING;
|
63
|
}
|
64
|
|
65
|
public ngOnInit() {
|
66
|
this.properties = properties;
|
67
|
var url = this.properties.domain + this.properties.baseLink + this._router.url;
|
68
|
this.seoService.createLinkForCanonicalURL(url, false);
|
69
|
this._meta.updateTag({content: url}, "property='og:url'");
|
70
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
71
|
this.subscriptions.push(this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe());
|
72
|
}
|
73
|
this.getCommunities();
|
74
|
this.createGifs();
|
75
|
//this.getDivContents();
|
76
|
this.getPageContents();
|
77
|
}
|
78
|
|
79
|
private getPageContents() {
|
80
|
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
81
|
this.pageContents = contents;
|
82
|
}));
|
83
|
}
|
84
|
|
85
|
private getDivContents() {
|
86
|
this.subscriptions.push(this.helper.getDivHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
87
|
this.divContents = contents;
|
88
|
}));
|
89
|
}
|
90
|
|
91
|
public getCommunities() {
|
92
|
this.loading = true;
|
93
|
this.status = this.errorCodes.LOADING;
|
94
|
this.subscriberErrorMessage = "";
|
95
|
|
96
|
this.researchCommunities = [];
|
97
|
|
98
|
this.subscriptions.push(this._communitiesService.getCommunitiesState().subscribe(
|
99
|
communitiesResults => {
|
100
|
if(!communitiesResults){
|
101
|
return;
|
102
|
}
|
103
|
if(communitiesResults.length == 0) {
|
104
|
this.status = this.errorCodes.DONE;
|
105
|
return;
|
106
|
}
|
107
|
this.sort(communitiesResults);
|
108
|
communitiesResults.forEach((community, index) => {
|
109
|
let showCommunity: boolean = true;
|
110
|
if (community['status'] == "hidden" || community['status'] == "manager") {
|
111
|
showCommunity = false;
|
112
|
}
|
113
|
if (showCommunity) {
|
114
|
this.researchCommunities.push(community);
|
115
|
}
|
116
|
this.status = this.errorCodes.DONE;
|
117
|
});
|
118
|
this.loading = false;
|
119
|
},
|
120
|
error => {
|
121
|
this.status = this.handleError("Error getting communities", error);
|
122
|
this.loading = false;
|
123
|
}
|
124
|
));
|
125
|
}
|
126
|
|
127
|
private createGifs() {
|
128
|
this.gifs.push({
|
129
|
gif: "assets/connect-assets/home/gifs/deposit.gif",
|
130
|
header: "Find a repository to deposit your research outcome",
|
131
|
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."
|
132
|
});
|
133
|
this.gifs.push({
|
134
|
gif: "assets/connect-assets/home/gifs/link.gif",
|
135
|
header: "Link your research output with your community, funding, and other research products",
|
136
|
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."
|
137
|
});
|
138
|
this.gifs.push({
|
139
|
gif: "assets/connect-assets/home/gifs/overview.gif",
|
140
|
header: "View community's overview at a glance",
|
141
|
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."
|
142
|
});
|
143
|
this.gifs.push({
|
144
|
gif: "assets/connect-assets/home/gifs/results.gif",
|
145
|
header: "Search & browse your community's research products. ",
|
146
|
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."
|
147
|
});
|
148
|
this.gifs.push({
|
149
|
gif: "assets/connect-assets/home/gifs/graph-analysis.gif",
|
150
|
header: "View statistics for your community's research products.",
|
151
|
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."
|
152
|
});
|
153
|
}
|
154
|
|
155
|
private sort(results: CommunityInfo[]) {
|
156
|
results.sort((left, right): number => {
|
157
|
if (!right.date || left.date > right.date) {
|
158
|
return -1;
|
159
|
} else if (!left.date || left.date < right.date) {
|
160
|
return 1;
|
161
|
} else {
|
162
|
if (left.title > right.title) {
|
163
|
return 1;
|
164
|
} else if (left.title < right.title) {
|
165
|
return -1;
|
166
|
} else {
|
167
|
return 0;
|
168
|
}
|
169
|
}
|
170
|
})
|
171
|
}
|
172
|
|
173
|
public quote(param: string): string {
|
174
|
return StringUtils.quote(param);
|
175
|
}
|
176
|
|
177
|
ngOnDestroy() {
|
178
|
this.subscriptions.forEach(subscription => {
|
179
|
if (subscription instanceof Subscriber) {
|
180
|
subscription.unsubscribe();
|
181
|
}
|
182
|
});
|
183
|
}
|
184
|
|
185
|
private handleError(message: string, error): number {
|
186
|
var code = "";
|
187
|
try {
|
188
|
if (!error.status) {
|
189
|
var error = error.json();
|
190
|
code = error.code;
|
191
|
} else {
|
192
|
code = error.status;
|
193
|
}
|
194
|
}catch(e){}
|
195
|
console.error("Communities (component): " + message, error);
|
196
|
return this.errorMessages.getErrorCode(code);
|
197
|
}
|
198
|
}
|