From a2edf88fb1c72ecb70415cfbd29bf29e9169f3a5 Mon Sep 17 00:00:00 2001 From: dan Date: Sun, 22 Mar 2020 20:41:15 -0600 Subject: [PATCH] update countdown and archived --- Client/src/app/components/home/countdown.ts | 50 +++++++++---------- .../live-stream/live-stream.component.ts | 26 +++++----- .../video-services.component.html | 8 +-- .../video-services.component.ts | 8 ++- Client/src/assets/json/videoServices.json | 10 +++- 5 files changed, 59 insertions(+), 43 deletions(-) diff --git a/Client/src/app/components/home/countdown.ts b/Client/src/app/components/home/countdown.ts index d54dbd1..429a5a4 100644 --- a/Client/src/app/components/home/countdown.ts +++ b/Client/src/app/components/home/countdown.ts @@ -72,20 +72,9 @@ export class Countdown { private updateClock() { this.showCounter = true; var now = DateTime.local(); - var nearestPast = this.getNearestPastDate(now).date; - if (nearestPast) { - var pastDiff = now.diff(nearestPast, ['minutes']); - if (pastDiff.minutes < 240) { - this.showButton = true; - this.dateDisplay = nearestPast.toLocaleString(DateTime.DATETIME_HUGE); - this.dateDisplaySmall = nearestPast.toLocaleString(DateTime.DATETIME_MED); - return; - } - } - this.showButton = false; - var nearestFuture = this.getNearestFutureDate(now).date; - if (!nearestFuture) { + var firstNonArchived = this.getFirstNonArchived(now); + if (!firstNonArchived) { this.stopClock(); this.resetToZero(); this.showCounter = false; @@ -93,26 +82,27 @@ export class Countdown { this.dateDisplaySmall = ''; return; } - var secDiff = (nearestFuture).diff(now, ['seconds']); - if (secDiff.seconds <= 0) { - this.showButton = true; - } - var hourDiff = (nearestFuture).diff(now, ['hours']); + var hourDiff = (firstNonArchived.date).diff(now, ['hours']); if (hourDiff.hours >= 48) { this.showCounter = false; this.dateDisplay = ''; this.dateDisplaySmall = ''; return; - } + } - var diff = (nearestFuture).diff(now, ['days', 'hours', 'minutes', 'seconds']); + var secDiff = (firstNonArchived.date).diff(now, ['seconds']); + if (secDiff.seconds <= 0) { + this.showButton = true; + } + + var diff = (firstNonArchived.date).diff(now, ['days', 'hours', 'minutes', 'seconds']); this.days = diff.days; this.hours = diff.hours; this.minutes = diff.minutes; this.seconds = Math.floor(diff.seconds); - this.dateDisplay = nearestFuture.toLocaleString(DateTime.DATETIME_HUGE); - this.dateDisplaySmall = nearestFuture.toLocaleString(DateTime.DATETIME_MED) + this.dateDisplay = firstNonArchived.date.toLocaleString(DateTime.DATETIME_HUGE); + this.dateDisplaySmall = firstNonArchived.date.toLocaleString(DateTime.DATETIME_MED) } private startClock() { @@ -123,13 +113,23 @@ export class Countdown { clearInterval(this.clock); } + private getFirstNonArchived(now: DateTime): VideoService { + if (this.services.length === 0) return null; + const nonArchived = this.services.filter(s => s.archived === false); + if (!nonArchived || nonArchived.length === 0) return null; + return nonArchived[0]; + } + private getNearestPastDate(now: DateTime): VideoService { if (this.services.length === 0) return null; + const archived = this.services.filter(s => s.archived === false); + if (!archived || archived.length === 0) return null; + var now = now || DateTime.local(); - var nearestIndex = this.services.findIndex(s => s.date > now); + var nearestIndex = archived.findIndex(s => s.date > now); if (nearestIndex === 0) return null; - if (nearestIndex === -1) return this.services[this.services.length - 1]; - return this.services[nearestIndex - 1]; + if (nearestIndex === -1) return archived[archived.length - 1]; + return archived[nearestIndex - 1]; } private getNearestFutureDate(now: DateTime): VideoService { diff --git a/Client/src/app/components/live-stream/live-stream.component.ts b/Client/src/app/components/live-stream/live-stream.component.ts index 30e5695..c34290c 100644 --- a/Client/src/app/components/live-stream/live-stream.component.ts +++ b/Client/src/app/components/live-stream/live-stream.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { VideoServices } from '../home/video-services'; +import { DateTime } from "luxon"; @Component({ selector: 'live-stream-component', @@ -30,9 +31,16 @@ export class LiveStreamComponent implements OnInit { ngOnInit() { this.interval = setInterval(() => { this.http.get('assets/json/videoServices.json').subscribe(res => { - var nonArchivedReady = res.videos.filter(v => v.archived === false); - if (nonArchivedReady && nonArchivedReady.length > 0) { - var service = nonArchivedReady[0]; + res.videos = res.videos.filter(v => v.archived === false); + res.videos.forEach(v => v.date = DateTime.fromISO(v.date, {zone: 'America/Denver'})); + res.videos.sort((a, b) => { + if (a.date < b.date) return -1; + if (a.date === b.date) return 0; + return 1; + }); + var service = res.videos[0]; + + if (service) { this.message = (service).message; if (service.isReady === true) { this.showVideo = true; @@ -40,17 +48,11 @@ export class LiveStreamComponent implements OnInit { this.videoSrc = service.src; clearInterval(this.interval); } - } + } else { + this.message = 'No Live Services'; + } }); }, 3000); - - // setTimeout(() => { - // this.isReady = true; - // this.showVideo = true; - // this.videoSrc = ''; - // this.videoSrc = this.videoSrc; - // clearInterval(this.interval); - // }, 12000) } diff --git a/Client/src/app/components/video-services/video-services.component.html b/Client/src/app/components/video-services/video-services.component.html index 851f402..4852c9b 100644 --- a/Client/src/app/components/video-services/video-services.component.html +++ b/Client/src/app/components/video-services/video-services.component.html @@ -1,11 +1,11 @@
-
- - +