1 |
54479
|
myrto.kouk
|
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 |
57171
|
stefania.m
|
lastTopicEntry = '';
|
20 |
54479
|
myrto.kouk
|
eventsPage: EventsPage;
|
21 |
|
|
currentPage: number; /* DELETE WHEN getNotificationsBySubscriptionId IS FIXED AND SENDS CORRECT VALUE FOR CURRENT PAGE */
|
22 |
|
|
|
23 |
57171
|
stefania.m
|
selectedItemIndex: number;
|
24 |
|
|
|
25 |
54479
|
myrto.kouk
|
constructor(private route: ActivatedRoute,
|
26 |
|
|
private brokerService: BrokerService) {}
|
27 |
|
|
|
28 |
|
|
ngOnInit () {
|
29 |
|
|
this.subId = this.route.snapshot.paramMap.get('id');
|
30 |
|
|
this.currentPage = 0; /* DELETE WHEN getNotificationsBySubscriptionId IS FIXED AND SENDS CORRECT VALUE FOR CURRENT PAGE */
|
31 |
|
|
this.getEventsPage(0);
|
32 |
57150
|
stefania.m
|
let body = document.getElementsByTagName('body')[0];
|
33 |
|
|
body.classList.remove("top_bar_active"); //remove the class
|
34 |
|
|
body.classList.remove("page_heading_active");
|
35 |
58065
|
stefania.m
|
body.classList.remove("landing");
|
36 |
|
|
body.classList.add("dashboard");
|
37 |
54479
|
myrto.kouk
|
}
|
38 |
|
|
|
39 |
|
|
getEventsPage(page: number) {
|
40 |
|
|
this.noEvents = '';
|
41 |
|
|
this.errorMessage = '';
|
42 |
|
|
this. loadingMessage = loadingEvents;
|
43 |
|
|
this.brokerService.getNotificationsBySubscriptionId(this.subId, page, 10).subscribe(
|
44 |
|
|
events => this.eventsPage = events,
|
45 |
|
|
error => {
|
46 |
|
|
this.loadingMessage = '';
|
47 |
|
|
this.errorMessage = noServiceMessage;
|
48 |
|
|
console.log(error);
|
49 |
|
|
},
|
50 |
|
|
() => {
|
51 |
|
|
this.loadingMessage = '';
|
52 |
|
|
console.log(this.eventsPage);
|
53 |
|
|
if (!this.eventsPage.total) {
|
54 |
|
|
this.noEvents = noEventsForTopic;
|
55 |
|
|
}
|
56 |
|
|
this.getCorrectTopic();
|
57 |
57171
|
stefania.m
|
// console.log('Topic: ' + this.topic);
|
58 |
|
|
this.lastTopicEntry = this.topic.substring(this.topic.lastIndexOf('|') + 1).toLowerCase();
|
59 |
|
|
this.lastTopicEntry = this.replaceAll(this.lastTopicEntry, '_', ' ');
|
60 |
|
|
// console.log('Last topic entry: ' + this.lastTopicEntry);
|
61 |
54479
|
myrto.kouk
|
}
|
62 |
|
|
);
|
63 |
|
|
}
|
64 |
|
|
|
65 |
57171
|
stefania.m
|
replaceAll(str, find, replace) {
|
66 |
|
|
return str.replace(new RegExp(find, 'g'), replace);
|
67 |
|
|
}
|
68 |
54479
|
myrto.kouk
|
|
69 |
57171
|
stefania.m
|
|
70 |
54479
|
myrto.kouk
|
goToNextPage() {
|
71 |
|
|
/* RESTORE WHEN getNotificationsBySubscriptionId IS FIXED AND SENDS CORRECT VALUE FOR CURRENT PAGE */
|
72 |
|
|
/*if(this.eventsPage.currPage < this.eventsPage.totalPages) {
|
73 |
|
|
console.log(`Get me page ${this.eventsPage.currPage+1}!`);
|
74 |
|
|
this.getEventsPage(this.eventsPage.currPage+1);
|
75 |
|
|
}*/
|
76 |
|
|
|
77 |
|
|
/* DELETE WHEN getNotificationsBySubscriptionId IS FIXED AND SENDS CORRECT VALUE FOR CURRENT PAGE */
|
78 |
|
|
if ( (this.currentPage + 1) < this.eventsPage.totalPages) {
|
79 |
|
|
this.currentPage = this.currentPage + 1;
|
80 |
|
|
console.log(`Get me page ${this.currentPage}!`);
|
81 |
|
|
this.getEventsPage(this.currentPage);
|
82 |
58281
|
stefania.m
|
|
83 |
|
|
window.scrollTo(0, 0);
|
84 |
54479
|
myrto.kouk
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
goToPreviousPage() {
|
88 |
|
|
/* RESTORE WHEN getNotificationsBySubscriptionId IS FIXED AND SENDS CORRECT VALUE FOR CURRENT PAGE */
|
89 |
|
|
/*if(this.eventsPage.currPage > 0) {
|
90 |
|
|
console.log(`Get me page ${this.eventsPage.currPage-1}!`);
|
91 |
|
|
this.getEventsPage(this.eventsPage.currPage-1);
|
92 |
|
|
}*/
|
93 |
|
|
|
94 |
|
|
/* DELETE WHEN getNotificationsBySubscriptionId IS FIXED AND SENDS CORRECT VALUE FOR CURRENT PAGE */
|
95 |
|
|
if (this.currentPage > 0) {
|
96 |
|
|
this.currentPage = this.currentPage - 1;
|
97 |
|
|
console.log(`Get me page ${this.currentPage}!`);
|
98 |
|
|
this.getEventsPage(this.currentPage);
|
99 |
58281
|
stefania.m
|
|
100 |
|
|
window.scrollTo(0, 0);
|
101 |
54479
|
myrto.kouk
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
isHighlighted(item: any, itemList: any[]) {
|
106 |
|
|
return itemList.some(x => x === item);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
getCorrectTopic() {
|
110 |
|
|
const temp = this.eventsPage.topic.split('/');
|
111 |
|
|
this.topic = temp[0];
|
112 |
|
|
for (let i = 1; i < temp.length; i++) {
|
113 |
|
|
this.topic += ` | ${temp[i]}`;
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
57171
|
stefania.m
|
|
117 |
|
|
displayFullResultInfo(i: number) {
|
118 |
|
|
if (this.selectedItemIndex === i) {
|
119 |
|
|
this.selectedItemIndex = null;
|
120 |
|
|
} else {
|
121 |
|
|
this.selectedItemIndex = i;
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
58281
|
stefania.m
|
|
125 |
|
|
showMore(i: number) {
|
126 |
|
|
this.selectedItemIndex = i;
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
showLess(i: number) {
|
130 |
|
|
this.selectedItemIndex = null;
|
131 |
|
|
}
|
132 |
54479
|
myrto.kouk
|
}
|