From b270ec096fdd1e1c04cd24bcad058b332044c395 Mon Sep 17 00:00:00 2001 From: Thomah <5090230+Thomah@users.noreply.github.com> Date: Wed, 15 Jun 2022 22:49:54 +0200 Subject: [PATCH] feat: Add list and play episode page --- package-lock.json | 4 +- package.json | 2 +- src/app/app-routing.module.ts | 10 +++ src/app/entities/season.ts | 2 + src/app/models/season.model.ts | 2 +- .../list-episodes-routing.module.ts | 17 +++++ .../list-episodes/list-episodes.module.ts | 20 ++++++ .../list-episodes/list-episodes.page.html | 36 ++++++++++ .../list-episodes/list-episodes.page.scss | 0 .../list-episodes/list-episodes.page.spec.ts | 24 +++++++ .../sagas/list-episodes/list-episodes.page.ts | 72 +++++++++++++++++++ .../play-episode-routing.module.ts | 17 +++++ .../sagas/play-episode/play-episode.module.ts | 20 ++++++ .../sagas/play-episode/play-episode.page.html | 21 ++++++ .../sagas/play-episode/play-episode.page.scss | 0 .../play-episode/play-episode.page.spec.ts | 24 +++++++ .../sagas/play-episode/play-episode.page.ts | 56 +++++++++++++++ .../pages/sagas/view-saga/view-saga.page.html | 22 +++--- .../episodes/episodes.service.spec.ts | 16 +++++ src/app/services/episodes/episodes.service.ts | 24 +++++++ src/app/services/seasons/season.service.ts | 8 ++- 21 files changed, 381 insertions(+), 16 deletions(-) create mode 100644 src/app/pages/sagas/list-episodes/list-episodes-routing.module.ts create mode 100644 src/app/pages/sagas/list-episodes/list-episodes.module.ts create mode 100644 src/app/pages/sagas/list-episodes/list-episodes.page.html create mode 100644 src/app/pages/sagas/list-episodes/list-episodes.page.scss create mode 100644 src/app/pages/sagas/list-episodes/list-episodes.page.spec.ts create mode 100644 src/app/pages/sagas/list-episodes/list-episodes.page.ts create mode 100644 src/app/pages/sagas/play-episode/play-episode-routing.module.ts create mode 100644 src/app/pages/sagas/play-episode/play-episode.module.ts create mode 100644 src/app/pages/sagas/play-episode/play-episode.page.html create mode 100644 src/app/pages/sagas/play-episode/play-episode.page.scss create mode 100644 src/app/pages/sagas/play-episode/play-episode.page.spec.ts create mode 100644 src/app/pages/sagas/play-episode/play-episode.page.ts create mode 100644 src/app/services/episodes/episodes.service.spec.ts create mode 100644 src/app/services/episodes/episodes.service.ts diff --git a/package-lock.json b/package-lock.json index 0bfa297..6ea3d2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "les-sagas-mp3", - "version": "0.6.2", + "version": "0.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "les-sagas-mp3", - "version": "0.6.2", + "version": "0.7.0", "dependencies": { "@angular/common": "~13.2.2", "@angular/core": "~13.2.2", diff --git a/package.json b/package.json index e9ef6b3..95f17cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "les-sagas-mp3", - "version": "0.6.2", + "version": "0.7.0", "author": "Les Sagas MP3", "homepage": "https://github.com/Les-Sagas-MP3", "scripts": { diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b0dbacc..3c61b17 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -34,7 +34,17 @@ const routes: Routes = [ { path: 'sync', loadChildren: () => import('./pages/admin/sync/sync.module').then( m => m.SyncPageModule) + }, + { + path: 'sagas/:id/seasons', + loadChildren: () => import('./pages/sagas/list-episodes/list-episodes.module').then( m => m.ListSeasonsPageModule) + }, + { + path: 'sagas/:saga/episode/:episode', + loadChildren: () => import('./pages/sagas/play-episode/play-episode.module').then( m => m.PlayEpisodePageModule) } + + ]; @NgModule({ diff --git a/src/app/entities/season.ts b/src/app/entities/season.ts index e1ecfc5..4420902 100644 --- a/src/app/entities/season.ts +++ b/src/app/entities/season.ts @@ -1,9 +1,11 @@ import { SeasonModel } from '../models/season.model'; +import { Episode } from './episode'; import { Saga } from './saga'; export class Season extends SeasonModel { saga: Saga; + episodes: Episode[] = []; static fromModel(model: SeasonModel): Season { var entity = new Season(); diff --git a/src/app/models/season.model.ts b/src/app/models/season.model.ts index 00b3af7..f7744a9 100644 --- a/src/app/models/season.model.ts +++ b/src/app/models/season.model.ts @@ -2,7 +2,7 @@ import { AuditModel } from './audit.model'; export class SeasonModel extends AuditModel { - number: number = 1; + number: number; name: string = ''; sagaRef: number = 0; episodesRef: [] = []; diff --git a/src/app/pages/sagas/list-episodes/list-episodes-routing.module.ts b/src/app/pages/sagas/list-episodes/list-episodes-routing.module.ts new file mode 100644 index 0000000..cdb5531 --- /dev/null +++ b/src/app/pages/sagas/list-episodes/list-episodes-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { ListSeasonsPage } from './list-episodes.page'; + +const routes: Routes = [ + { + path: '', + component: ListSeasonsPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class ListSeasonsPageRoutingModule {} diff --git a/src/app/pages/sagas/list-episodes/list-episodes.module.ts b/src/app/pages/sagas/list-episodes/list-episodes.module.ts new file mode 100644 index 0000000..9ef12e1 --- /dev/null +++ b/src/app/pages/sagas/list-episodes/list-episodes.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { ListSeasonsPageRoutingModule } from './list-episodes-routing.module'; + +import { ListSeasonsPage } from './list-episodes.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + ListSeasonsPageRoutingModule + ], + declarations: [ListSeasonsPage] +}) +export class ListSeasonsPageModule {} diff --git a/src/app/pages/sagas/list-episodes/list-episodes.page.html b/src/app/pages/sagas/list-episodes/list-episodes.page.html new file mode 100644 index 0000000..b19de6b --- /dev/null +++ b/src/app/pages/sagas/list-episodes/list-episodes.page.html @@ -0,0 +1,36 @@ + + + + + + + {{ item.title }} + + + + + + + + Saison {{ season.number }} {{ season.name }} + + + + Episode 1 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/app/pages/sagas/list-episodes/list-episodes.page.scss b/src/app/pages/sagas/list-episodes/list-episodes.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/sagas/list-episodes/list-episodes.page.spec.ts b/src/app/pages/sagas/list-episodes/list-episodes.page.spec.ts new file mode 100644 index 0000000..68c6d3c --- /dev/null +++ b/src/app/pages/sagas/list-episodes/list-episodes.page.spec.ts @@ -0,0 +1,24 @@ +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { ListSeasonsPage } from './list-episodes.page'; + +describe('ListSeasonsPage', () => { + let component: ListSeasonsPage; + let fixture: ComponentFixture; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + declarations: [ ListSeasonsPage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(ListSeasonsPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/sagas/list-episodes/list-episodes.page.ts b/src/app/pages/sagas/list-episodes/list-episodes.page.ts new file mode 100644 index 0000000..65e0a72 --- /dev/null +++ b/src/app/pages/sagas/list-episodes/list-episodes.page.ts @@ -0,0 +1,72 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { LoadingController } from '@ionic/angular'; +import { Episode } from 'src/app/entities/episode'; +import { Saga } from 'src/app/entities/saga'; +import { Season } from 'src/app/entities/season'; +import { SeasonModel } from 'src/app/models/season.model'; +import { AuthService } from 'src/app/services/auth/auth.service'; +import { ConfigService } from 'src/app/services/config/config.service'; +import { EpisodesService } from 'src/app/services/episodes/episodes.service'; +import { SagaService } from 'src/app/services/sagas/saga.service'; +import { SeasonService } from 'src/app/services/seasons/season.service'; + +@Component({ + selector: 'app-list-episodes', + templateUrl: './list-episodes.page.html', + styleUrls: ['./list-episodes.page.scss'], +}) +export class ListSeasonsPage implements OnInit { + + public item: Saga = new Saga(); + + constructor( + private activatedRoute: ActivatedRoute, + public loadingController: LoadingController, + private authService: AuthService, + public configService: ConfigService, + private episodeService: EpisodesService, + private sagaService: SagaService, + private seasonService: SeasonService) { } + + + ngOnInit() { + var itemId: number = +this.activatedRoute.snapshot.paramMap.get('id'); + this.loadingController.create({ + message: 'Téléchargement...' + }).then((loading) => { + loading.present(); + this.sagaService.getById(itemId) + .subscribe(data => { + this.item = Saga.fromModel(data); + this.seasonService.getAllByIds(data.seasonsRef) + .subscribe(data => { + this.item.seasons = Season.fromModels(data); + let episodeIds = []; + this.item.seasons.forEach(season => { + episodeIds.push(season.episodesRef); + }); + this.episodeService.getAllByIds(episodeIds) + .subscribe(data => { + const episodes = Episode.fromModels(data); + episodes.forEach(episode => { + this.item.seasons.find(season => season.id === episode.seasonRef).episodes.push(episode); + }) + loading.dismiss(); + }) + }); + }); + }); + } + + create() { + const season = new SeasonModel(); + season.sagaRef = this.item.id; + season.number = this.item.seasons.length + 1; + this.seasonService.create(season) + .subscribe(() => { + this.ngOnInit(); + }) + } + +} diff --git a/src/app/pages/sagas/play-episode/play-episode-routing.module.ts b/src/app/pages/sagas/play-episode/play-episode-routing.module.ts new file mode 100644 index 0000000..deb4e68 --- /dev/null +++ b/src/app/pages/sagas/play-episode/play-episode-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { PlayEpisodePage } from './play-episode.page'; + +const routes: Routes = [ + { + path: '', + component: PlayEpisodePage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class PlayEpisodePageRoutingModule {} diff --git a/src/app/pages/sagas/play-episode/play-episode.module.ts b/src/app/pages/sagas/play-episode/play-episode.module.ts new file mode 100644 index 0000000..4a0a516 --- /dev/null +++ b/src/app/pages/sagas/play-episode/play-episode.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { PlayEpisodePageRoutingModule } from './play-episode-routing.module'; + +import { PlayEpisodePage } from './play-episode.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + PlayEpisodePageRoutingModule + ], + declarations: [PlayEpisodePage] +}) +export class PlayEpisodePageModule {} diff --git a/src/app/pages/sagas/play-episode/play-episode.page.html b/src/app/pages/sagas/play-episode/play-episode.page.html new file mode 100644 index 0000000..1181dd5 --- /dev/null +++ b/src/app/pages/sagas/play-episode/play-episode.page.html @@ -0,0 +1,21 @@ + + + + + + + {{ saga.title }} + + + + + + + + {{ episode.title }} + #{{ episode.number }} + + + + + diff --git a/src/app/pages/sagas/play-episode/play-episode.page.scss b/src/app/pages/sagas/play-episode/play-episode.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/sagas/play-episode/play-episode.page.spec.ts b/src/app/pages/sagas/play-episode/play-episode.page.spec.ts new file mode 100644 index 0000000..43cf706 --- /dev/null +++ b/src/app/pages/sagas/play-episode/play-episode.page.spec.ts @@ -0,0 +1,24 @@ +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { PlayEpisodePage } from './play-episode.page'; + +describe('PlayEpisodePage', () => { + let component: PlayEpisodePage; + let fixture: ComponentFixture; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + declarations: [ PlayEpisodePage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(PlayEpisodePage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/sagas/play-episode/play-episode.page.ts b/src/app/pages/sagas/play-episode/play-episode.page.ts new file mode 100644 index 0000000..e78a5b4 --- /dev/null +++ b/src/app/pages/sagas/play-episode/play-episode.page.ts @@ -0,0 +1,56 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { LoadingController } from '@ionic/angular'; +import { Episode } from 'src/app/entities/episode'; +import { Saga } from 'src/app/entities/saga'; +import { AuthService } from 'src/app/services/auth/auth.service'; +import { ConfigService } from 'src/app/services/config/config.service'; +import { EpisodesService } from 'src/app/services/episodes/episodes.service'; +import { SagaService } from 'src/app/services/sagas/saga.service'; + +@Component({ + selector: 'app-play-episode', + templateUrl: './play-episode.page.html', + styleUrls: ['./play-episode.page.scss'], +}) +export class PlayEpisodePage implements OnInit { + + public saga: Saga = new Saga(); + public episode: Episode = new Episode(); + + constructor( + private activatedRoute: ActivatedRoute, + public loadingController: LoadingController, + private authService: AuthService, + public configService: ConfigService, + private sagaService: SagaService, + private episodeService: EpisodesService) { } + + + ngOnInit() { + var sagaId: number = +this.activatedRoute.snapshot.paramMap.get('saga'); + var episodeId: number = +this.activatedRoute.snapshot.paramMap.get('episode'); + this.loadingController.create({ + message: 'Téléchargement...' + }).then((loading) => { + loading.present(); + this.sagaService.getById(sagaId) + .subscribe(data => { + this.saga = Saga.fromModel(data); + this.episodeService.getById(episodeId) + .subscribe(data => { + this.episode = Episode.fromModel(data); + loading.dismiss(); + }); + }); + }); + } + + coverUrl(): string { + if(this.saga.coverUrl) { + return this.configService.get('appUrl') + this.saga.coverUrl; + } else { + return ''; + } + } +} diff --git a/src/app/pages/sagas/view-saga/view-saga.page.html b/src/app/pages/sagas/view-saga/view-saga.page.html index 1ceafa5..859b83f 100644 --- a/src/app/pages/sagas/view-saga/view-saga.page.html +++ b/src/app/pages/sagas/view-saga/view-saga.page.html @@ -24,6 +24,9 @@ + + Informations + @@ -66,16 +69,15 @@ - 0"> - - Saisons - - - - Saison {{ season.number }} {{ season.name }} - - - + + Episodes + + + + + Voir les épisodes + + \ No newline at end of file diff --git a/src/app/services/episodes/episodes.service.spec.ts b/src/app/services/episodes/episodes.service.spec.ts new file mode 100644 index 0000000..629688c --- /dev/null +++ b/src/app/services/episodes/episodes.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { EpisodesService } from './episodes.service'; + +describe('EpisodesService', () => { + let service: EpisodesService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(EpisodesService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/episodes/episodes.service.ts b/src/app/services/episodes/episodes.service.ts new file mode 100644 index 0000000..b9ab387 --- /dev/null +++ b/src/app/services/episodes/episodes.service.ts @@ -0,0 +1,24 @@ +import { HttpClient, HttpParams } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { EpisodeModel } from 'src/app/models/episode.model'; +import { ConfigService } from '../config/config.service'; + +@Injectable({ + providedIn: 'root' +}) +export class EpisodesService { + + constructor(private http: HttpClient, private configService: ConfigService) { } + + getById(id: number) : Observable { + return this.http.get(`${this.configService.get('apiUrl')}/episode/${id}`); + } + + getAllByIds(ids: number[]) { + const params = new HttpParams() + .set('ids', ids.toString()); + return this.http.get(`${this.configService.get('apiUrl')}/episode`, { params }); + } + +} diff --git a/src/app/services/seasons/season.service.ts b/src/app/services/seasons/season.service.ts index 9fdb9dd..b4479d1 100644 --- a/src/app/services/seasons/season.service.ts +++ b/src/app/services/seasons/season.service.ts @@ -9,11 +9,15 @@ import { ConfigService } from '../config/config.service'; export class SeasonService { constructor(private http: HttpClient, private configService: ConfigService) { } - + getAllByIds(ids: number[]) { const params = new HttpParams() - .set('ids', ids.toString()); + .set('ids', ids.toString()); return this.http.get(`${this.configService.get('apiUrl')}/season`, { params }); } + create(season: SeasonModel) { + return this.http.post(`${this.configService.get('apiUrl')}/season`, season); + } + }