From fdbe02b47e400cdad0c6e0294579150590ac5c14 Mon Sep 17 00:00:00 2001 From: 4gray Date: Fri, 5 Feb 2021 00:09:00 +0100 Subject: [PATCH] feat(epg): epg program list with date navigation --- .../epg-list/epg-list.component.html | 112 ++++++++++++------ .../epg-list/epg-list.component.scss | 44 ++++--- .../epg-list/epg-list.component.spec.ts | 8 +- .../components/epg-list/epg-list.component.ts | 59 ++++++--- 4 files changed, 147 insertions(+), 76 deletions(-) diff --git a/src/app/player/components/epg-list/epg-list.component.html b/src/app/player/components/epg-list/epg-list.component.html index 66a585c5d..1c9c2201d 100644 --- a/src/app/player/components/epg-list/epg-list.component.html +++ b/src/app/player/components/epg-list/epg-list.component.html @@ -1,49 +1,87 @@ -
-
-
+ +
+
+
-
-
{{ channel?.name[0]?.value }}
- -
Playing now:
-
- {{ - playingNow - ? playingNow.title[0]?.value - : 'Live stream' - }} -
-
+
+
+ {{ channel?.name[0]?.value }} +
+
+ {{ + playingNow ? playingNow.title[0]?.value : 'Live stream' + }} +
+
+ + + {{ dateToday | momentDate: 'YYYYMMDD':'MMMM Do dddd' }} + +
+ + - -
- {{ item.start }} - {{ item.stop }} - live -
-

{{ item?.title[0]?.value }}

- -
+ + +
+ {{ item.start }} - {{ item.stop }} + live +
+

{{ item?.title[0]?.value }}

