Skip to content

Commit

Permalink
Do not preload programs
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsBergqvist committed Nov 24, 2023
1 parent f688f39 commit b2a2496
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 194 deletions.
1 change: 0 additions & 1 deletion .github/workflows/buildanddeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/channels/channel-schedule.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}));
}

Expand Down
8 changes: 0 additions & 8 deletions src/app/components/programs/program-details.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
<b>{{'Category' | translate}}</b>: {{getCategoryNameFromId(program.programcategory.id)}}
</span>
</span>
<span class="p-col-4">
<span *ngIf="!program.fav" class="clickable" (click)="onAddToFavorites(program.id, program.name)"><i
class="pi pi-star fav-but"></i>
</span>
<span *ngIf="program.fav" class="clickable" (click)="onRemoveFromFavorites(program.id, program.name)"><i
class="pi pi-star-fill yellow-fav"></i>
</span>
</span>
</div>
<hr>
<app-episodes-table [episodes]="episodes" (onLoadLazy)="loadLazy($event)" [totalHits]="totalHits"
Expand Down
19 changes: 9 additions & 10 deletions src/app/components/programs/program-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MessageBrokerService } from 'src/app/services/message-broker.service';
import { SRApiService } from 'src/app/services/srapi.service';
import { EpisodeViewModel } from '../episodes/episode-viewmodel';
import { EpisodesLoadLazyArgs } from '../episodes/episodes-table.component';
import { ProgramsService } from 'src/app/services/programs.service';

@Component({
selector: 'app-program-details',
Expand All @@ -26,7 +27,8 @@ export class ProgramDetailsComponent implements OnInit, OnDestroy {
private readonly service: EpisodesService,
private readonly srApiService: SRApiService,
private readonly activatedRoute: ActivatedRoute,
private readonly broker: MessageBrokerService
private readonly broker: MessageBrokerService,
private readonly programsService: ProgramsService,
) {}

async ngOnInit() {
Expand All @@ -36,10 +38,15 @@ export class ProgramDetailsComponent implements OnInit, OnDestroy {
map((route) => 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);
// }
});
}

Expand Down Expand Up @@ -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);
}
}
20 changes: 0 additions & 20 deletions src/app/components/programs/programs-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
[globalFilterFields]="['name','channel.name','description']" styleClass="sr-table">
<ng-template pTemplate="caption">
<span class="p-d-flex">
<div [ngStyle]="{'margin-bottom': '10px' }">
<span class="fav-chk">
<p-checkbox (onChange)="onFilterFavClicked($event, dt2)" [(ngModel)]="localState.showOnlyFavs"
[binary]="true" label="{{'OnlyFavs' | translate }}" class="fav-checkbox"></p-checkbox>
</span>
<span class="p-input-icon-left p-ml-auto">
<i class="pi pi-search"></i>
<input pInputText class="p-inputtext-sm kw-input" type="text" [(ngModel)]="localState.searchString"
(input)="dt2.filterGlobal($event.target.value, 'contains')"
placeholder="{{'SearchKeyword' | translate | uppercase}}" />
</span>
</div>

<p-accordion [activeIndex]="0">
<p-accordionTab header="{{'Categories' | translate}}">
<p-selectButton [options]="categoryOptions" [(ngModel)]="localState.selectedCategory" optionLabel="label" optionValue="value"
Expand Down Expand Up @@ -57,13 +44,6 @@
<span class="clickable" (click)="onShowEpisodes(program)"><i
class="pi pi-info-circle details-btn"></i>
</span>
<span *ngIf="!program.fav" class="clickable"
(click)="onAddToFavorites(program.id, program.name)"><i class="pi pi-star fav-but details-btn"></i>
</span>
<span *ngIf="program.fav" class="clickable"
(click)="onRemoveFromFavorites(program.id, program.name)"><i
class="pi pi-star-fill yellow-fav details-btn"></i>
</span>
</span>
</div>
</td>
Expand Down
48 changes: 3 additions & 45 deletions src/app/components/programs/programs-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = [];
Expand All @@ -66,14 +53,15 @@ export class ProgramsListComponent implements OnInit, OnDestroy, AfterViewInit {
this.categoryOptions.push(...categories);
}
});

await this.fetch(0);
}

async loadLazy(event: any) {
await this.fetch(event.first);
}

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;
Expand All @@ -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() {
Expand All @@ -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);
}
}
}
26 changes: 8 additions & 18 deletions src/app/services/programs.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -46,8 +39,12 @@ export class ProgramsService extends SRBaseService {
return res;
}

/*
const progs: Program[] = programsRawResult.programs.map((p: Program) => ({
async fetchProgramWithId(programId: number): Promise<Program> {
let url = `${this.BaseUrl}programs/${programId}?${this.FormatParam}`;
const res = await lastValueFrom(this.http.get<any>(`${url}`));
const p = res.program;

const prog: any = {
name: p.name,
id: p.id,
fav: false,
Expand All @@ -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<any> {
const params = `?${this.FormatParam}&page=1&size=10000`;
let url = `${this.BaseUrl}programs/${params}`;
return lastValueFrom(this.http.get<any>(`${url}`));
return prog;
}
*/

}
Loading

0 comments on commit b2a2496

Please sign in to comment.