1
|
import {Component, OnInit} from '@angular/core';
|
2
|
import { SimpleSubscriptionDesc } from '../../domain/typeScriptClasses';
|
3
|
import { AuthenticationService } from '../../services/authentication.service';
|
4
|
import { BrokerService } from '../../services/broker.service';
|
5
|
import { deletingSubscription, deletingSubscriptionError, deletingSubscriptionSuccess,
|
6
|
loadingSubscriptions, noServiceMessage, noSubscriptionsFound } from '../../domain/shared-messages';
|
7
|
|
8
|
@Component ({
|
9
|
selector: 'app-content-notifications',
|
10
|
templateUrl: 'content-notifications.component.html'
|
11
|
})
|
12
|
|
13
|
export class ContentNotificationsComponent implements OnInit {
|
14
|
errorMessage: string;
|
15
|
successMessage: string;
|
16
|
loadingMessage: string;
|
17
|
noSubscriptions: string;
|
18
|
|
19
|
subscrOfUser: Map<string, SimpleSubscriptionDesc[]> = new Map<string, SimpleSubscriptionDesc[]>();
|
20
|
subKeys: string[];
|
21
|
|
22
|
constructor(private authService: AuthenticationService,
|
23
|
private brokerService: BrokerService) {}
|
24
|
|
25
|
ngOnInit() {
|
26
|
this.getSubscriptions();
|
27
|
}
|
28
|
|
29
|
getSubscriptions() {
|
30
|
this.errorMessage = '';
|
31
|
this.loadingMessage = loadingSubscriptions;
|
32
|
this.subKeys = [];
|
33
|
this.brokerService.getSimpleSubscriptionsOfUser(this.authService.getUserEmail()).subscribe(
|
34
|
subscrs => this.subscrOfUser = subscrs,
|
35
|
error => {
|
36
|
console.log(`getSimpleSubscriptions returned error`);
|
37
|
console.log(error);
|
38
|
this.loadingMessage = '';
|
39
|
this.errorMessage = noServiceMessage;
|
40
|
},
|
41
|
() => {
|
42
|
this.loadingMessage = '';
|
43
|
for (const key in this.subscrOfUser) {
|
44
|
this.subKeys.push(key);
|
45
|
console.log(key);
|
46
|
}
|
47
|
if (!this.subKeys.length) {
|
48
|
this.noSubscriptions = noSubscriptionsFound;
|
49
|
}
|
50
|
}
|
51
|
);
|
52
|
}
|
53
|
|
54
|
deleteSubscription(key: string) {
|
55
|
this.loadingMessage = deletingSubscription;
|
56
|
this.successMessage = '';
|
57
|
this.errorMessage = '';
|
58
|
this.brokerService.unsubscribe(key).subscribe(
|
59
|
response => console.log(`unsubscribe responded with ${response}`),
|
60
|
error => {
|
61
|
console.log(error);
|
62
|
this.loadingMessage = '';
|
63
|
this.errorMessage = deletingSubscriptionError;
|
64
|
},
|
65
|
() => {
|
66
|
this.loadingMessage = '';
|
67
|
this.successMessage = deletingSubscriptionSuccess;
|
68
|
this.getSubscriptions();
|
69
|
}
|
70
|
|
71
|
);
|
72
|
}
|
73
|
|
74
|
}
|