From 4db4cd4b051102ff638a2dcb1b1c925cdf6d66f8 Mon Sep 17 00:00:00 2001 From: Thomah <5090230+Thomah@users.noreply.github.com> Date: Wed, 24 Aug 2022 13:54:36 +0200 Subject: [PATCH 1/5] feat: add page to create and update saga informations --- src/app/app-routing.module.ts | 40 ++++--- src/app/entities/saga.ts | 2 +- src/app/models/{ => saga}/saga.model.spec.ts | 0 src/app/models/{ => saga}/saga.model.ts | 2 +- .../edit-episode-routing.module.ts | 0 .../edit-episode/edit-episode.module.ts | 0 .../edit-episode/edit-episode.page.html | 0 .../edit-episode/edit-episode.page.scss | 0 .../edit-episode/edit-episode.page.spec.ts | 0 .../edit-episode/edit-episode.page.ts | 0 .../list-episodes-routing.module.ts | 0 .../list-episodes/list-episodes.module.ts | 0 .../list-episodes/list-episodes.page.html | 5 + .../list-episodes/list-episodes.page.scss | 0 .../list-episodes/list-episodes.page.spec.ts | 0 .../list-episodes/list-episodes.page.ts | 15 ++- .../play-episode-routing.module.ts | 0 .../play-episode/play-episode.module.ts | 0 .../play-episode/play-episode.page.html | 0 .../play-episode/play-episode.page.scss | 0 .../play-episode/play-episode.page.spec.ts | 0 .../play-episode/play-episode.page.ts | 0 .../edit-saga/edit-saga-routing.module.ts | 17 +++ .../pages/sagas/edit-saga/edit-saga.module.ts | 21 ++++ .../pages/sagas/edit-saga/edit-saga.page.html | 52 +++++++++ .../pages/sagas/edit-saga/edit-saga.page.scss | 0 .../sagas/edit-saga/edit-saga.page.spec.ts | 24 ++++ .../pages/sagas/edit-saga/edit-saga.page.ts | 110 ++++++++++++++++++ .../sagas/list-sagas/list-sagas.page.html | 5 + .../pages/sagas/list-sagas/list-sagas.page.ts | 10 ++ .../pages/sagas/view-saga/view-saga.page.html | 6 + src/app/services/episodes/episodes.service.ts | 4 + src/app/services/sagas/saga.service.ts | 6 +- 33 files changed, 297 insertions(+), 22 deletions(-) rename src/app/models/{ => saga}/saga.model.spec.ts (100%) rename src/app/models/{ => saga}/saga.model.ts (94%) rename src/app/pages/{sagas => }/episodes/edit-episode/edit-episode-routing.module.ts (100%) rename src/app/pages/{sagas => }/episodes/edit-episode/edit-episode.module.ts (100%) rename src/app/pages/{sagas => }/episodes/edit-episode/edit-episode.page.html (100%) rename src/app/pages/{sagas => }/episodes/edit-episode/edit-episode.page.scss (100%) rename src/app/pages/{sagas => }/episodes/edit-episode/edit-episode.page.spec.ts (100%) rename src/app/pages/{sagas => }/episodes/edit-episode/edit-episode.page.ts (100%) rename src/app/pages/{sagas => }/episodes/list-episodes/list-episodes-routing.module.ts (100%) rename src/app/pages/{sagas => }/episodes/list-episodes/list-episodes.module.ts (100%) rename src/app/pages/{sagas => }/episodes/list-episodes/list-episodes.page.html (83%) rename src/app/pages/{sagas => }/episodes/list-episodes/list-episodes.page.scss (100%) rename src/app/pages/{sagas => }/episodes/list-episodes/list-episodes.page.spec.ts (100%) rename src/app/pages/{sagas => }/episodes/list-episodes/list-episodes.page.ts (81%) rename src/app/pages/{sagas => }/episodes/play-episode/play-episode-routing.module.ts (100%) rename src/app/pages/{sagas => }/episodes/play-episode/play-episode.module.ts (100%) rename src/app/pages/{sagas => }/episodes/play-episode/play-episode.page.html (100%) rename src/app/pages/{sagas => }/episodes/play-episode/play-episode.page.scss (100%) rename src/app/pages/{sagas => }/episodes/play-episode/play-episode.page.spec.ts (100%) rename src/app/pages/{sagas => }/episodes/play-episode/play-episode.page.ts (100%) create mode 100644 src/app/pages/sagas/edit-saga/edit-saga-routing.module.ts create mode 100644 src/app/pages/sagas/edit-saga/edit-saga.module.ts create mode 100644 src/app/pages/sagas/edit-saga/edit-saga.page.html create mode 100644 src/app/pages/sagas/edit-saga/edit-saga.page.scss create mode 100644 src/app/pages/sagas/edit-saga/edit-saga.page.spec.ts create mode 100644 src/app/pages/sagas/edit-saga/edit-saga.page.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 59ceb86..b47e980 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -7,14 +7,6 @@ const routes: Routes = [ redirectTo: 'news', pathMatch: 'full' }, - { - path: 'sagas', - loadChildren: () => import('./pages/sagas/list-sagas/list-sagas.module').then( m => m.ListSagasPageModule) - }, - { - path: 'sagas/:id', - loadChildren: () => import('./pages/sagas/view-saga/view-saga.module').then( m => m.ViewSagaPageModule) - }, { path: 'news', loadChildren: () => import('./pages/news/list-news/list-news.module').then( m => m.ListNewsPageModule) @@ -24,20 +16,20 @@ const routes: Routes = [ loadChildren: () => import('./pages/news/view-news/view-news.module').then( m => m.ViewNewsPageModule) }, { - path: 'login', - loadChildren: () => import('./pages/login/login.module').then( m => m.LoginPageModule) + path: 'sagas', + loadChildren: () => import('./pages/sagas/list-sagas/list-sagas.module').then( m => m.ListSagasPageModule) }, { - path: 'signup', - loadChildren: () => import('./pages/signup/signup.module').then( m => m.SignupPageModule) + path: 'sagas/:id', + loadChildren: () => import('./pages/sagas/view-saga/view-saga.module').then( m => m.ViewSagaPageModule) }, { - path: 'sync', - loadChildren: () => import('./pages/admin/sync/sync.module').then( m => m.SyncPageModule) + path: 'sagas/:id/edit', + loadChildren: () => import('./pages/sagas/edit-saga/edit-saga.module').then( m => m.EditSagaPageModule) }, { path: 'sagas/:sagaId/seasons/:seasonId', - loadChildren: () => import('./pages/sagas/episodes/list-episodes/list-episodes.module').then( m => m.ListEpisodesPageModule) + loadChildren: () => import('./pages/episodes/list-episodes/list-episodes.module').then( m => m.ListEpisodesPageModule) }, { path: 'sagas/:sagaId/seasons/:seasonId/edit', @@ -45,12 +37,24 @@ const routes: Routes = [ }, { path: 'sagas/:saga/episode/:episode', - loadChildren: () => import('./pages/sagas/episodes/play-episode/play-episode.module').then( m => m.PlayEpisodePageModule) + loadChildren: () => import('./pages/episodes/play-episode/play-episode.module').then( m => m.PlayEpisodePageModule) }, { path: 'sagas/:saga/episode/:episode/edit', - loadChildren: () => import('./pages/sagas/episodes/edit-episode/edit-episode.module').then( m => m.EditEpisodePageModule) - } + loadChildren: () => import('./pages/episodes/edit-episode/edit-episode.module').then( m => m.EditEpisodePageModule) + }, + { + path: 'login', + loadChildren: () => import('./pages/login/login.module').then( m => m.LoginPageModule) + }, + { + path: 'signup', + loadChildren: () => import('./pages/signup/signup.module').then( m => m.SignupPageModule) + }, + { + path: 'sync', + loadChildren: () => import('./pages/admin/sync/sync.module').then( m => m.SyncPageModule) + }, ]; diff --git a/src/app/entities/saga.ts b/src/app/entities/saga.ts index 247f6ec..f442c13 100644 --- a/src/app/entities/saga.ts +++ b/src/app/entities/saga.ts @@ -1,4 +1,4 @@ -import { SagaModel } from '../models/saga.model'; +import { SagaModel } from '../models/saga/saga.model'; import { Author } from './author'; import { Category } from './category'; import { Season } from './season'; diff --git a/src/app/models/saga.model.spec.ts b/src/app/models/saga/saga.model.spec.ts similarity index 100% rename from src/app/models/saga.model.spec.ts rename to src/app/models/saga/saga.model.spec.ts diff --git a/src/app/models/saga.model.ts b/src/app/models/saga/saga.model.ts similarity index 94% rename from src/app/models/saga.model.ts rename to src/app/models/saga/saga.model.ts index 13bf7c3..3b7a60d 100644 --- a/src/app/models/saga.model.ts +++ b/src/app/models/saga/saga.model.ts @@ -1,4 +1,4 @@ -import { AuditModel } from './audit.model'; +import { AuditModel } from '../audit.model'; export class SagaModel extends AuditModel { diff --git a/src/app/pages/sagas/episodes/edit-episode/edit-episode-routing.module.ts b/src/app/pages/episodes/edit-episode/edit-episode-routing.module.ts similarity index 100% rename from src/app/pages/sagas/episodes/edit-episode/edit-episode-routing.module.ts rename to src/app/pages/episodes/edit-episode/edit-episode-routing.module.ts diff --git a/src/app/pages/sagas/episodes/edit-episode/edit-episode.module.ts b/src/app/pages/episodes/edit-episode/edit-episode.module.ts similarity index 100% rename from src/app/pages/sagas/episodes/edit-episode/edit-episode.module.ts rename to src/app/pages/episodes/edit-episode/edit-episode.module.ts diff --git a/src/app/pages/sagas/episodes/edit-episode/edit-episode.page.html b/src/app/pages/episodes/edit-episode/edit-episode.page.html similarity index 100% rename from src/app/pages/sagas/episodes/edit-episode/edit-episode.page.html rename to src/app/pages/episodes/edit-episode/edit-episode.page.html diff --git a/src/app/pages/sagas/episodes/edit-episode/edit-episode.page.scss b/src/app/pages/episodes/edit-episode/edit-episode.page.scss similarity index 100% rename from src/app/pages/sagas/episodes/edit-episode/edit-episode.page.scss rename to src/app/pages/episodes/edit-episode/edit-episode.page.scss diff --git a/src/app/pages/sagas/episodes/edit-episode/edit-episode.page.spec.ts b/src/app/pages/episodes/edit-episode/edit-episode.page.spec.ts similarity index 100% rename from src/app/pages/sagas/episodes/edit-episode/edit-episode.page.spec.ts rename to src/app/pages/episodes/edit-episode/edit-episode.page.spec.ts diff --git a/src/app/pages/sagas/episodes/edit-episode/edit-episode.page.ts b/src/app/pages/episodes/edit-episode/edit-episode.page.ts similarity index 100% rename from src/app/pages/sagas/episodes/edit-episode/edit-episode.page.ts rename to src/app/pages/episodes/edit-episode/edit-episode.page.ts diff --git a/src/app/pages/sagas/episodes/list-episodes/list-episodes-routing.module.ts b/src/app/pages/episodes/list-episodes/list-episodes-routing.module.ts similarity index 100% rename from src/app/pages/sagas/episodes/list-episodes/list-episodes-routing.module.ts rename to src/app/pages/episodes/list-episodes/list-episodes-routing.module.ts diff --git a/src/app/pages/sagas/episodes/list-episodes/list-episodes.module.ts b/src/app/pages/episodes/list-episodes/list-episodes.module.ts similarity index 100% rename from src/app/pages/sagas/episodes/list-episodes/list-episodes.module.ts rename to src/app/pages/episodes/list-episodes/list-episodes.module.ts diff --git a/src/app/pages/sagas/episodes/list-episodes/list-episodes.page.html b/src/app/pages/episodes/list-episodes/list-episodes.page.html similarity index 83% rename from src/app/pages/sagas/episodes/list-episodes/list-episodes.page.html rename to src/app/pages/episodes/list-episodes/list-episodes.page.html index 4e2b97a..8bc088c 100644 --- a/src/app/pages/sagas/episodes/list-episodes/list-episodes.page.html +++ b/src/app/pages/episodes/list-episodes/list-episodes.page.html @@ -21,5 +21,10 @@ {{ episode.displayedNumber }} - {{ episode.title }} + + + < Ajouter un épisode > + + \ No newline at end of file diff --git a/src/app/pages/sagas/episodes/list-episodes/list-episodes.page.scss b/src/app/pages/episodes/list-episodes/list-episodes.page.scss similarity index 100% rename from src/app/pages/sagas/episodes/list-episodes/list-episodes.page.scss rename to src/app/pages/episodes/list-episodes/list-episodes.page.scss diff --git a/src/app/pages/sagas/episodes/list-episodes/list-episodes.page.spec.ts b/src/app/pages/episodes/list-episodes/list-episodes.page.spec.ts similarity index 100% rename from src/app/pages/sagas/episodes/list-episodes/list-episodes.page.spec.ts rename to src/app/pages/episodes/list-episodes/list-episodes.page.spec.ts diff --git a/src/app/pages/sagas/episodes/list-episodes/list-episodes.page.ts b/src/app/pages/episodes/list-episodes/list-episodes.page.ts similarity index 81% rename from src/app/pages/sagas/episodes/list-episodes/list-episodes.page.ts rename to src/app/pages/episodes/list-episodes/list-episodes.page.ts index 1973aa7..505574c 100644 --- a/src/app/pages/sagas/episodes/list-episodes/list-episodes.page.ts +++ b/src/app/pages/episodes/list-episodes/list-episodes.page.ts @@ -4,6 +4,7 @@ import { ActionSheetController, 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 { EpisodeModel } from 'src/app/models/episode.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'; @@ -45,7 +46,7 @@ export class ListEpisodesPage implements OnInit { this.season = Season.fromModel(data); this.episodeService.getAllByIds(this.season.episodesRef) .subscribe(data => { - this.season.episodes = Episode.fromModels(data); + this.season.episodes = Episode.fromModels(data).sort((first, second) => 0 - (first.number > second.number ? -1 : 1)); loading.dismiss(); }) }); @@ -53,4 +54,16 @@ export class ListEpisodesPage implements OnInit { }); } + addEpisode() { + var episode = new EpisodeModel(); + if(this.season.episodes.length > 0) { + episode.number = this.season.episodes[this.season.episodes.length - 1].number + 1; + } + episode.seasonRef = this.season.id; + this.episodeService.create(episode) + .subscribe(data => { + this.ngOnInit(); + }); + } + } diff --git a/src/app/pages/sagas/episodes/play-episode/play-episode-routing.module.ts b/src/app/pages/episodes/play-episode/play-episode-routing.module.ts similarity index 100% rename from src/app/pages/sagas/episodes/play-episode/play-episode-routing.module.ts rename to src/app/pages/episodes/play-episode/play-episode-routing.module.ts diff --git a/src/app/pages/sagas/episodes/play-episode/play-episode.module.ts b/src/app/pages/episodes/play-episode/play-episode.module.ts similarity index 100% rename from src/app/pages/sagas/episodes/play-episode/play-episode.module.ts rename to src/app/pages/episodes/play-episode/play-episode.module.ts diff --git a/src/app/pages/sagas/episodes/play-episode/play-episode.page.html b/src/app/pages/episodes/play-episode/play-episode.page.html similarity index 100% rename from src/app/pages/sagas/episodes/play-episode/play-episode.page.html rename to src/app/pages/episodes/play-episode/play-episode.page.html diff --git a/src/app/pages/sagas/episodes/play-episode/play-episode.page.scss b/src/app/pages/episodes/play-episode/play-episode.page.scss similarity index 100% rename from src/app/pages/sagas/episodes/play-episode/play-episode.page.scss rename to src/app/pages/episodes/play-episode/play-episode.page.scss diff --git a/src/app/pages/sagas/episodes/play-episode/play-episode.page.spec.ts b/src/app/pages/episodes/play-episode/play-episode.page.spec.ts similarity index 100% rename from src/app/pages/sagas/episodes/play-episode/play-episode.page.spec.ts rename to src/app/pages/episodes/play-episode/play-episode.page.spec.ts diff --git a/src/app/pages/sagas/episodes/play-episode/play-episode.page.ts b/src/app/pages/episodes/play-episode/play-episode.page.ts similarity index 100% rename from src/app/pages/sagas/episodes/play-episode/play-episode.page.ts rename to src/app/pages/episodes/play-episode/play-episode.page.ts diff --git a/src/app/pages/sagas/edit-saga/edit-saga-routing.module.ts b/src/app/pages/sagas/edit-saga/edit-saga-routing.module.ts new file mode 100644 index 0000000..db6d1fd --- /dev/null +++ b/src/app/pages/sagas/edit-saga/edit-saga-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { EditSagaPage } from './edit-saga.page'; + +const routes: Routes = [ + { + path: '', + component: EditSagaPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class EditSagaPageRoutingModule {} diff --git a/src/app/pages/sagas/edit-saga/edit-saga.module.ts b/src/app/pages/sagas/edit-saga/edit-saga.module.ts new file mode 100644 index 0000000..9fa22f1 --- /dev/null +++ b/src/app/pages/sagas/edit-saga/edit-saga.module.ts @@ -0,0 +1,21 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { EditSagaPageRoutingModule } from './edit-saga-routing.module'; + +import { EditSagaPage } from './edit-saga.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + ReactiveFormsModule, + IonicModule, + EditSagaPageRoutingModule + ], + declarations: [EditSagaPage] +}) +export class EditSagaPageModule {} diff --git a/src/app/pages/sagas/edit-saga/edit-saga.page.html b/src/app/pages/sagas/edit-saga/edit-saga.page.html new file mode 100644 index 0000000..b0a0142 --- /dev/null +++ b/src/app/pages/sagas/edit-saga/edit-saga.page.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + {{ saga.title }} + + + + +
+ + + Informations + + + Titre + + + + Status + + + + Synopsis + + + + Origine + + + + Awards + + + + Bannière + {{ bannerSource }} + + + Pochette + {{ coverSource }} + + +
+
\ No newline at end of file diff --git a/src/app/pages/sagas/edit-saga/edit-saga.page.scss b/src/app/pages/sagas/edit-saga/edit-saga.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/sagas/edit-saga/edit-saga.page.spec.ts b/src/app/pages/sagas/edit-saga/edit-saga.page.spec.ts new file mode 100644 index 0000000..bfdec5e --- /dev/null +++ b/src/app/pages/sagas/edit-saga/edit-saga.page.spec.ts @@ -0,0 +1,24 @@ +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { EditSagaPage } from './edit-saga.page'; + +describe('EditSagaPage', () => { + let component: EditSagaPage; + let fixture: ComponentFixture; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + declarations: [ EditSagaPage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(EditSagaPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/sagas/edit-saga/edit-saga.page.ts b/src/app/pages/sagas/edit-saga/edit-saga.page.ts new file mode 100644 index 0000000..1d718bd --- /dev/null +++ b/src/app/pages/sagas/edit-saga/edit-saga.page.ts @@ -0,0 +1,110 @@ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { ActivatedRoute } from '@angular/router'; +import { LoadingController, NavController } from '@ionic/angular'; +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 { FileService } from 'src/app/services/file/file.service'; +import { SagaService } from 'src/app/services/sagas/saga.service'; + +@Component({ + selector: 'app-edit-saga', + templateUrl: './edit-saga.page.html', + styleUrls: ['./edit-saga.page.scss'], +}) +export class EditSagaPage implements OnInit { + + public saga: Saga = new Saga(); + + sagaForm: FormGroup; + attemptedSubmit = false; + bannerSource = ''; + coverSource = ''; + + constructor( + private activatedRoute: ActivatedRoute, + private fb: FormBuilder, + public loadingController: LoadingController, + public navCtrl: NavController, + public authService: AuthService, + public configService: ConfigService, + private fileService: FileService, + private sagaService: SagaService) { + + this.sagaForm = this.fb.group({ + title: ['', [Validators.required]], + status: [], + synopsis: [], + origin: [], + awards: [], + banner: [''], + bannerSource: [''], + cover: [''], + coverSource: [''] + }); + } + + ngOnInit() { + var sagaId: number = +this.activatedRoute.snapshot.paramMap.get('id'); + this.loadingController.create({ + message: 'Téléchargement...' + }).then((loading) => { + loading.present(); + this.sagaService.getById(sagaId) + .subscribe(data => { + this.saga = Saga.fromModel(data); + loading.dismiss(); + }); + }); + } + + markFieldsDirty() { + const controls = this.sagaForm.controls; + for (const field in controls) { + if (controls[field]) { + controls[field].markAsDirty(); + } + } + } + + async save() { + this.attemptedSubmit = true; + if (this.sagaForm.valid) { + const controls = this.sagaForm.controls; + this.loadingController.create({ + message: 'Sauvegarde en cours...' + }).then((loading) => { + loading.present(); + loading.dismiss(); + }); + } else { + this.markFieldsDirty(); + } + } + + onBannerChange(event) { + if (event.target.files.length > 0) { + const file = event.target.files[0]; + if(file.size <= this.fileService.maxFileSize) { + this.sagaForm.patchValue({ + bannerSource: file + }); + this.bannerSource = file.name; + } + } + } + + onCoverChange(event) { + if (event.target.files.length > 0) { + const file = event.target.files[0]; + if(file.size <= this.fileService.maxFileSize) { + this.sagaForm.patchValue({ + coverSource: file + }); + this.coverSource = file.name; + } + } + } + +} diff --git a/src/app/pages/sagas/list-sagas/list-sagas.page.html b/src/app/pages/sagas/list-sagas/list-sagas.page.html index 937d74a..a9b1ec6 100644 --- a/src/app/pages/sagas/list-sagas/list-sagas.page.html +++ b/src/app/pages/sagas/list-sagas/list-sagas.page.html @@ -23,6 +23,11 @@

+ + + < Ajouter une saga > + + diff --git a/src/app/pages/sagas/list-sagas/list-sagas.page.ts b/src/app/pages/sagas/list-sagas/list-sagas.page.ts index 3d538db..2dabfae 100644 --- a/src/app/pages/sagas/list-sagas/list-sagas.page.ts +++ b/src/app/pages/sagas/list-sagas/list-sagas.page.ts @@ -6,6 +6,7 @@ import { CategoryService } from 'src/app/services/categories/category.service'; import { Category } from 'src/app/entities/category'; import { Saga } from 'src/app/entities/saga'; import { AuthService } from 'src/app/services/auth/auth.service'; +import { SagaModel } from 'src/app/models/saga/saga.model'; @Component({ selector: 'app-list-sagas', @@ -77,6 +78,15 @@ export class ListSagasPage implements OnInit { }); } + addSaga() { + var saga = new SagaModel(); + saga.title = "Nouvelle saga"; + this.sagaService.create(saga) + .subscribe(data => { + this.navCtrl.navigateForward("sagas/" + data.id) + }); + } + createSagaFromPdf(event) { const file = event.target.files[0]; this.sagaService.uploadPdf(file) 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 3998483..d7ca84d 100644 --- a/src/app/pages/sagas/view-saga/view-saga.page.html +++ b/src/app/pages/sagas/view-saga/view-saga.page.html @@ -5,6 +5,12 @@ {{ item.title }} + + + + + diff --git a/src/app/services/episodes/episodes.service.ts b/src/app/services/episodes/episodes.service.ts index e8a7431..fc955d9 100644 --- a/src/app/services/episodes/episodes.service.ts +++ b/src/app/services/episodes/episodes.service.ts @@ -21,6 +21,10 @@ export class EpisodesService { return this.http.get(`${this.configService.get('apiUrl')}/episode`, { params }); } + create(episode: EpisodeModel) { + return this.http.post(`${this.configService.get('apiUrl')}/episode`, episode); + } + update(episode: EpisodeModel) { return this.http.put(`${this.configService.get('apiUrl')}/episode`, episode); } diff --git a/src/app/services/sagas/saga.service.ts b/src/app/services/sagas/saga.service.ts index f9ad2a8..662a1a8 100644 --- a/src/app/services/sagas/saga.service.ts +++ b/src/app/services/sagas/saga.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; -import { SagaModel } from 'src/app/models/saga.model'; +import { SagaModel } from 'src/app/models/saga/saga.model'; import { DataPage } from 'src/app/models/pagination/data.page'; import { ConfigService } from '../config/config.service'; @@ -30,6 +30,10 @@ export class SagaService { return this.http.get(`${this.configService.get('apiUrl')}/saga?search=${search}`); } + create(saga: SagaModel) { + return this.http.post(`${this.configService.get('apiUrl')}/saga`, saga); + } + uploadPdf(file): Observable { let formData = new FormData(); formData.append("file", file, file.name); From 6f35c27672d6609789a102e128a8c7799b48387c Mon Sep 17 00:00:00 2001 From: Titohma <102875311+Titohma@users.noreply.github.com> Date: Mon, 10 Apr 2023 20:21:54 +0200 Subject: [PATCH 2/5] disable analytics --- angular.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/angular.json b/angular.json index 4cd87b9..b653ce8 100644 --- a/angular.json +++ b/angular.json @@ -148,7 +148,8 @@ "cli": { "schematicCollections": [ "@ionic/angular-toolkit" - ] + ], + "analytics": false }, "schematics": { "@ionic/angular-toolkit:component": { From bcdb858b085d72c1fbb11f28ac75fbe554e69603 Mon Sep 17 00:00:00 2001 From: Titohma <102875311+Titohma@users.noreply.github.com> Date: Mon, 10 Apr 2023 20:34:27 +0200 Subject: [PATCH 3/5] resolve conflicts --- src/app/pages/sagas/edit-saga/edit-saga.page.ts | 6 +++--- src/app/pages/sagas/list-sagas/list-sagas.page.ts | 2 +- src/app/services/sagas/saga.service.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/pages/sagas/edit-saga/edit-saga.page.ts b/src/app/pages/sagas/edit-saga/edit-saga.page.ts index 1d718bd..45dd067 100644 --- a/src/app/pages/sagas/edit-saga/edit-saga.page.ts +++ b/src/app/pages/sagas/edit-saga/edit-saga.page.ts @@ -46,7 +46,7 @@ export class EditSagaPage implements OnInit { } ngOnInit() { - var sagaId: number = +this.activatedRoute.snapshot.paramMap.get('id'); + var sagaId: number = +this.activatedRoute.snapshot.paramMap.get('id')!; this.loadingController.create({ message: 'Téléchargement...' }).then((loading) => { @@ -83,7 +83,7 @@ export class EditSagaPage implements OnInit { } } - onBannerChange(event) { + onBannerChange(event : any) { if (event.target.files.length > 0) { const file = event.target.files[0]; if(file.size <= this.fileService.maxFileSize) { @@ -95,7 +95,7 @@ export class EditSagaPage implements OnInit { } } - onCoverChange(event) { + onCoverChange(event : any) { if (event.target.files.length > 0) { const file = event.target.files[0]; if(file.size <= this.fileService.maxFileSize) { diff --git a/src/app/pages/sagas/list-sagas/list-sagas.page.ts b/src/app/pages/sagas/list-sagas/list-sagas.page.ts index 1a0b10e..c25fb25 100644 --- a/src/app/pages/sagas/list-sagas/list-sagas.page.ts +++ b/src/app/pages/sagas/list-sagas/list-sagas.page.ts @@ -88,7 +88,7 @@ export class ListSagasPage implements OnInit { }); } - createSagaFromPdf(event) { + createSagaFromPdf(event: any) { const file = event.target.files[0]; this.sagaService.uploadPdf(file) .subscribe(res => { diff --git a/src/app/services/sagas/saga.service.ts b/src/app/services/sagas/saga.service.ts index 662a1a8..bf30657 100644 --- a/src/app/services/sagas/saga.service.ts +++ b/src/app/services/sagas/saga.service.ts @@ -34,7 +34,7 @@ export class SagaService { return this.http.post(`${this.configService.get('apiUrl')}/saga`, saga); } - uploadPdf(file): Observable { + uploadPdf(file : any): Observable { let formData = new FormData(); formData.append("file", file, file.name); return this.http.post(`${this.configService.get('apiUrl')}/saga/pdf`, formData); From b1fc60f83bc6664d6f2dcb55a29a5d8e6ea14f39 Mon Sep 17 00:00:00 2001 From: Titohma <102875311+Titohma@users.noreply.github.com> Date: Mon, 10 Apr 2023 22:01:13 +0200 Subject: [PATCH 4/5] feat: implement saga update --- .../edit-episode/edit-episode.page.ts | 2 + .../pages/sagas/edit-saga/edit-saga.page.html | 16 ++- .../pages/sagas/edit-saga/edit-saga.page.ts | 114 +++++++++++++++--- .../pages/sagas/view-saga/view-saga.page.html | 3 +- .../pages/sagas/view-saga/view-saga.page.ts | 6 +- src/app/services/sagas/saga.service.ts | 4 + 6 files changed, 121 insertions(+), 24 deletions(-) diff --git a/src/app/pages/episodes/edit-episode/edit-episode.page.ts b/src/app/pages/episodes/edit-episode/edit-episode.page.ts index 3e085bc..73f8f90 100644 --- a/src/app/pages/episodes/edit-episode/edit-episode.page.ts +++ b/src/app/pages/episodes/edit-episode/edit-episode.page.ts @@ -108,6 +108,7 @@ export class EditEpisodePage implements OnInit { this.episodeService.update(episode) .subscribe(data => { console.debug(data); + this.navCtrl.navigateForward("sagas/" + this.saga.id) loading.dismiss(); }, error => { console.error(error); @@ -118,6 +119,7 @@ export class EditEpisodePage implements OnInit { this.episodeService.update(episode) .subscribe(data => { console.debug(data); + this.navCtrl.navigateForward("sagas/" + this.saga.id) loading.dismiss(); }, error => { console.error(error); diff --git a/src/app/pages/sagas/edit-saga/edit-saga.page.html b/src/app/pages/sagas/edit-saga/edit-saga.page.html index b0a0142..f1fb6c1 100644 --- a/src/app/pages/sagas/edit-saga/edit-saga.page.html +++ b/src/app/pages/sagas/edit-saga/edit-saga.page.html @@ -24,7 +24,15 @@ - Status + URL + + + + URL Wiki + + + + Etat @@ -36,7 +44,11 @@ - Awards + Génèse + + + + Récompenses diff --git a/src/app/pages/sagas/edit-saga/edit-saga.page.ts b/src/app/pages/sagas/edit-saga/edit-saga.page.ts index 45dd067..3ea6614 100644 --- a/src/app/pages/sagas/edit-saga/edit-saga.page.ts +++ b/src/app/pages/sagas/edit-saga/edit-saga.page.ts @@ -2,7 +2,9 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; import { LoadingController, NavController } from '@ionic/angular'; +import { forkJoin, map } from 'rxjs'; import { Saga } from 'src/app/entities/saga'; +import { SagaModel } from 'src/app/models/saga/saga.model'; import { AuthService } from 'src/app/services/auth/auth.service'; import { ConfigService } from 'src/app/services/config/config.service'; import { FileService } from 'src/app/services/file/file.service'; @@ -31,19 +33,22 @@ export class EditSagaPage implements OnInit { public configService: ConfigService, private fileService: FileService, private sagaService: SagaService) { - - this.sagaForm = this.fb.group({ - title: ['', [Validators.required]], - status: [], - synopsis: [], - origin: [], - awards: [], - banner: [''], - bannerSource: [''], - cover: [''], - coverSource: [''] - }); - } + + this.sagaForm = this.fb.group({ + title: ['', [Validators.required]], + url: [], + urlWiki: [], + status: [], + synopsis: [], + origin: [], + genese: [], + awards: [], + banner: [''], + bannerSource: [''], + cover: [''], + coverSource: [''] + }); + } ngOnInit() { var sagaId: number = +this.activatedRoute.snapshot.paramMap.get('id')!; @@ -68,14 +73,87 @@ export class EditSagaPage implements OnInit { } } + updateSaga(loading: HTMLIonLoadingElement, saga: SagaModel) { + this.sagaService.update(saga) + .subscribe({ + next: (data) => { + console.debug(data); + loading.dismiss(); + this.navCtrl.navigateForward("sagas/" + this.saga.id) + }, + error: error => { + console.error(error); + loading.dismiss(); + } + } + ); + } + async save() { this.attemptedSubmit = true; - if (this.sagaForm.valid) { + if (this.sagaForm.valid) { const controls = this.sagaForm.controls; this.loadingController.create({ message: 'Sauvegarde en cours...' }).then((loading) => { loading.present(); + + // Fields from form + let saga = new SagaModel(); + saga.title = controls['title'].value; + saga.url = controls['url'].value; + saga.urlWiki = controls['urlWiki'].value; + saga.status = controls['status'].value; + saga.synopsis = controls['synopsis'].value; + saga.origin = controls['origin'].value; + saga.genese = controls['genese'].value; + saga.awards = controls['awards'].value; + + // Fields from DB + saga.id = this.saga.id; + saga.startDate = this.saga.startDate; + saga.duration = this.saga.duration; + saga.levelArt = this.saga.levelArt; + saga.levelTech = this.saga.levelTech; + saga.nbReviews = this.saga.nbReviews; + saga.urlReviews = this.saga.urlReviews; + saga.nbBravos = this.saga.nbBravos; + saga.workspace = this.saga.workspace; + + if (controls['bannerSource'].value && controls['coverSource'].value) { + const banner = this.fileService.upload(controls['bannerSource'].value, "sagas/" + this.saga.workspace + "/images", "banner"); + const cover = this.fileService.upload(controls['coverSource'].value, "sagas/" + this.saga.workspace + "/images", "cover"); + forkJoin([banner, cover]) + .pipe(map(responses => { + saga.bannerUrl = responses[0].url; + saga.coverUrl = responses[1].url; + this.updateSaga(loading, saga); + })) + .subscribe(); + } else if (controls['bannerSource'].value && !controls['coverSource'].value) { + this.fileService.upload(controls['bannerSource'].value, "sagas/" + this.saga.workspace + "/images", "banner") + .subscribe({ + next: (data) => { + saga.bannerUrl = data.url; + saga.coverUrl = this.saga.coverUrl; + this.updateSaga(loading, saga); + } + }); + } else if (!controls['bannerSource'].value && controls['coverSource'].value) { + this.fileService.upload(controls['coverSource'].value, "sagas/" + this.saga.workspace + "/images", "cover") + .subscribe({ + next: (data) => { + saga.bannerUrl = this.saga.bannerUrl; + saga.coverUrl = data.url; + this.updateSaga(loading, saga); + } + }); + } else { + saga.bannerUrl = this.saga.bannerUrl; + saga.coverUrl = this.saga.coverUrl; + this.updateSaga(loading, saga); + } + loading.dismiss(); }); } else { @@ -83,10 +161,10 @@ export class EditSagaPage implements OnInit { } } - onBannerChange(event : any) { + onBannerChange(event: any) { if (event.target.files.length > 0) { const file = event.target.files[0]; - if(file.size <= this.fileService.maxFileSize) { + if (file.size <= this.fileService.maxFileSize) { this.sagaForm.patchValue({ bannerSource: file }); @@ -95,10 +173,10 @@ export class EditSagaPage implements OnInit { } } - onCoverChange(event : any) { + onCoverChange(event: any) { if (event.target.files.length > 0) { const file = event.target.files[0]; - if(file.size <= this.fileService.maxFileSize) { + if (file.size <= this.fileService.maxFileSize) { this.sagaForm.patchValue({ coverSource: file }); 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 833bae6..bd5a2e0 100644 --- a/src/app/pages/sagas/view-saga/view-saga.page.html +++ b/src/app/pages/sagas/view-saga/view-saga.page.html @@ -14,7 +14,8 @@ -
+
+
diff --git a/src/app/pages/sagas/view-saga/view-saga.page.ts b/src/app/pages/sagas/view-saga/view-saga.page.ts index 6466586..8a3fe16 100644 --- a/src/app/pages/sagas/view-saga/view-saga.page.ts +++ b/src/app/pages/sagas/view-saga/view-saga.page.ts @@ -56,9 +56,9 @@ export class ViewSagaPage implements OnInit { }); } - bannerUrl(): string { + bannerUrl(): any { if(this.item.bannerUrl) { - return 'url(' + this.configService.get('appUrl') + this.item.bannerUrl + ')'; + return {'background-image': 'url(' + this.configService.get('apiUrl') + "/files/image" + this.item.bannerUrl + ')'} } else { return ''; } @@ -66,7 +66,7 @@ export class ViewSagaPage implements OnInit { coverUrl(): string { if(this.item.coverUrl) { - return this.configService.get('appUrl') + this.item.coverUrl; + return this.configService.get('apiUrl') + "/files/image" + this.item.coverUrl; } else { return ''; } diff --git a/src/app/services/sagas/saga.service.ts b/src/app/services/sagas/saga.service.ts index bf30657..17587ae 100644 --- a/src/app/services/sagas/saga.service.ts +++ b/src/app/services/sagas/saga.service.ts @@ -34,6 +34,10 @@ export class SagaService { return this.http.post(`${this.configService.get('apiUrl')}/saga`, saga); } + update(episode: SagaModel) { + return this.http.put(`${this.configService.get('apiUrl')}/saga`, episode); + } + uploadPdf(file : any): Observable { let formData = new FormData(); formData.append("file", file, file.name); From a519ce4b336bacb5a0895241aadcbc9fd08af1dc Mon Sep 17 00:00:00 2001 From: Titohma <102875311+Titohma@users.noreply.github.com> Date: Sat, 15 Apr 2023 12:53:13 +0200 Subject: [PATCH 5/5] bump project version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d109bb0..26e8188 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "les-sagas-mp3", - "version": "0.10.1", + "version": "0.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "les-sagas-mp3", - "version": "0.10.1", + "version": "0.11.0", "dependencies": { "@angular/common": "^15.0.0", "@angular/core": "^15.0.0", diff --git a/package.json b/package.json index 37a0212..78c9106 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "les-sagas-mp3", - "version": "0.10.1", + "version": "0.11.0", "author": "Les Sagas MP3", "homepage": "https://github.com/Les-Sagas-MP3", "scripts": {