1
|
import { Component, OnInit } from '@angular/core';
|
2
|
import { ActivatedRoute } from '@angular/router';
|
3
|
import { BrokerService } from '../../services/broker.service';
|
4
|
import { loadingEvents, noEventsForTopic, noServiceMessage } from '../../domain/shared-messages';
|
5
|
import { EventsPage } from '../../domain/typeScriptClasses';
|
6
|
|
7
|
@Component ({
|
8
|
selector: 'app-content-notifications-of-subscription',
|
9
|
templateUrl: 'content-notifications-of-subscription.component.html'
|
10
|
})
|
11
|
|
12
|
export class ContentNotificationsOfSubscriptionComponent implements OnInit {
|
13
|
noEvents: string;
|
14
|
errorMessage: string;
|
15
|
loadingMessage: string;
|
16
|
|
17
|
subId: string;
|
18
|
topic: string;
|
19
|
eventsPage: EventsPage;
|
20
|
|
21
|
constructor(private route: ActivatedRoute,
|
22
|
private brokerService: BrokerService) {}
|
23
|
|
24
|
ngOnInit () {
|
25
|
this.subId = this.route.snapshot.paramMap.get('id');
|
26
|
this.getEventsPage(0);
|
27
|
}
|
28
|
|
29
|
getEventsPage(page: number) {
|
30
|
this.noEvents = '';
|
31
|
this.errorMessage = '';
|
32
|
this. loadingMessage = loadingEvents;
|
33
|
this.brokerService.getNotificationsBySubscriptionId(this.subId, page,10).subscribe(
|
34
|
events => this.eventsPage = events,
|
35
|
error => {
|
36
|
this.loadingMessage = '';
|
37
|
this.errorMessage = noServiceMessage;
|
38
|
console.log(error);
|
39
|
},
|
40
|
() => {
|
41
|
this.loadingMessage = '';
|
42
|
console.log(this.eventsPage);
|
43
|
if (!this.eventsPage.total)
|
44
|
this.noEvents = noEventsForTopic;
|
45
|
this.getCorrectTopic();
|
46
|
}
|
47
|
);
|
48
|
}
|
49
|
|
50
|
|
51
|
goToNextPage(){
|
52
|
if(this.eventsPage.currPage < this.eventsPage.totalPages) {
|
53
|
console.log(`Get me page ${this.eventsPage.currPage+1}!`);
|
54
|
this.getEventsPage(this.eventsPage.currPage+1);
|
55
|
}
|
56
|
}
|
57
|
|
58
|
goToPreviousPage(){
|
59
|
if(this.eventsPage.currPage > 0) {
|
60
|
console.log(`Get me page ${this.eventsPage.currPage-1}!`);
|
61
|
this.getEventsPage(this.eventsPage.currPage-1);
|
62
|
}
|
63
|
}
|
64
|
|
65
|
|
66
|
getCorrectTopic() {
|
67
|
let temp = this.eventsPage.topic.split('/');
|
68
|
this.topic = temp[0];
|
69
|
for (let i=1; i<temp.length; i++){
|
70
|
this.topic += ` | ${temp[i]}`;
|
71
|
}
|
72
|
}
|
73
|
}
|