+ +
+
+ + Ooops, EPG is not available for the selected + date +
+ diff --git a/src/app/player/components/epg-list/epg-list.component.scss b/src/app/player/components/epg-list/epg-list.component.scss index 94ab206d1..9dacbad6d 100644 --- a/src/app/player/components/epg-list/epg-list.component.scss +++ b/src/app/player/components/epg-list/epg-list.component.scss @@ -12,10 +12,9 @@ .active { border-bottom: 1px dashed #666; background: linear-gradient(to top, #d2d2d2 0%, #d6d6d6 20%, rgba(255, 255, 255, 0) 100%) - } -.time, .playing-now { +.time { color: #666; border-bottom: 1px solid #ccc; font-size: 0.8em; @@ -23,29 +22,27 @@ margin-bottom: 5px; } -.epg-program-name { - overflow: hidden; - text-overflow: ellipsis; - display: -webkit-box; - -webkit-line-clamp: 1; - -webkit-box-orient: vertical; - font-size: 0.9em; -} - #channel-info { - padding:10px; border-bottom: 1px solid #ccc; box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); background-color: #ccc; -} -.channel-name { - font-weight: 800; -} + .channel-icon { + overflow: hidden; + } -mat-list { - height: calc(100vh - 110px); - overflow: auto; + .channel-name { + font-weight: 800; + } + + .program-name { + overflow: hidden; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-line-clamp: 1; + -webkit-box-orient: vertical; + font-size: 0.9em; + } } mat-selection-list { @@ -60,4 +57,13 @@ mat-selection-list { text-transform: uppercase; margin-left: 6px; font-size: 0.8em; +} + +#date-navigator { + border-top: 1px solid #999; + + .selected-date { + font-size: 0.9em; + color: #333; + } } \ No newline at end of file diff --git a/src/app/player/components/epg-list/epg-list.component.spec.ts b/src/app/player/components/epg-list/epg-list.component.spec.ts index 169fe22fa..7d241d25e 100644 --- a/src/app/player/components/epg-list/epg-list.component.spec.ts +++ b/src/app/player/components/epg-list/epg-list.component.spec.ts @@ -2,12 +2,14 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { EpgListComponent, EpgData } from './epg-list.component'; import { MatListModule } from '@angular/material/list'; -import { MockModule } from 'ng-mocks'; +import { MockModule, MockPipe } from 'ng-mocks'; import { ElectronService } from '../../../services/electron.service'; import { ElectronServiceStub } from '../../../home/home.component.spec'; import * as moment from 'moment'; import { EPG_GET_PROGRAM_DONE } from '../../../shared/ipc-commands'; import { ChannelStore } from '../../../state'; +import { MomentDatePipe } from '../../../shared/pipes/moment-date.pipe'; +import { MatIconModule } from '@angular/material/icon'; describe('EpgListComponent', () => { let component: EpgListComponent; @@ -77,8 +79,8 @@ describe('EpgListComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [EpgListComponent], - imports: [MockModule(MatListModule)], + declarations: [EpgListComponent, MockPipe(MomentDatePipe)], + imports: [MockModule(MatIconModule), MockModule(MatListModule)], providers: [ { provide: ElectronService, useClass: ElectronServiceStub }, ], diff --git a/src/app/player/components/epg-list/epg-list.component.ts b/src/app/player/components/epg-list/epg-list.component.ts index cf7f8e818..23b82df4e 100644 --- a/src/app/player/components/epg-list/epg-list.component.ts +++ b/src/app/player/components/epg-list/epg-list.component.ts @@ -37,6 +37,8 @@ export class EpgListComponent { /** Current time as formatted string */ timeNow: string; + selectedDate: string; + /** * Creates an instance of EpgListComponent * @param electronService @@ -61,25 +63,11 @@ export class EpgListComponent { */ handleEpgData(programs: { payload: EpgData }): void { if (programs.payload?.items?.length > 0) { + this.programs = programs; this.timeNow = moment(Date.now()).format('HH:mm'); this.dateToday = moment(Date.now()).format('YYYYMMDD'); this.channel = programs.payload?.channel; - this.items = programs.payload?.items - .filter((item) => - item.start.includes(this.dateToday.toString()) - ) - .map((program) => ({ - ...program, - start: moment(program.start, 'YYYYMMDDHHmm ZZ').format( - 'HH:mm' - ), - stop: moment(program.stop, 'YYYYMMDDHHmm ZZ').format( - 'HH:mm' - ), - })) - .sort((a, b) => { - return a.start.localeCompare(b.start); - }); + this.items = this.selectPrograms(programs); this.setPlayingNow(); } else { @@ -88,6 +76,42 @@ export class EpgListComponent { } } + /** + * Selects the program based on the active date + * @param programs object with all available epg programs for the active channel + */ + selectPrograms(programs: { payload: EpgData }): EpgProgram[] { + return programs.payload?.items + .filter((item) => item.start.includes(this.dateToday.toString())) + .map((program) => ({ + ...program, + start: moment(program.start, 'YYYYMMDDHHmm ZZ').format('HH:mm'), + stop: moment(program.stop, 'YYYYMMDDHHmm ZZ').format('HH:mm'), + })) + .sort((a, b) => { + return a.start.localeCompare(b.start); + }); + } + + /** + * Changes the date to update the epg list with programs + * @param direction direction to switch + */ + changeDate(direction: 'next' | 'prev'): void { + let dateToSwitch; + if (direction === 'next') { + dateToSwitch = moment(this.dateToday, 'YYYYMMDD') + .add(1, 'days') + .format('YYYYMMDD'); + } else if (direction === 'prev') { + dateToSwitch = moment(this.dateToday, 'YYYYMMDD') + .subtract(1, 'days') + .format('YYYYMMDD'); + } + this.dateToday = dateToSwitch; + this.items = this.selectPrograms(this.programs); + } + /** * Sets the playing now variable based on the current time */ @@ -99,7 +123,8 @@ export class EpgListComponent { /** * Sets the provided epg program as active and starts to play - * @param program + * @param program epg program to set + * @param isLive live stream flag */ setEpgProgram(program: EpgProgram, isLive?: boolean): void { isLive