Revision 60454
Added by Konstantinos Triantafyllou over 3 years ago
my-communities.component.ts | ||
---|---|---|
3 | 3 |
import {Meta, Title} from '@angular/platform-browser'; |
4 | 4 |
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; |
5 | 5 |
import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service'; |
6 |
import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service'; |
|
7 | 6 |
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo'; |
8 | 7 |
|
9 | 8 |
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; |
... | ... | |
38 | 37 |
public errorCodes: ErrorCodes; |
39 | 38 |
private errorMessages: ErrorMessagesComponent; |
40 | 39 |
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'my Communities'}]; |
41 |
|
|
40 |
|
|
42 | 41 |
properties: EnvProperties; |
43 | 42 |
private user: User; |
44 | 43 |
subscriptions = []; |
44 |
|
|
45 | 45 |
constructor( |
46 | 46 |
private route: ActivatedRoute, |
47 | 47 |
private _router: Router, |
... | ... | |
49 | 49 |
private _title: Title, |
50 | 50 |
private _piwikService: PiwikService, |
51 | 51 |
private _communitiesService: CommunitiesService, |
52 |
private _subscribeService: SubscribeService, |
|
53 | 52 |
private helper: HelperService, |
54 | 53 |
private seoService: SEOService, |
55 | 54 |
private userManagementService: UserManagementService) { |
56 |
|
|
55 |
|
|
57 | 56 |
var description = "OpenAIRE - Connect, Community Dashboard, research community " + |
58 | 57 |
"| My managing and subscribed to Communities"; |
59 | 58 |
var title = "OpenAIRE - Connect | My Communities"; |
60 |
|
|
59 |
|
|
61 | 60 |
this._meta.updateTag({content: description}, "name='description'"); |
62 | 61 |
this._meta.updateTag({content: description}, "property='og:description'"); |
63 | 62 |
this._meta.updateTag({content: title}, "property='og:title'"); |
64 | 63 |
this._title.setTitle(title); |
65 |
|
|
64 |
|
|
66 | 65 |
this.errorCodes = new ErrorCodes(); |
67 | 66 |
this.errorMessages = new ErrorMessagesComponent(); |
68 | 67 |
this.status = this.errorCodes.LOADING; |
69 | 68 |
} |
70 |
|
|
69 |
|
|
71 | 70 |
public ngOnInit() { |
72 | 71 |
this.properties = properties; |
73 | 72 |
var url = this.properties.domain + this.properties.baseLink + this._router.url; |
... | ... | |
78 | 77 |
} |
79 | 78 |
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { |
80 | 79 |
this.user = user; |
81 |
if(this.user) { |
|
80 |
if (this.user) {
|
|
82 | 81 |
this.getCommunities(); |
83 | 82 |
} |
84 | 83 |
//this.getDivContents(); |
85 | 84 |
//this.getPageContents(); |
86 | 85 |
})); |
87 |
|
|
86 |
|
|
88 | 87 |
} |
89 |
|
|
88 |
|
|
90 | 89 |
private getPageContents() { |
91 | 90 |
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => { |
92 | 91 |
this.pageContents = contents; |
93 | 92 |
})); |
94 | 93 |
} |
95 |
|
|
94 |
|
|
96 | 95 |
private getDivContents() { |
97 | 96 |
this.subscriptions.push(this.helper.getDivHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => { |
98 | 97 |
this.divContents = contents; |
99 | 98 |
})); |
100 | 99 |
} |
101 |
|
|
100 |
|
|
102 | 101 |
public getCommunities() { |
103 | 102 |
this.loading = true; |
104 | 103 |
this.status = this.errorCodes.LOADING; |
105 | 104 |
this.subscriberErrorMessage = ""; |
106 |
|
|
105 |
|
|
107 | 106 |
this.subscriberOfCommunities = []; |
108 | 107 |
this.managerOfCommunities = []; |
109 | 108 |
this.researchCommunities = []; |
110 |
|
|
109 |
|
|
111 | 110 |
this.subscriptions.push(this._communitiesService.getCommunitiesState().subscribe( |
112 | 111 |
communitiesResults => { |
113 | 112 |
if (!communitiesResults) { |
... | ... | |
117 | 116 |
this.status = this.errorCodes.DONE; |
118 | 117 |
return; |
119 | 118 |
} |
120 |
; |
|
121 | 119 |
this.sort(communitiesResults); |
122 |
|
|
123 |
var subscribedLoading = communitiesResults.length; |
|
124 |
var mail = this.user.email; |
|
125 | 120 |
communitiesResults.forEach((community, index) => { |
126 | 121 |
let showCommunity: boolean = true; |
127 |
let isManager: boolean = false; |
|
128 |
let isSubscriber: boolean = false; |
|
129 |
|
|
122 |
community.isManager = Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || Session.isManager('community', community.communityId, this.user); |
|
130 | 123 |
if (community['status'] == "hidden") { |
131 | 124 |
showCommunity = false; |
132 | 125 |
} else { |
133 |
if (mail == null && community['status'] == "manager") { // no user
|
|
126 |
if(!community.isManager && community['status'] == "manager") {
|
|
134 | 127 |
showCommunity = false; |
135 |
} else if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) { |
|
136 |
isManager = true; |
|
137 |
} else if (community.managers.indexOf(mail) != -1) { |
|
138 |
isManager = true; |
|
139 |
} else if (community['status'] == "manager") { |
|
140 |
showCommunity = false; |
|
141 | 128 |
} |
142 | 129 |
} |
143 |
|
|
144 | 130 |
if (showCommunity) { |
145 | 131 |
this.researchCommunities.push(community); |
146 |
if (isManager) { |
|
147 |
community.isManager = true; |
|
132 |
if (community.isManager) { |
|
148 | 133 |
this.managerOfCommunities.push(community); |
149 | 134 |
} |
150 | 135 |
} |
151 |
|
|
152 | 136 |
this.status = this.errorCodes.DONE; |
153 |
|
|
154 |
if (mail != null && showCommunity) { |
|
155 |
this.subscriptions.push(this._subscribeService.isSubscribedToCommunity(this.properties, community.communityId).subscribe( |
|
156 |
res => { |
|
157 |
isSubscriber = res; |
|
158 |
if (isSubscriber) { |
|
159 |
community.isSubscribed = true; |
|
160 |
if (isManager) { |
|
161 |
this.subscriberOfCommunities.push(community); |
|
162 |
} else { |
|
163 |
this.subscriberOfCommunities.unshift(community); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
subscribedLoading--; |
|
168 |
if (subscribedLoading == 0) { |
|
169 |
this.loading = false; |
|
170 |
} |
|
171 |
}, |
|
172 |
error => { |
|
173 |
this.handleError("Error getting response if email: " + mail + " is subscribed to community with id: " + community.communityId, error); |
|
174 |
subscribedLoading--; |
|
175 |
if (subscribedLoading == 0) { |
|
176 |
this.loading = false; |
|
177 |
} |
|
178 |
})); |
|
179 |
} else { |
|
180 |
subscribedLoading--; |
|
181 |
if (subscribedLoading == 0) { |
|
182 |
this.loading = false; |
|
137 |
if (this.user && showCommunity) { |
|
138 |
community.isSubscribed = Session.isSubscribedTo('community', community.communityId, this.user); |
|
139 |
if(community.isSubscribed) { |
|
140 |
if (community.isManager) { |
|
141 |
this.subscriberOfCommunities.push(community); |
|
142 |
} else { |
|
143 |
this.subscriberOfCommunities.unshift(community); |
|
144 |
} |
|
183 | 145 |
} |
184 | 146 |
} |
147 |
this.loading = false; |
|
185 | 148 |
}); |
186 | 149 |
}, |
187 | 150 |
error => { |
... | ... | |
190 | 153 |
} |
191 | 154 |
)); |
192 | 155 |
} |
193 |
|
|
156 |
|
|
194 | 157 |
private sort(results: CommunityInfo[]) { |
195 | 158 |
results.sort((left, right): number => { |
196 | 159 |
if (!right.date || left.date > right.date) { |
... | ... | |
208 | 171 |
} |
209 | 172 |
}) |
210 | 173 |
} |
211 |
|
|
174 |
|
|
212 | 175 |
public quote(param: string): string { |
213 | 176 |
return StringUtils.quote(param); |
214 | 177 |
} |
215 |
|
|
178 |
|
|
216 | 179 |
ngOnDestroy() { |
217 | 180 |
this.subscriptions.forEach(subscription => { |
218 | 181 |
if (subscription instanceof Subscriber) { |
... | ... | |
220 | 183 |
} |
221 | 184 |
}); |
222 | 185 |
} |
223 |
|
|
186 |
|
|
224 | 187 |
private handleError(message: string, error): number { |
225 | 188 |
var code = ""; |
226 | 189 |
if (!error.status) { |
... | ... | |
228 | 191 |
} else { |
229 | 192 |
code = error.status; |
230 | 193 |
} |
231 |
|
|
194 |
|
|
232 | 195 |
console.error("Communities (component): " + message, error); |
233 |
|
|
196 |
|
|
234 | 197 |
return this.errorMessages.getErrorCode(code); |
235 | 198 |
} |
236 | 199 |
} |
Also available in: Unified diff
[Connect | Trunk]: 1. Add new roles functionllities (subscribe - role-verification). 2. Comment customization. 3. Refactor getting community logic