From 014d2e9f5e81a9a3b88115b2b7f0927c5b6b8e0c Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 31 Aug 2025 23:18:44 -0600 Subject: [PATCH] Try live? --- views/event-logs.ejs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/views/event-logs.ejs b/views/event-logs.ejs index 5227f9b..76df995 100644 --- a/views/event-logs.ejs +++ b/views/event-logs.ejs @@ -51,6 +51,38 @@ // Handle incoming event log messages // Example: append to a table or display in the UI console.log('Event received:', event.data); + const tbody = document.querySelector('tbody'); + const log = JSON.parse(event.data); + + const date = new Date(log.Timestamp); + const pad = n => n.toString().padStart(2, '0'); + const yyyy = date.getFullYear(); + const mm = pad(date.getMonth() + 1); + const dd = pad(date.getDate()); + const HH = pad(date.getHours()); + const MM = pad(date.getMinutes()); + const ss = pad(date.getSeconds()); + const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; + const formattedDate = `${yyyy}-${mm}-${dd} ${HH}:${MM}:${ss} ${tz}`; + + // Use EJS-injected dataTypes for event types, directions, and reasons + const eventTypes = <%- JSON.stringify(dataTypes.EventType) %>; + const directions = <%- JSON.stringify(dataTypes.Direction) %>; + const reasons = <%- JSON.stringify(dataTypes.EventReason) %>; + + const tr = document.createElement('tr'); + tr.innerHTML = ` + ${log.Controller} + ${log.EventIndex} + ${formattedDate} + ${eventTypes[log.Type] || log.Type} + ${log.Granted ? "True" : "False"} + ${log.Door} + ${directions[log.Direction] || log.Direction} + ${log.CardNumber} + ${reasons[log.Reason] || log.Reason} + `; + tbody.insertBefore(tr, tbody.firstChild); }; ws.onopen = function() {