strix

A simple web UI for motion
git clone https://www.brianlane.com/git/strix
Log | Files | Refs | LICENSE

commit ecd589b6bcbd6b8cd3c8f04a72accadadd53203f
parent 75f7e68cef25b701212b0d2b2db0e8e6dd1a57bd
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sun, 23 Apr 2023 09:10:48 -0700

Create the event title in python as part of the details

The javascript time parsing code is crap, it is taking the correct time
and returning a time one hour earlier. So just generate the title string
as part of the event details and feed it to the UI code for display
as-is.

Diffstat:
Msrc/strix/events.py | 5+++++
Msrc/strix/ui/index.html | 9+--------
2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/strix/events.py b/src/strix/events.py @@ -69,6 +69,10 @@ class EventCacheClass: if "end" in value and type(value["end"]) == type(""): value["end"] = datetime.fromisoformat(value["end"]) + # Add missing title (old cache will not have this new field) + if "title" not in value: + value["title"] = value["start"].strftime("%a %b %d %I:%M:%S %p"), + self._cache[key] = value # This can potentially remove the key just added if it is an old event @@ -289,6 +293,7 @@ def event_details(log, event_path): details = { "start": start_time, "end": end_time, + "title": start_time.strftime("%a %b %d %I:%M:%S %p"), "video": video[0], "debug_video": video[1], "thumbnail": thumbnail, diff --git a/src/strix/ui/index.html b/src/strix/ui/index.html @@ -26,13 +26,6 @@ function set_feed_src() { }); } -function nice_time_string(time_str) { - var d = new Date(time_str); - // DoW Mo Day Year - var fields = d.toDateString().split(" "); - return fields.slice(0,3).join(" ") + " " + d.toLocaleTimeString(); -} - function get_events(camera_name, offset, limit) { // The API returns the events with the oldest one first in the .events list fetch("/api/events/"+camera_name+"?offset="+offset+"&limit="+limit) @@ -43,7 +36,7 @@ function get_events(camera_name, offset, limit) { videos.forEach(video => { event = data.events[camera_name][idx]; video.href="events.html?camera="+camera_name+"&event="+event.video; - video.title=nice_time_string(event.start); + video.title=event.title; img = video.firstChild; img.src = event.thumbnail; idx++;