Compare commits

..

No commits in common. "e615d6e44128cb9b55d709d3d0ce8089a95bca72" and "0c672e717abacc34072a0186475bf7523db0d84d" have entirely different histories.

2 changed files with 3 additions and 104 deletions

View file

@ -33,93 +33,6 @@ async function fetchEvents() {
setTimeout(fetchEvents, 1000);
}
dataTypes = {
DoorMode: {
1: 'NormallyOpen',
2: 'NormallyClosed',
3: 'Controlled'
},
Direction: {
1: 'In',
2: 'Out'
},
EventType: {
0: 'None',
1: 'Swipe',
2: 'Door',
3: 'Alarm',
255: 'Overwritten'
},
EventReason: {
0: 'None',
1: 'Swipe',
2: 'SwipeOpen',
3: 'SwipeClose',
5: 'Denied',
6: 'NoAccessRights',
7: 'IncorrectPassword',
8: 'AntiPassback',
9: 'MoreCards',
10: 'FirstCardOpen',
11: 'DoorIsNormallyClosed',
12: 'Interlock',
13: 'NotInAllowedTimePeriod',
15: 'InvalidTimezone',
18: 'AccessDenied',
20: 'PushbuttonOk',
23: 'DoorOpened',
24: 'DoorClosed',
25: 'DoorOpenedSupervisorPassword',
28: 'ControllerPowerOn',
29: 'ControllerReset',
31: 'PushbuttonInvalidDoorLocked',
32: 'PushbuttonInvalidOffline',
33: 'PushbuttonInvalidInterlock',
34: 'PushbuttonInvalidThreat',
37: 'DoorOpenTooLong',
38: 'ForcedOpen',
39: 'Fire',
40: 'ForcedClosed',
41: 'TheftPrevention',
42: 'Zone24x7',
43: 'Emergency',
44: 'RemoteOpenDoor',
45: 'RemoteOpenDoorUSBReader'
}
}
const validEvents = {
1: [1,2,3,6,7],
2: [25],
3: [23,24,28,37,38,39,40,41,42,43,44,45]
}
if (process.env.EVENT_TESTING == true) {
setInterval(() => {
const eventTypes = Object.keys(validEvents);
const eventType = parseInt(eventTypes[Math.floor(Math.random() * eventTypes.length)]);
const reasons = validEvents[eventType];
const eventReason = reasons[Math.floor(Math.random() * reasons.length)];
const cardNumber = Math.floor(Math.random() * 1000000) + 1;
const granted = [5, 6, 7, 18].includes(eventReason) ? false : true;
const testEvent = {
Controller: 123456789,
EventIndex: ++lastEventIndex,
Timestamp: new Date().toISOString().replace('T', ' ').substring(0, 19),
Type: eventType,
Reason: eventReason,
Granted: granted,
CardNumber: cardNumber,
Door: 1,
Direction: eventType == 1 ? (Math.random() < 0.5 ? 1 : 2) : 0,
}
log.info(`Generated test event: ${JSON.stringify(testEvent)}`);
emitter.emit('event', testEvent);
}, 1000);
}
(async () => {
await getLastEventIndex();
await fetchEvents();

View file

@ -79,9 +79,6 @@
const reasons = <% - JSON.stringify(dataTypes.EventReason) %>;
const tr = document.createElement('tr');
if (log.Type === 3) {
tr.style.background = '#f7c5c5';
}
tr.innerHTML = `
<td>${log.Controller}</td>
<td>${log.EventIndex}</td>
@ -96,18 +93,6 @@
<td>${reasons[log.Reason] || log.Reason}</td>
`;
tbody.insertBefore(tr, tbody.firstChild);
tr.style.background = 'orange';
setTimeout(() => {
let opacity = 1;
const fade = setInterval(() => {
opacity -= 0.05;
tr.style.background = `rgba(255,165,0,${opacity})`;
if (opacity <= 0.1) {
tr.style.background = '';
clearInterval(fade);
}
}, 40);
}, 0);
};
ws.onopen = function () {
@ -143,7 +128,7 @@
</thead>
<tbody>
<% logs.forEach(function(log) { %>
<tr style="<%= log.Type === 3 ? 'background:#f7c5c5;' : '' %>"></tr>
<tr>
<td>
<%= log.Controller %>
</td>
@ -160,12 +145,13 @@
const ss = pad(date.getSeconds());
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
%>
%>
<%= `${yyyy}-${mm}-${dd} ${HH}:${MM}:${ss} ${tz}` %>
</td>
<td>
<%= dataTypes.EventType[log.Type] %>
</td>
<td style="<%= (log.Type === 1 || log.Type === 2) ? `background:${log.Granted ? '#c8f7c5' : '#f7c5c5'};` : '' %>">
<td style="<%= log.Type === 1 ? `background:${log.Granted ? '#c8f7c5' : '#f7c5c5'};` : '' %>">
<%= log.Granted ? "True" : "False" %>
</td>
<td>