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