From b2a2496eeb715142271c1fbfaa233988257c98cd Mon Sep 17 00:00:00 2001 From: Lars Bergqvist Date: Fri, 24 Nov 2023 06:25:46 +0100 Subject: [PATCH] Do not preload programs --- .github/workflows/buildanddeploy.yml | 1 - .../channels/channel-schedule.component.ts | 2 +- .../programs/program-details.component.html | 8 -- .../programs/program-details.component.ts | 19 ++-- .../programs/programs-list.component.html | 20 ---- .../programs/programs-list.component.ts | 48 +--------- src/app/services/programs.service.ts | 26 ++--- src/app/services/srapi.service.ts | 96 +------------------ 8 files changed, 26 insertions(+), 194 deletions(-) diff --git a/.github/workflows/buildanddeploy.yml b/.github/workflows/buildanddeploy.yml index e3f3ba0..ac1807c 100644 --- a/.github/workflows/buildanddeploy.yml +++ b/.github/workflows/buildanddeploy.yml @@ -35,7 +35,6 @@ jobs: deploy: needs: test-and-build runs-on: ubuntu-latest - if: github.ref == 'refs/heads/master' steps: - name: Checkout uses: actions/checkout@v3 diff --git a/src/app/components/channels/channel-schedule.component.ts b/src/app/components/channels/channel-schedule.component.ts index 160227b..2762fd4 100644 --- a/src/app/components/channels/channel-schedule.component.ts +++ b/src/app/components/channels/channel-schedule.component.ts @@ -105,7 +105,7 @@ export class ChannelScheduleComponent implements OnInit, OnDestroy { endtimeDate: convertFromJSONstring(s?.endtimeutc), program: s.program, imageurltemplate: s.imageurltemplate, - imageurl: s.imageurltemplate ? s.imageurltemplate + SRApiService.DefaultImagePreset : this.srApiService.getProgramImageUrlFromId(s.program.id) + imageurl: s.imageurltemplate ? s.imageurltemplate + SRApiService.DefaultImagePreset : this.srApiService.getChannelImageUrlFromId(channelId) })); } diff --git a/src/app/components/programs/program-details.component.html b/src/app/components/programs/program-details.component.html index 3198741..1e09bc6 100644 --- a/src/app/components/programs/program-details.component.html +++ b/src/app/components/programs/program-details.component.html @@ -14,14 +14,6 @@ {{'Category' | translate}}: {{getCategoryNameFromId(program.programcategory.id)}} - - - - - -
route.id) ) .subscribe(async (id: string) => { - const program = await this.srApiService.getProgramFromId(parseInt(id)); + const program = await this.programsService.fetchProgramWithId(parseInt(id)); if (program) { await this.show(program); } + console.log('todo') +// const program = await this.srApiService.getProgramFromId(parseInt(id)); +// if (program) { +// await this.show(program); +// } }); } @@ -77,12 +84,4 @@ export class ProgramDetailsComponent implements OnInit, OnDestroy { getCategoryNameFromId(id: number) { return this.srApiService.getCategoryNameFromId(id); } - - onAddToFavorites(programId: number, programName: string) { - this.srApiService.addProgramToFavorites(programId, programName); - } - - onRemoveFromFavorites(programId: number, programName: string) { - this.srApiService.removeProgramFromFavorites(programId, programName); - } } diff --git a/src/app/components/programs/programs-list.component.html b/src/app/components/programs/programs-list.component.html index 5dbd513..816b341 100644 --- a/src/app/components/programs/programs-list.component.html +++ b/src/app/components/programs/programs-list.component.html @@ -3,19 +3,6 @@ [globalFilterFields]="['name','channel.name','description']" styleClass="sr-table"> -
- - - - - - - -
-
- - - - diff --git a/src/app/components/programs/programs-list.component.ts b/src/app/components/programs/programs-list.component.ts index fedf013..2e23b5d 100644 --- a/src/app/components/programs/programs-list.component.ts +++ b/src/app/components/programs/programs-list.component.ts @@ -26,9 +26,7 @@ export class ProgramsListComponent implements OnInit, OnDestroy, AfterViewInit { private readonly storageId = 'ProgramsListState'; localState = { - showOnlyFavs: false, selectedCategory: null, - searchString: '' }; @ViewChild(Table) tableComponent: Table; @@ -47,17 +45,6 @@ export class ProgramsListComponent implements OnInit, OnDestroy, AfterViewInit { this.localState = oldState; } -// let result = await this.programsService.fetchPrograms(1,10); -// this.programs = result.programs; -// console.log(this.programs.length) - await this.fetch(0); - /* - this.srApiService.programs$.pipe(takeUntil(this.unsubscribe$)).subscribe((values: Program[]) => { - if (values) { - this.programs = []; - this.programs.push(...values); - } - });*/ this.srApiService.programCategories$.pipe(takeUntil(this.unsubscribe$)).subscribe((values: ProgramCategory[]) => { if (values) { this.categoryOptions = []; @@ -66,6 +53,8 @@ export class ProgramsListComponent implements OnInit, OnDestroy, AfterViewInit { this.categoryOptions.push(...categories); } }); + + await this.fetch(0); } async loadLazy(event: any) { @@ -73,7 +62,6 @@ export class ProgramsListComponent implements OnInit, OnDestroy, AfterViewInit { } async fetch(first: number) { - console.log(this.localState.selectedCategory) const page = first / this.pageSize + 1; let result = await this.programsService.fetchPrograms(page,this.pageSize, this.localState.selectedCategory); this.totalHits = result.pagination.totalhits; @@ -82,21 +70,7 @@ export class ProgramsListComponent implements OnInit, OnDestroy, AfterViewInit { ngAfterViewInit(): void { - if (this.tableComponent) { - if (this.localState.showOnlyFavs) { - this.tableComponent.filter(true, 'fav', 'equals'); - } else { - this.tableComponent.filter([true, false], 'fav', 'in'); - } - - if (this.localState.selectedCategory) { - this.tableComponent.filter(this.localState.selectedCategory, 'programcategory.id', 'equals'); - } - if (this.localState.searchString) { - this.tableComponent.filterGlobal(this.localState.searchString, 'contains'); - } - } } ngOnDestroy() { @@ -110,26 +84,10 @@ export class ProgramsListComponent implements OnInit, OnDestroy, AfterViewInit { this.broker.sendMessage(new ShowProgramDetailsMessage(program.id)); } - onFilterFavClicked(event, dt) { - this.localState.showOnlyFavs = event.checked; - if (this.localState.showOnlyFavs) { - dt.filter(true, 'fav', 'equals'); - } else { - dt.filter([true, false], 'fav', 'in'); - } - } - - onAddToFavorites(programId: number, programName: string) { - this.srApiService.addProgramToFavorites(programId, programName); - } - - onRemoveFromFavorites(programId: number, programName: string) { - this.srApiService.removeProgramFromFavorites(programId, programName); - } onCategoryChanged(event, dt) { if (event.value !== '') { - dt.filter(event.value, 'programcategory.id', 'equals'); + dt.filter(event.value); } } } diff --git a/src/app/services/programs.service.ts b/src/app/services/programs.service.ts index aaecbec..4be15e0 100644 --- a/src/app/services/programs.service.ts +++ b/src/app/services/programs.service.ts @@ -1,15 +1,8 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { EpisodesResult } from '../models/episodes-result'; import { SRBaseService } from './sr-base.service'; -import { RightNowEpisodes } from '../models/right-now-episodes'; -import { ScheduleResult } from '../models/schedule-result'; -import { EpisodeResult } from '../models/episode'; import { SRApiService } from './srapi.service'; import { lastValueFrom } from 'rxjs'; -import { EpisodesOverviewResult } from '../models/episodes-overview-result'; -import { EpisodeGroupResult } from '../models/episode-group-result'; -import { EpisodeOverview } from '../models/episode-overview'; import { ProgramsResult } from '../models/programs-result'; import { Program } from '../models/program'; @@ -46,8 +39,12 @@ export class ProgramsService extends SRBaseService { return res; } - /* - const progs: Program[] = programsRawResult.programs.map((p: Program) => ({ + async fetchProgramWithId(programId: number): Promise { + let url = `${this.BaseUrl}programs/${programId}?${this.FormatParam}`; + const res = await lastValueFrom(this.http.get(`${url}`)); + const p = res.program; + + const prog: any = { name: p.name, id: p.id, fav: false, @@ -58,16 +55,9 @@ export class ProgramsService extends SRBaseService { programimage: p.programimagetemplate + SRApiService.DefaultImagePreset, description: p.description, programcategory: p.programcategory - })); - - this.updateProgramsWithFavs(progs); - + }; - private async getAllPrograms(): Promise { - const params = `?${this.FormatParam}&page=1&size=10000`; - let url = `${this.BaseUrl}programs/${params}`; - return lastValueFrom(this.http.get(`${url}`)); + return prog; } - */ } diff --git a/src/app/services/srapi.service.ts b/src/app/services/srapi.service.ts index b004294..a43aa4e 100644 --- a/src/app/services/srapi.service.ts +++ b/src/app/services/srapi.service.ts @@ -2,14 +2,12 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { BehaviorSubject, lastValueFrom } from 'rxjs'; import { BookmarkChangedMessage } from '../messages/bookmark-changed.message'; -import { SuccessInfoMessage } from '../messages/success-info.message'; import { Channel } from '../models/channel'; import { Program } from '../models/program'; import { ProgramCategory } from '../models/program-category'; import { LocalStorageService } from './local-storage.service'; import { MessageBrokerService } from './message-broker.service'; import { SRBaseService } from './sr-base.service'; -import { TranslationService } from './translation.service'; @Injectable({ providedIn: 'root' @@ -17,14 +15,11 @@ import { TranslationService } from './translation.service'; export class SRApiService extends SRBaseService { private channels: Channel[]; channels$ = new BehaviorSubject(null); - private programs: Program[]; - programs$ = new BehaviorSubject(null); private programCategories: ProgramCategory[]; programCategories$ = new BehaviorSubject(null); private currentlyPlaying: string; - private programFavs = new Set(); private episodeBookmarks = new Set(); private baseDataFetched = false; @@ -32,17 +27,14 @@ export class SRApiService extends SRBaseService { constructor( private readonly http: HttpClient, private readonly localStorageService: LocalStorageService, - private readonly broker: MessageBrokerService, - private readonly translationService: TranslationService + private readonly broker: MessageBrokerService ) { super(); - this.initFavoritesFromLocalStorage(); this.initBookmarksFromLocalStorage(); } async fetchBaseData() { await this.fetchChannelsBaseData(); -// await this.fetchBaseProgramsData(); await this.fetchBaseProgramCategoriesData(); this.baseDataFetched = true; } @@ -72,24 +64,6 @@ export class SRApiService extends SRBaseService { this.channels$.next(this.channels); } - private async fetchBaseProgramsData() { - const programsRawResult = await this.getAllPrograms(); - const progs: Program[] = programsRawResult.programs.map((p: Program) => ({ - name: p.name, - id: p.id, - fav: false, - channel: { - id: p?.channel.id, - name: p?.channel.name - }, - programimage: p.programimagetemplate + SRApiService.DefaultImagePreset, - description: p.description, - programcategory: p.programcategory - })); - - this.updateProgramsWithFavs(progs); - } - private async fetchBaseProgramCategoriesData() { const categoriesRawResult = await this.getAllProgramCategories(); this.programCategories = categoriesRawResult.programcategories.map((r) => ({ @@ -105,11 +79,6 @@ export class SRApiService extends SRBaseService { return lastValueFrom(this.http.get(`${url}`)); } - private async getAllPrograms(): Promise { - const params = `?${this.FormatParam}&page=1&size=10000`; - let url = `${this.BaseUrl}programs/${params}`; - return lastValueFrom(this.http.get(`${url}`)); - } private async getAllProgramCategories(): Promise { const params = `?${this.FormatParam}&page=1&size=10000`; let url = `${this.BaseUrl}programcategories/${params}`; @@ -128,30 +97,6 @@ export class SRApiService extends SRBaseService { return category?.name; } - getProgramImageUrlFromId(programId: number): string { - if (!this.programs) return; - const program = this?.programs.find((c) => c.id === programId); - return program?.programimage; - } - - addProgramToFavorites(programId: number, programName: string) { - if (!this.programFavs.has(programId)) { - this.programFavs.add(programId); - this.storeFavsInLocalStorage(); - this.updateProgramsWithFavs(this.programs); - this.broker.sendMessage(new SuccessInfoMessage(this.translationService.translateWithArgs('AddedToFavorites', programName))); - } - } - - removeProgramFromFavorites(programId: number, programName: string) { - if (this.programFavs.has(programId)) { - this.programFavs.delete(programId); - this.storeFavsInLocalStorage(); - this.updateProgramsWithFavs(this.programs); - this.broker.sendMessage(new SuccessInfoMessage(this.translationService.translateWithArgs('RemovedFromFavorites', programName))); - } - } - addBookmarkForEpisode(episodeId: number) { if (!this.episodeBookmarks.has(episodeId)) { this.episodeBookmarks.add(episodeId); @@ -176,13 +121,10 @@ export class SRApiService extends SRBaseService { return this.episodeBookmarks.has(episodeId); } - async getProgramFromId(programId: number): Promise { - if (!this.baseDataFetched) { - await this.fetchBaseData(); - } - - const program = this.programs.find((p) => p.id === programId); - return program; + getChannelImageUrlFromId(channelId: number): string { + if (!this.channels) return; + const channel = this?.channels.find((c) => c.id === channelId); + return channel?.image; } async getChannelFromId(channelId: number): Promise { @@ -194,34 +136,6 @@ export class SRApiService extends SRBaseService { return channel; } - private updateProgramsWithFavs(progs: Program[]) { - progs.forEach((p) => (p.fav = this.programFavs.has(p.id))); - progs.sort((a: { name: string }, b: { name: any }) => { - return a.name.localeCompare(b.name); - }); - this.programs = progs; - this.programs$.next(this.programs); - } - - private initFavoritesFromLocalStorage() { - const favsarrayStr = this.localStorageService.get('programfavs'); - if (favsarrayStr) { - try { - const favsArray: [] = JSON.parse(favsarrayStr); - if (favsArray) { - favsArray.forEach((f) => { - this.programFavs.add(f); - }); - } - } catch {} - } - } - - private storeFavsInLocalStorage() { - let serializedSet = JSON.stringify(Array.from(this.programFavs)); - this.localStorageService.set('programfavs', serializedSet); - } - private initBookmarksFromLocalStorage() { const bookmarksArrayStr = this.localStorageService.get('episodeBookmarks'); if (bookmarksArrayStr) {