Revision 60454
Added by Konstantinos Triantafyllou over 3 years ago
subscribe.component.ts | ||
---|---|---|
4 | 4 |
import {AlertModal} from '../../openaireLibrary/utils/modal/alert'; |
5 | 5 |
|
6 | 6 |
import {CommunityService} from '../../openaireLibrary/connect/community/community.service'; |
7 |
import {SubscribeService} from '../../openaireLibrary/utils/subscribe/subscribe.service'; |
|
8 | 7 |
import {EmailService} from "../../openaireLibrary/utils/email/email.service"; |
9 |
import {User} from '../../openaireLibrary/login/utils/helper.class'; |
|
8 |
import {Session, User} from '../../openaireLibrary/login/utils/helper.class';
|
|
10 | 9 |
|
11 | 10 |
import {Email} from "../../openaireLibrary/utils/email/email"; |
12 | 11 |
import {Composer} from "../../openaireLibrary/utils/email/composer"; |
... | ... | |
15 | 14 |
import {Subscriber, Subscription} from "rxjs"; |
16 | 15 |
import {properties} from "../../../environments/environment"; |
17 | 16 |
import {UserRegistryService} from "../../openaireLibrary/services/user-registry.service"; |
17 |
import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe.service"; |
|
18 | 18 |
|
19 | 19 |
declare var UIkit: any; |
20 | 20 |
|
21 | 21 |
@Component({ |
22 | 22 |
selector: 'subscribe', |
23 | 23 |
template: ` |
24 |
|
|
25 | 24 |
<span *ngIf="subscribed != null && !showNumbers && showTemplate"> |
26 | 25 |
<div *ngIf="!subscribed && showLoginAlert" class="uk-alert-warning uk-animation-slide-bottom" uk-alert=""> |
27 | 26 |
<a class="uk-alert-close" uk-close></a> |
28 | 27 |
<p>Please login first to subscribe</p> |
29 | 28 |
</div> |
30 |
<button *ngIf="!subscribed" |
|
31 |
[class]="'uk-button portal-button uk-button-small uk-width-1-1 ' + (loading ? ' uk-disabled' : '')" |
|
29 |
<button *ngIf="loading" class="uk-button portal-button-reverse uk-button-small uk-width-1-1"> |
|
30 |
<span class="uk-icon"><loading [top_margin]="false" [size]="'small'" [color]="null"></loading></span> |
|
31 |
</button> |
|
32 |
<button *ngIf="!subscribed && !loading" class="uk-button portal-button uk-button-small uk-width-1-1" |
|
32 | 33 |
(click)="subscribe()"> |
33 | 34 |
<span class="uk-icon uk-flex uk-flex-middle"> |
34 | 35 |
<svg height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> |
... | ... | |
39 | 40 |
<span class="space">Subscribe</span> |
40 | 41 |
</span> |
41 | 42 |
</button> |
42 |
<button *ngIf="subscribed" |
|
43 |
[class]="'subscribed-button uk-button uk-button-small uk-width-1-1 ' + (loading ? ' uk-disabled' : '')" |
|
43 |
<button *ngIf="subscribed && !loading" class="subscribed-button uk-button uk-button-small uk-width-1-1" |
|
44 | 44 |
(click)="confirmOpen()"> |
45 | 45 |
<span class="uk-icon uk-flex uk-flex-middle"> |
46 | 46 |
<svg height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> |
... | ... | |
52 | 52 |
</span> |
53 | 53 |
</button> |
54 | 54 |
</span> |
55 |
|
|
56 |
<span *ngIf="showNumbers && subscribers !=null && subscribers > 0 && showTemplate" class="uk-display-inline-block"> |
|
57 |
<span class="lowOpacityColor uk-text-muted">Members: </span> {{subscribers}} |
|
55 |
<span *ngIf="showNumbers && members > 0 && showTemplate" class="uk-display-inline-block"> |
|
56 |
<span class="lowOpacityColor uk-text-muted">Members: </span> {{members}} |
|
58 | 57 |
</span> |
59 | 58 |
<modal-alert (alertOutput)="confirmClose($event)"> |
60 | 59 |
</modal-alert> |
61 | 60 |
` |
62 | 61 |
}) |
63 |
|
|
64 | 62 |
export class SubscribeComponent { |
65 | 63 |
// @Input() showSubscribe:boolean = true; |
66 | 64 |
@Input() showNumbers: boolean; |
... | ... | |
73 | 71 |
|
74 | 72 |
loading: boolean = false; |
75 | 73 |
subscribed: boolean = null; |
76 |
@Input() properties: EnvProperties; |
|
77 |
subscribers: number = null;
|
|
74 |
@Input() properties: EnvProperties = properties;
|
|
75 |
members: number = 0;
|
|
78 | 76 |
@Output() countSubscribersEvent = new EventEmitter(); |
79 | 77 |
showLoginAlert: Boolean = false; |
80 | 78 |
@ViewChild(AlertModal) alert; |
... | ... | |
83 | 81 |
subs: Subscription[] = []; |
84 | 82 |
|
85 | 83 |
constructor(private route: ActivatedRoute, |
86 |
private _subscribeService: SubscribeService, |
|
87 | 84 |
private _emailService: EmailService, |
88 | 85 |
private _communityService: CommunityService, |
89 | 86 |
private router: Router, |
87 |
private subscribeService: SubscribeService, |
|
90 | 88 |
private userManagementService: UserManagementService, |
91 |
private userRegistryService: UserRegistryService |
|
92 |
) { |
|
89 |
private userRegistryService: UserRegistryService) { |
|
93 | 90 |
} |
94 | 91 |
|
95 | 92 |
public ngOnInit() { |
96 |
if (!this.properties) { |
|
97 |
this.properties = properties; |
|
98 |
} |
|
93 |
this.subs.push(this.subscribeService.getLoading().subscribe(loading => { |
|
94 |
this.loading = loading; |
|
95 |
})); |
|
96 |
this.subs.push(this.subscribeService.getMembers().subscribe(members => { |
|
97 |
this.members = members; |
|
98 |
this.countSubscribersEvent.emit({ |
|
99 |
value: this.members |
|
100 |
}); |
|
101 |
})); |
|
99 | 102 |
if (!this.showNumbers) { |
100 | 103 |
this.subs.push(this.userManagementService.getUserInfo().subscribe( |
101 | 104 |
user => { |
... | ... | |
106 | 109 |
} else { |
107 | 110 |
this.init(); |
108 | 111 |
} |
109 |
//this.init(); |
|
110 | 112 |
} |
111 | 113 |
|
112 | 114 |
public ngOnDestroy() { |
... | ... | |
118 | 120 |
} |
119 | 121 |
|
120 | 122 |
private isSubscribed() { |
121 |
// this.subscribed = Session.isSubscribedTo('community', this.communityId, this.user); |
|
122 |
// if (!this.subscribed) { |
|
123 |
this.subs.push(this._subscribeService.isSubscribed.subscribe( |
|
124 |
res => { |
|
125 |
this.subscribed = res; |
|
126 |
if (this.subscribed) { |
|
127 |
this.subscribeEvent.emit({ |
|
128 |
value: "ok" |
|
129 |
}); |
|
130 |
} |
|
131 |
} |
|
132 |
)); |
|
133 |
// } else { |
|
134 |
// if (this.subscribed) { |
|
135 |
// this.subscribeEvent.emit({ |
|
136 |
// value: "ok" |
|
137 |
// }); |
|
138 |
// } |
|
139 |
// } |
|
123 |
this.subscribed = Session.isSubscribedTo('community', this.communityId, this.user); |
|
140 | 124 |
} |
141 | 125 |
|
142 | 126 |
private init() { |
... | ... | |
146 | 130 |
this.subscribed = false; |
147 | 131 |
} else { |
148 | 132 |
if (this.communityId) { |
149 |
this._subscribeService.initIsSubscribedToCommunity(this.properties, this.communityId); |
|
150 | 133 |
this.isSubscribed(); |
151 | 134 |
} |
152 | 135 |
} |
153 | 136 |
} else { |
154 | 137 |
if (this.communityId) { |
155 |
//if (properties.environment !== 'development') { |
|
156 |
this.subs.push(this._subscribeService.getNumberOfCommunitySubscribers(this.properties, this.communityId).subscribe( |
|
157 |
res => { |
|
158 |
this.subscribers = (res && res.value) ? res.value : 0;//(res && res.subscribers && res.subscribers.length) ? res.subscribers.length : 0; |
|
159 |
this.countSubscribersEvent.emit({ |
|
160 |
value: this.subscribers |
|
161 |
}); |
|
162 |
}, |
|
163 |
error => { |
|
164 |
this.handleError("Error getting community subscribers for community with id: " + this.communityId, error); |
|
165 |
})); |
|
166 |
// } else { |
|
167 |
// this.subs.push(this.userRegistryService.getSubscribersCount('community', this.communityId).subscribe(res => { |
|
168 |
// this.subscribers = (res && res.response) ? res.response : 0; |
|
169 |
// this.countSubscribersEvent.emit({ |
|
170 |
// value: this.subscribers |
|
171 |
// }); |
|
172 |
// }, |
|
173 |
// error => { |
|
174 |
// this.handleError("Error getting community subscribers for community with id: " + this.communityId, error); |
|
175 |
// })); |
|
176 |
// } |
|
138 |
this.subscribeService.setLoading(true); |
|
139 |
this.subs.push(this.userRegistryService.getMembersCount('community', this.communityId).subscribe(res => { |
|
140 |
this.subscribeService.setMembers((res && res.response) ? res.response : 0); |
|
141 |
this.subscribeService.setLoading(false); |
|
142 |
}, |
|
143 |
error => { |
|
144 |
this.handleError("Error getting community subscribers for community with id: " + this.communityId, error); |
|
145 |
})); |
|
177 | 146 |
} |
178 | 147 |
} |
179 | 148 |
if (this.communityId) { |
180 | 149 |
this.emailToInformManagers = {body: "", subject: "", recipients: []}; |
181 |
|
|
182 |
this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI + this.communityId).subscribe( |
|
150 |
this.subs.push(this._communityService.getCommunityAsObservable().subscribe( |
|
183 | 151 |
community => { |
184 | 152 |
this.community = community; |
185 | 153 |
}, |
... | ... | |
211 | 179 |
} |
212 | 180 |
|
213 | 181 |
subscribe() { |
214 |
var email = (this.user) ? this.user.email : null; |
|
215 |
if (email == null) { |
|
182 |
if (!this.user) { |
|
216 | 183 |
this.subscribed = false; |
217 | 184 |
// this.showLoginAlert = true; |
218 | 185 |
this.router.navigate(['/user-info'], { |
... | ... | |
222 | 189 |
} |
223 | 190 |
}); |
224 | 191 |
} else { |
225 |
this.loading = true; |
|
226 |
// this.showLoginAlert = false; |
|
227 |
// if(properties.environment === 'development') { |
|
228 |
// this.subs.push(this.userRegistryService.subscribeTo('community', this.communityId).subscribe(res => { |
|
229 |
// this.userManagementService.updateUserInfo(); |
|
230 |
// this.loading = false; |
|
231 |
// this.successfulSubscribe(email); |
|
232 |
// },error => { |
|
233 |
// this.loading = false; |
|
234 |
// UIkit.notification({ |
|
235 |
// message: '<strong>An error occurred. Please try again!<strong>', |
|
236 |
// status: 'warning', |
|
237 |
// timeout: 3000, |
|
238 |
// pos: 'top-center' |
|
239 |
// }); |
|
240 |
// //console.log(error) |
|
241 |
// this.handleError("Error subscribing email: " + email + " from community with id: " + this.communityId, error); |
|
242 |
// })); |
|
243 |
// } |
|
244 |
this.subs.push(this._subscribeService.subscribeToCommunity(this.properties, this.communityId).subscribe( |
|
245 |
res => { |
|
246 |
this.loading = false; |
|
247 |
if (res.status && res.status != 200) { |
|
248 |
this.subscribeEvent.emit({ |
|
249 |
value: "error" |
|
250 |
}); |
|
251 |
UIkit.notification({ |
|
252 |
message: '<strong>An error occurred. Please try again!<strong>', |
|
253 |
status: 'warning', |
|
254 |
timeout: 3000, |
|
255 |
pos: 'top-center' |
|
256 |
}); |
|
257 |
} else { |
|
258 |
this.successfulSubscribe(email); |
|
259 |
} |
|
260 |
}, |
|
261 |
error => { |
|
262 |
this.loading = false; |
|
263 |
this.subscribeEvent.emit({ |
|
264 |
value: "error" |
|
265 |
}); |
|
266 |
UIkit.notification({ |
|
267 |
message: '<strong>An error occurred. Please try again!<strong>', |
|
268 |
status: 'warning', |
|
269 |
timeout: 3000, |
|
270 |
pos: 'top-center' |
|
271 |
}); |
|
272 |
//console.log(error) |
|
273 |
this.handleError("Error subscribing email: " + email + " to community with id: " + this.communityId, error); |
|
274 |
})); |
|
192 |
this.subscribeService.setLoading(true); |
|
193 |
this.showLoginAlert = false; |
|
194 |
this.subs.push(this.userRegistryService.subscribeTo('community', this.communityId).subscribe(res => { |
|
195 |
this.userManagementService.updateUserInfo(); |
|
196 |
this.subscribeService.setMembers(this.members + 1); |
|
197 |
this.subscribeService.setLoading(false); |
|
198 |
this.successfulSubscribe(this.user.email); |
|
199 |
}, error => { |
|
200 |
this.subscribeService.setLoading(false); |
|
201 |
UIkit.notification({ |
|
202 |
message: '<strong>An error occurred. Please try again!<strong>', |
|
203 |
status: 'warning', |
|
204 |
timeout: 3000, |
|
205 |
pos: 'top-center' |
|
206 |
}); |
|
207 |
//console.log(error) |
|
208 |
this.handleError("Error subscribing email: " + this.user.email + " from community with id: " + this.communityId, error); |
|
209 |
})); |
|
275 | 210 |
} |
276 | 211 |
} |
277 | 212 |
|
... | ... | |
280 | 215 |
if (email == null) { |
281 | 216 |
this.subscribed = false; |
282 | 217 |
} else { |
283 |
this.loading = true; |
|
284 |
// if(properties.environment === 'development') { |
|
285 |
// this.subs.push(this.userRegistryService.unsubscribeFrom('community', this.communityId).subscribe(res => { |
|
286 |
// this.userManagementService.updateUserInfo(); |
|
287 |
// this.loading = false; |
|
288 |
// this.subscribed = false; |
|
289 |
// },error => { |
|
290 |
// this.loading = false; |
|
291 |
// UIkit.notification({ |
|
292 |
// message: '<strong>An error occurred. Please try again!<strong>', |
|
293 |
// status: 'warning', |
|
294 |
// timeout: 3000, |
|
295 |
// pos: 'top-center' |
|
296 |
// }); |
|
297 |
// //console.log(error) |
|
298 |
// this.handleError("Error unsubscribing email: " + email + " from community with id: " + this.communityId, error); |
|
299 |
// })); |
|
300 |
// } |
|
301 |
this.subs.push(this._subscribeService.unSubscribeToCommunity(this.properties, this.communityId).subscribe( |
|
302 |
res => { |
|
303 |
this.loading = false; |
|
304 |
if (res.status && res.status != 200) { |
|
305 |
UIkit.notification({ |
|
306 |
message: '<strong>An error occurred. Please try again!<strong>', |
|
307 |
status: 'warning', |
|
308 |
timeout: 3000, |
|
309 |
pos: 'top-center' |
|
310 |
}); |
|
311 |
} else { |
|
312 |
//console.log(res); |
|
313 |
if (this.subscribed) { |
|
314 |
this.subscribed = false; |
|
315 |
} |
|
316 |
} |
|
317 |
}, |
|
318 |
error => { |
|
319 |
this.loading = false; |
|
320 |
UIkit.notification({ |
|
321 |
message: '<strong>An error occurred. Please try again!<strong>', |
|
322 |
status: 'warning', |
|
323 |
timeout: 3000, |
|
324 |
pos: 'top-center' |
|
325 |
}); |
|
326 |
//console.log(error) |
|
327 |
this.handleError("Error unsubscribing email: " + email + " from community with id: " + this.communityId, error); |
|
328 |
})); |
|
218 |
this.subscribeService.setLoading(true); |
|
219 |
this.subs.push(this.userRegistryService.unsubscribeFrom('community', this.communityId).subscribe(res => { |
|
220 |
this.userManagementService.updateUserInfo(); |
|
221 |
this.subscribeService.setMembers(this.members - 1); |
|
222 |
this.subscribeService.setLoading(false); |
|
223 |
this.subscribed = false; |
|
224 |
}, error => { |
|
225 |
this.subscribeService.setLoading(false); |
|
226 |
UIkit.notification({ |
|
227 |
message: '<strong>An error occurred. Please try again!<strong>', |
|
228 |
status: 'warning', |
|
229 |
timeout: 3000, |
|
230 |
pos: 'top-center' |
|
231 |
}); |
|
232 |
//console.log(error) |
|
233 |
this.handleError("Error unsubscribing email: " + email + " from community with id: " + this.communityId, error); |
|
234 |
})); |
|
329 | 235 |
} |
330 | 236 |
} |
331 | 237 |
|
Also available in: Unified diff
[Connect | Trunk]: 1. Add new roles functionllities (subscribe - role-verification). 2. Comment customization. 3. Refactor getting community logic