From a36441675c1718308f1221c52845155ec2cbd03f Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Fri, 19 Jul 2024 15:00:09 +0200 Subject: [PATCH] Fixed the bug mentioned by Lars and followed up on most of the other comments --- assets/index.js | 47 +++++++++++++++++++---------------------- assets/style.css | 2 +- main.go | 4 +++- opencast-ca-display.yml | 1 + 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/assets/index.js b/assets/index.js index 2b03314..b899f07 100644 --- a/assets/index.js +++ b/assets/index.js @@ -1,5 +1,5 @@ var config = null; -var calendar = updateCalendar(); +updateCalendar(); var is_active = null; /** @@ -47,50 +47,47 @@ function updateTimer() { } return response.json() }).then(capturing => { - console.log('capturing', capturing); - if(is_active != capturing && !capturing){ - updateCalendar() - } + console.debug('capturing', capturing); is_active = capturing; updateView(capturing ? config.capturing : config.idle); }) } function parseCalendar(active){ - // Do we want 'Startet/Endet in' or 'Startet/Endet um'? - let diff = 0; - let t = 0; + let time_remaining = 0; + console.debug('Is Active? ', is_active); + const event_time = is_active ? calendar[0].End : calendar[0].Start; now = Date.now(); if (calendar.length > 0){ - t = is_active ? calendar[0].End : calendar[0].Start; - diff = t - now; - console.debug('Diff ', diff, t, now); + // TODO Maybe switch 'is_active' to 'capturing' here? + //t = is_active ? calendar[0].End : calendar[0].Start; + time_remaining = event_time - now; + console.debug('Time Remaining: ', time_remaining, event_time, now); } else { console.debug('Calendar is empty'); - + if(!is_active){ + return active.none; + } } - - hours = (diff > 0) ? Math.floor(diff / (1000 * 60 * 60)) : 0; - minutes = (diff > 0) ? Math.floor((diff / (1000 * 60)) % 60) : 0; - seconds = (diff > 0) ? Math.floor((diff / 1000) % 60) : 0; - + + hours = (time_remaining > 0) ? Math.floor(time_remaining / (1000 * 60 * 60)) : 0; + minutes = (time_remaining > 0) ? Math.floor((time_remaining / (1000 * 60)) % 60) : 0; + seconds = (time_remaining > 0) ? Math.floor((time_remaining / 1000) % 60) : 0; + hours = (hours < 10) ? '0' + hours : hours; minutes = (minutes < 10) ? '0' + minutes : minutes; seconds = (seconds < 10) ? '0' + seconds : seconds; - - console.debug('Remaining ', diff/1000); - if (calendar.length == 0 && !is_active) { - return 'Keine Aufzeichnung geplant'; - } else { - return (hours > 0) ? active.info + ' ' + hours + ':' + minutes + ':' + seconds : active.info + ' ' + minutes + ':' + seconds; - } + + time_remaining = `${hours}:${minutes}:${seconds}`; + console.debug('Compare ', is_active, now, event_time); + return (is_active && now < calendar[0].Start) ? "" : active.info + ' ' + time_remaining; } function updateCalendar() { fetch("/calendar") .then(response => { - console.debug('Calednar fetched; Status ', response.status) + console.debug('Calendar fetched; Status ', response.status); return response.json()}) .then(json => { console.log('Calendar ', json); diff --git a/assets/style.css b/assets/style.css index f8facdc..666ba96 100644 --- a/assets/style.css +++ b/assets/style.css @@ -32,9 +32,9 @@ body { align-items: center; position: absolute; top: 0; - bottom: 75; left: 0; right: 0; padding: 3vw; font-size: 3vw; + font-weight: 500; } \ No newline at end of file diff --git a/main.go b/main.go index 61567af..78f17d4 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,7 @@ type DisplayConfig struct { Background string `json:"background"` Image string `json:"image"` Info string `json:"info"` + Empty string `json:"none"` } type Config struct { @@ -154,7 +155,7 @@ func setupRouter() *gin.Engine { r.GET("/calendar", func(c *gin.Context) { client := &http.Client{} // Cutoff is set to 24 hours from now - cutoff := time.Now().UnixMilli() + int64(86400000) + cutoff := time.Now().UnixMilli() + 86400000 url := config.Opencast.Url + "/recordings/calendar.json?agentid=" + config.Opencast.Agent + "&cutoff=" + fmt.Sprint(cutoff) + "×tamp=true" req, err := http.NewRequest("GET", url, nil) req.SetBasicAuth(config.Opencast.Username, config.Opencast.Password) @@ -172,6 +173,7 @@ func setupRouter() *gin.Engine { bodyText, err := io.ReadAll(resp.Body) s := string([]byte(bodyText)) + start := regexp.MustCompile(`"startDate":[\d]+`) end := regexp.MustCompile(`"endDate":[\d]+`) t := regexp.MustCompile(`"event.title":"[^"]+"`) diff --git a/opencast-ca-display.yml b/opencast-ca-display.yml index 1485737..dbbf0a1 100644 --- a/opencast-ca-display.yml +++ b/opencast-ca-display.yml @@ -111,6 +111,7 @@ display: bdf+Ja02rbN0Tm63v7bb1/63qhYAAAAAAAAAAAAAAAAAAAAAAAAAAIDY8w9T Gxe/25sMhQAAAABJRU5ErkJggg== info: Nächste Aufzeichnung in + empty: Keine Aufzeichnung geplant unknown: text: Unknown