1 |
50041
|
myrto.kouk
|
import {Component, OnInit} from "@angular/core";
|
2 |
50883
|
myrto.kouk
|
import { SimpleSubscriptionDesc, Subscription } from '../../domain/typeScriptClasses';
|
3 |
50746
|
myrto.kouk
|
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 |
50041
|
myrto.kouk
|
|
10 |
|
|
@Component ({
|
11 |
|
|
selector: 'app-content-notifications',
|
12 |
|
|
templateUrl: 'content-notifications.component.html'
|
13 |
|
|
})
|
14 |
|
|
|
15 |
|
|
export class ContentNotificationsComponent implements OnInit {
|
16 |
50746
|
myrto.kouk
|
errorMessage: string;
|
17 |
|
|
successMessage: string;
|
18 |
|
|
loadingMessage: string;
|
19 |
|
|
noSubscriptions: string;
|
20 |
50041
|
myrto.kouk
|
|
21 |
51751
|
myrto.kouk
|
subscrOfUser: Map<string,SimpleSubscriptionDesc[]> = new Map<string,SimpleSubscriptionDesc[]>();
|
22 |
50746
|
myrto.kouk
|
subKeys: string[] = [];
|
23 |
50041
|
myrto.kouk
|
|
24 |
50746
|
myrto.kouk
|
constructor(private authService: AuthenticationService,
|
25 |
|
|
private brokerService: BrokerService) {}
|
26 |
|
|
|
27 |
|
|
ngOnInit() {
|
28 |
|
|
this.getSubscriptions();
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
getSubscriptions() {
|
32 |
|
|
this.loadingMessage = loadingSubscriptions;
|
33 |
51275
|
myrto.kouk
|
this.brokerService.getSimpleSubscriptionsOfUser(this.authService.getUserEmail()).subscribe(
|
34 |
50746
|
myrto.kouk
|
subscrs => this.subscrOfUser = subscrs,
|
35 |
|
|
error => {
|
36 |
51751
|
myrto.kouk
|
console.log(`getSimpleSubscriptions returned error`);
|
37 |
50746
|
myrto.kouk
|
console.log(error);
|
38 |
|
|
this.loadingMessage = '';
|
39 |
|
|
this.errorMessage = noServiceMessage;
|
40 |
|
|
},
|
41 |
|
|
() => {
|
42 |
|
|
this.loadingMessage = '';
|
43 |
51240
|
myrto.kouk
|
for (let key in this.subscrOfUser) {
|
44 |
50765
|
myrto.kouk
|
this.subKeys.push(key);
|
45 |
|
|
console.log(key);
|
46 |
|
|
}
|
47 |
|
|
if (!this.subKeys.length) {
|
48 |
50746
|
myrto.kouk
|
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 |
|
|
}
|
69 |
|
|
|
70 |
|
|
);
|
71 |
|
|
}
|
72 |
|
|
|
73 |
50041
|
myrto.kouk
|
}
|