forked from Project-Sloth/ps-dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
166 lines (133 loc) · 6.27 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
$(document).ready(() => {
window.addEventListener('message', function (event) {
let data = event.data;
if (data.update == "newCall") {
addNewCall(data.callID, data.timer, data.data, data.isPolice);
};
});
});
const MONTH_NAMES = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
function getFormattedDate(date, prefomattedDate = false, hideYear = false) {
const day = date.getDate();
const month = MONTH_NAMES[date.getMonth()];
const year = date.getFullYear();
const hours = date.getHours();
let minutes = date.getMinutes();
if (minutes < 10) {
minutes = `0${minutes}`;
}
if (prefomattedDate) {
return `${prefomattedDate} at ${hours}:${minutes}`;
}
if (hideYear) {
return `${day}. ${month} at ${hours}:${minutes}`;
}
return `${day}. ${month} ${year}. at ${hours}:${minutes}`;
}
function timeAgo(dateParam) {
if (!dateParam) {
return null;
}
const date = typeof dateParam === 'object' ? dateParam : new Date(dateParam);
const DAY_IN_MS = 86400000;
const today = new Date();
const yesterday = new Date(today - DAY_IN_MS);
const seconds = Math.round((today - date) / 1000);
const minutes = Math.round(seconds / 60);
const isToday = today.toDateString() === date.toDateString();
const isYesterday = yesterday.toDateString() === date.toDateString();
const isThisYear = today.getFullYear() === date.getFullYear();
if (seconds < 5) {
return 'Just Now';
} else if (seconds < 60) {
return `${seconds} Seconds ago`;
} else if (seconds < 90) {
return 'About a minute ago';
} else if (minutes < 60) {
return `${minutes} Minutes ago`;
} else if (isToday) {
return getFormattedDate(date, 'Today');
} else if (isYesterday) {
return getFormattedDate(date, 'Yesterday');
} else if (isThisYear) {
return getFormattedDate(date, false, true);
}
return getFormattedDate(date);
}
function addNewCall(callID, timer, info, isPolice) {
console.log(callID, timer, info, isPolice)
const prio = info['priority']
let DispatchItem;
if (info['isDead']){
DispatchItem = `<div class="dispatch-item ${callID} dispatch-item-${info['isDead']} animate__animated"><div class="top-info-holder"><div class="call-id">#${callID}</div><div class="call-code priority-${prio}">${info.dispatchCode}</div><div class="call-name">${info.dispatchMessage}</div></div><div class="bottom-info-holder">`
}
else{
DispatchItem = `<div class="dispatch-item ${callID} dispatch-item-${isPolice} animate__animated"><div class="top-info-holder"><div class="call-id">#${callID}</div><div class="call-code priority-${prio}">${info.dispatchCode}</div><div class="call-name">${info.dispatchMessage}</div></div><div class="bottom-info-holder">`
}
// Above we are defining a default dispatch item and then we will append the data we have been sent.
if (info['time']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-clock"></span>${timeAgo(info['time'])}</div>`
}
if (info['firstStreet']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-map-pin"></span>${info['firstStreet']}</div>`
}
if (info['heading']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-share"></span>${info['heading']}</div>`
}
if (info['callsign']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-solid fa-eye"></span>${info['callsign']}</div>`
}
if (info['doorCount']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-door-open"></span>${info['doorCount']}</div>`
}
if (info['weapon']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-bullseye"></span>${info['weapon']}</div>`
}
if (info["camId"]) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-camera"></span>${info['camId']}</div>`
}
if (info['gender']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-genderless"></span>${info['gender']}</div>`
}
if (info['model'] && info['plate']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-car"></span>${info['model']}<span class="fas fa-digital-tachograph" style="margin-left: 2vh;"></span>${info['plate']}</div>`
} else if (info['plate']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-digital-tachograph"></span>${info['plate']}</div>`
} else if (info['model']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-car"></span>${info['model']}</div>`
}
if (info['firstColor']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-spray-can"></span>${info['firstColor']}</div>`
}
if (info['automaticGunfire'] == true) {
DispatchItem += `<div class="call-bottom-info"><span class="fab fa-blackberry"></span>Automatic Gunfire</div>`
}
if (info['name'] && info['number']) {
DispatchItem += `<div class="call-bottom-info"><span class="far fa-id-badge"></span>${info['name']}<span class="fas fa-mobile-alt" style="margin-left: 2vh;"></span>${info['number']}</div>`
} else if (info['number']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-mobile-alt"></span>${info['number']}</div>`
} else if (info['name']) {
DispatchItem += `<div class="call-bottom-info"><span class="far fa-id-badge"></span>${info['name']}</div>`
}
if (info['information']) {
DispatchItem += `<div class="line"></div><div class="call-bottom-info call-bottom-information"><span class="far fa-question-circle"></span>${info['information']}</div>`
}
DispatchItem += `</div></div>`
$(".dispatch-holder").prepend(DispatchItem)
var timer = 4000
if (prio == 1) {
timer = 12000
} else if (prio == 2) {
timer = 9000
}
$(`.${callID}`).addClass("animate__backInRight");
setTimeout(() => {
$(`.${callID}`).addClass("animate__backOutRight");
setTimeout(() => {
$(`.${callID}`).remove();
}, 1000);
}, timer || 4500);
};