Skip to content

Commit

Permalink
feat: Add list and play episode page
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomah committed Jun 15, 2022
1 parent 68513b7 commit b270ec0
Show file tree
Hide file tree
Showing 21 changed files with 381 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
10 changes: 10 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions src/app/entities/season.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/season.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] = [];
Expand Down
17 changes: 17 additions & 0 deletions src/app/pages/sagas/list-episodes/list-episodes-routing.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
20 changes: 20 additions & 0 deletions src/app/pages/sagas/list-episodes/list-episodes.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
36 changes: 36 additions & 0 deletions src/app/pages/sagas/list-episodes/list-episodes.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<ion-header [translucent]="true">
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>{{ item.title }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<ion-list>
<div *ngFor="let season of item.seasons">
<ion-list-header color="primary">
<ion-label>Saison {{ season.number }} {{ season.name }}</ion-label>
</ion-list-header>
<ion-item *ngFor="let episode of season.episodes" lines="none" routerLink="/sagas/{{ item.id }}/episode/{{ episode.id }}" routerDirection="forward">
<ion-label>
<ion-icon name="play-outline"></ion-icon> Episode 1
</ion-label>
</ion-item>
</div>
</ion-list>
<ion-fab vertical="bottom" horizontal="end" slot="fixed" *ngIf="authService.currentTokenValue">
<ion-fab-button><ion-icon name="pencil-outline"></ion-icon></ion-fab-button>
<ion-fab-list side="top">
<ion-fab-button (click)="create()" >
<ion-icon name="add"></ion-icon>
</ion-fab-button>
<ion-fab-button>
<ion-icon name="pencil-outline"></ion-icon>
</ion-fab-button>
</ion-fab-list>
</ion-fab>

</ion-content>
Empty file.
24 changes: 24 additions & 0 deletions src/app/pages/sagas/list-episodes/list-episodes.page.spec.ts
Original file line number Diff line number Diff line change
@@ -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<ListSeasonsPage>;

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();
});
});
72 changes: 72 additions & 0 deletions src/app/pages/sagas/list-episodes/list-episodes.page.ts
Original file line number Diff line number Diff line change
@@ -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();
})
}

}
17 changes: 17 additions & 0 deletions src/app/pages/sagas/play-episode/play-episode-routing.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
20 changes: 20 additions & 0 deletions src/app/pages/sagas/play-episode/play-episode.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
21 changes: 21 additions & 0 deletions src/app/pages/sagas/play-episode/play-episode.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<ion-header [translucent]="true">
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>{{ saga.title }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<ion-card>
<ion-img class="cover" [src]="coverUrl()"></ion-img>
<ion-card-header class="ion-text-center">
<ion-card-title>{{ episode.title }}</ion-card-title>
<ion-card-subtitle>#{{ episode.number }}</ion-card-subtitle>
</ion-card-header>

</ion-card>

</ion-content>
Empty file.
24 changes: 24 additions & 0 deletions src/app/pages/sagas/play-episode/play-episode.page.spec.ts
Original file line number Diff line number Diff line change
@@ -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<PlayEpisodePage>;

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();
});
});
56 changes: 56 additions & 0 deletions src/app/pages/sagas/play-episode/play-episode.page.ts
Original file line number Diff line number Diff line change
@@ -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 '';
}
}
}
Loading

0 comments on commit b270ec0

Please sign in to comment.