From ee364b64ec74fee272c89cffc60122489a9b660a Mon Sep 17 00:00:00 2001 From: FazCodeFR <30906528+FazCodeFR@users.noreply.github.com> Date: Thu, 12 Sep 2024 20:41:11 +0200 Subject: [PATCH 1/3] wip create-edit cat --- src/app/app-routing.module.ts | 5 + src/app/app.module.ts | 2 + .../animaux-details.component.html | 153 +----------- .../animaux-edit/animaux-edit.component.html | 219 ++++++++++++++++++ .../animaux-edit/animaux-edit.component.scss | 0 .../animaux-edit.component.spec.ts | 21 ++ .../animaux-edit/animaux-edit.component.ts | 110 +++++++++ .../animaux-list/animaux-list.component.html | 8 + src/app/services/app.service.ts | 8 + 9 files changed, 383 insertions(+), 143 deletions(-) create mode 100644 src/app/components/animaux/animaux-edit/animaux-edit.component.html create mode 100644 src/app/components/animaux/animaux-edit/animaux-edit.component.scss create mode 100644 src/app/components/animaux/animaux-edit/animaux-edit.component.spec.ts create mode 100644 src/app/components/animaux/animaux-edit/animaux-edit.component.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b01099d..d83c355 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -17,6 +17,7 @@ import { AuthGuard } from '@auth0/auth0-angular'; import { TchatComponent } from './components/tchat/tchat.component'; import { AssociationsDetailsComponent } from './components/associations/associations-details/associations-details.component'; import { BugComponent } from './components/bug/bug.component'; +import { AnimauxEditComponent } from './components/animaux/animaux-edit/animaux-edit.component'; const routes: Routes = [ { @@ -41,6 +42,10 @@ const routes: Routes = [ path: 'contact', component: ContactComponent, }, + { + path: 'animaux/ajouter', + component: AnimauxEditComponent, + }, { path: 'animaux/:id', component: AnimauxDetailsComponent, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d61cf8e..1cd01d5 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -49,6 +49,7 @@ import { BugComponent } from './components/bug/bug.component'; import { AssociationsDetailsComponent } from './components/associations/associations-details/associations-details.component'; import { PaginatorModule } from 'primeng/paginator'; import { AssociationsFormComponent } from './components/associations/associations-form/associations-form.component'; +import { AnimauxEditComponent } from './components/animaux/animaux-edit/animaux-edit.component'; @NgModule({ @@ -76,6 +77,7 @@ import { AssociationsFormComponent } from './components/associations/association AssociationsDetailsComponent, BugComponent, AssociationsFormComponent, + AnimauxEditComponent, ], imports: [ BrowserModule, diff --git a/src/app/components/animaux/animaux-details/animaux-details.component.html b/src/app/components/animaux/animaux-details/animaux-details.component.html index cff2fb6..7bf9ada 100644 --- a/src/app/components/animaux/animaux-details/animaux-details.component.html +++ b/src/app/components/animaux/animaux-details/animaux-details.component.html @@ -1,18 +1,16 @@ -
+
+ +
+ +

Catégorie : Chat

- - -

-

@@ -36,42 +33,11 @@

-
- - -
-
- - -
- -
- -

@@ -87,31 +53,6 @@

-
-
-
-
- - -
-
- - -
-
-
-

@@ -153,51 +88,8 @@

-
- - - - -
- -
- - - - -
- -
- - - - -
- - -
@@ -247,11 +116,6 @@

Santé :

- - + + + +
+

+ +

+
+ + +
+ +
+
+ +
+ + +
+
+
+
+ +
+ + +
+
+
+ + + +
+ +
+
+ +
+
+ +
+
+
+
+ + +
+
+ + +
+
+
+
+
+
+ +

+ J'ai + + ans +

+ +
+ +
+ +

+ Je suis un {{chat.race}} +

+
+ +
+ + +
+
+ + + + +
+ +
+ + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +

+ Je suis actuellement chouchouté par l'association + {{ chat.association.nom }} +

+
+
+
+ + +
+ + + +
+ + + + \ No newline at end of file diff --git a/src/app/components/animaux/animaux-edit/animaux-edit.component.scss b/src/app/components/animaux/animaux-edit/animaux-edit.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/animaux/animaux-edit/animaux-edit.component.spec.ts b/src/app/components/animaux/animaux-edit/animaux-edit.component.spec.ts new file mode 100644 index 0000000..02ede79 --- /dev/null +++ b/src/app/components/animaux/animaux-edit/animaux-edit.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AnimauxEditComponent } from './animaux-edit.component'; + +describe('AnimauxEditComponent', () => { + let component: AnimauxEditComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [AnimauxEditComponent] + }); + fixture = TestBed.createComponent(AnimauxEditComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/animaux/animaux-edit/animaux-edit.component.ts b/src/app/components/animaux/animaux-edit/animaux-edit.component.ts new file mode 100644 index 0000000..d9efe3e --- /dev/null +++ b/src/app/components/animaux/animaux-edit/animaux-edit.component.ts @@ -0,0 +1,110 @@ +import { Component, Input } from '@angular/core'; +import { ToastrService } from 'ngx-toastr'; +import { AppService } from '../../../services/app.service'; +import { UserService } from '../../../services/user.service'; +import { Chat, Sexe } from '../../../interfaces/interfaces'; +import { faMars, faTrash, faUpload, faVenus, faHeart } from '@fortawesome/free-solid-svg-icons'; +import { faHeart as fasHeart } from '@fortawesome/free-regular-svg-icons'; + +@Component({ + selector: 'app-animaux-edit', + templateUrl: './animaux-edit.component.html', + styleUrls: ['./animaux-edit.component.scss'] +}) +export class AnimauxEditComponent { + @Input() chat: Chat | undefined; + @Input() isCreationMode: boolean = false; + isLoaded: boolean = false; + sexe = Sexe; + faMars = faMars; + faVenus = faVenus; + faTrash = faTrash; + faUpload = faUpload; + faHeart = faHeart; + fasHeart = fasHeart; + dataModel: any; + isAuthenticated: boolean = false; + + + constructor( + private appService: AppService, + private toastr: ToastrService, + public userService: UserService, + ) {} + + ngOnInit() { + this.initializeChat(); + } + + private initializeChat() { + if (!this.chat) { + this.chat = this.createDefaultChat(); + this.isCreationMode = true; + } else { + this.isCreationMode = false; + } + } + + private createDefaultChat(): Chat { + return { + description: `

Le chat est ....

+

Voici quelques questions pour vous aider à décrire votre chat :

+ +

Répondez à ces questions pour compléter la description de votre chat !

`, + ententeChien: true, + ententeChat: true, + ententeEnfant: true, + sexe: Sexe.MALE, + age: 1, + } as Chat; + } + + submitForm() { + if (!this.isCreationMode) { + this.updateChat(); + } else { + this.saveChat(); + } + } + + + saveChat() { + // Function to create a new chat + this.appService.createChat(this.chat!).subscribe({ + error: (error) => { + console.error('error:', error); + this.toastr.error('Erreur lors de la création du chat'); + }, + complete: () => { + this.toastr.success('Chat créé avec succès'); + }, + }); + } + + updateChat() { + this.appService.updateChat(this.chat!).subscribe({ + error: (error) => { + console.error('error:', error); + if (error?.error?.message) { + this.toastr.error( + error.error.message, + 'Erreur de mise à jour du chat' + ); + } else { + this.toastr.error('Erreur de mise à jour du chat'); + } + }, + complete: () => { + this.toastr.success('Chat mis à jour avec succès'); + }, + }); + } +} diff --git a/src/app/components/animaux/animaux-list/animaux-list.component.html b/src/app/components/animaux/animaux-list/animaux-list.component.html index e5515b6..c94f135 100644 --- a/src/app/components/animaux/animaux-list/animaux-list.component.html +++ b/src/app/components/animaux/animaux-list/animaux-list.component.html @@ -38,9 +38,17 @@

Les chat
+ +

Nombre de chats disponibles : {{ chats.length }}

+
diff --git a/src/app/services/app.service.ts b/src/app/services/app.service.ts index b9cb877..03c0093 100644 --- a/src/app/services/app.service.ts +++ b/src/app/services/app.service.ts @@ -76,6 +76,14 @@ export class AppService { ); } + createChat(chat: Chat): Observable { + return this.http.post(this.api + '/chats', chat).pipe( + map((res: any) => res), + share(), + take(1) + ); + } + getAllAsso(): Observable { return this.http.get(this.api + '/associations').pipe( map((res: any) => res), From 407025b14e5e57e4ae92c498e142d9845ed36457 Mon Sep 17 00:00:00 2001 From: FazCodeFR <30906528+FazCodeFR@users.noreply.github.com> Date: Sun, 15 Sep 2024 12:32:53 +0200 Subject: [PATCH 2/3] Wip img --- .../animaux-details.component.html | 4 +- .../animaux-details.component.ts | 21 +--- .../animaux-edit/animaux-edit.component.html | 81 ++++++++------ .../animaux-edit/animaux-edit.component.ts | 101 +++++++++++++++--- .../animaux-list/animaux-list.component.html | 4 +- .../animaux-list/animaux-list.component.ts | 2 + src/app/services/app.service.ts | 9 +- src/environments/environment.model.ts | 1 + src/environments/environment.prod.ts | 1 + src/environments/environment.ts | 1 + 10 files changed, 150 insertions(+), 75 deletions(-) diff --git a/src/app/components/animaux/animaux-details/animaux-details.component.html b/src/app/components/animaux/animaux-details/animaux-details.component.html index 7bf9ada..7898e94 100644 --- a/src/app/components/animaux/animaux-details/animaux-details.component.html +++ b/src/app/components/animaux/animaux-details/animaux-details.component.html @@ -32,10 +32,10 @@

- +
- +

diff --git a/src/app/components/animaux/animaux-details/animaux-details.component.ts b/src/app/components/animaux/animaux-details/animaux-details.component.ts index 5325df0..3e83a17 100644 --- a/src/app/components/animaux/animaux-details/animaux-details.component.ts +++ b/src/app/components/animaux/animaux-details/animaux-details.component.ts @@ -10,6 +10,7 @@ import { ToastrService } from 'ngx-toastr'; import { AuthService } from '@auth0/auth0-angular'; import { UserService } from '../../../services/user.service'; import { Subscription, firstValueFrom } from 'rxjs'; +import { environment } from 'src/environments/environment'; @Component({ selector: 'app-animaux-details', @@ -31,6 +32,7 @@ export class AnimauxDetailsComponent { isEditMode: boolean = false; isAuthenticated: boolean = false; private subscriptions = new Subscription(); + s3Url = environment.s3Url; constructor( private route: ActivatedRoute, @@ -69,25 +71,6 @@ export class AnimauxDetailsComponent { }); } - updateChat() { - this.appService.updateChat(this.chat!).subscribe({ - error: (error) => { - console.error('error:', error); - if (error?.error?.message) { - this.toastr.error( - error.error.message, - 'Erreur de mise à jour du chat' - ); - } else { - this.toastr.error('Erreur de mise à jour du chat'); - } - }, - complete: () => { - this.toastr.success('Chat mis à jour avec succès'); - this.isEditMode = false; - }, - }); - } getFavs() { const favSubscription = this.appService.getFavorisByUser().subscribe({ next: (favoriIds: number[]) => { diff --git a/src/app/components/animaux/animaux-edit/animaux-edit.component.html b/src/app/components/animaux/animaux-edit/animaux-edit.component.html index d63b2e6..6ebfb02 100644 --- a/src/app/components/animaux/animaux-edit/animaux-edit.component.html +++ b/src/app/components/animaux/animaux-edit/animaux-edit.component.html @@ -26,48 +26,65 @@

-
- + +
+
+
- + +
+
+ +
+
+ +
+ + - +
+
-
-
- -
- - -
+ +
+
+ +
+
+
- - +
- + +
-
+
+ + + +
diff --git a/src/app/components/animaux/animaux-edit/animaux-edit.component.ts b/src/app/components/animaux/animaux-edit/animaux-edit.component.ts index d9efe3e..9bfec9a 100644 --- a/src/app/components/animaux/animaux-edit/animaux-edit.component.ts +++ b/src/app/components/animaux/animaux-edit/animaux-edit.component.ts @@ -1,17 +1,20 @@ -import { Component, Input } from '@angular/core'; +import { Component, ElementRef, Input, ChangeDetectorRef, AfterViewChecked, ChangeDetectionStrategy } from '@angular/core'; import { ToastrService } from 'ngx-toastr'; import { AppService } from '../../../services/app.service'; import { UserService } from '../../../services/user.service'; import { Chat, Sexe } from '../../../interfaces/interfaces'; import { faMars, faTrash, faUpload, faVenus, faHeart } from '@fortawesome/free-solid-svg-icons'; import { faHeart as fasHeart } from '@fortawesome/free-regular-svg-icons'; +import { environment } from 'src/environments/environment'; +import { NgZone } from '@angular/core'; @Component({ selector: 'app-animaux-edit', templateUrl: './animaux-edit.component.html', - styleUrls: ['./animaux-edit.component.scss'] + styleUrls: ['./animaux-edit.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush }) -export class AnimauxEditComponent { +export class AnimauxEditComponent implements AfterViewChecked{ @Input() chat: Chat | undefined; @Input() isCreationMode: boolean = false; isLoaded: boolean = false; @@ -24,18 +27,25 @@ export class AnimauxEditComponent { fasHeart = fasHeart; dataModel: any; isAuthenticated: boolean = false; - - + selectedFiles: File[] = []; + s3Url = environment.s3Url; constructor( private appService: AppService, private toastr: ToastrService, public userService: UserService, + private cdr: ChangeDetectorRef, + private zone: NgZone ) {} ngOnInit() { this.initializeChat(); } + ngAfterViewChecked() { + // Code à exécuter après que la vue ait été vérifiée + // this.cdr.detectChanges(); + } + private initializeChat() { if (!this.chat) { this.chat = this.createDefaultChat(); @@ -76,9 +86,59 @@ export class AnimauxEditComponent { } + onFileSelected(event: Event, existingPhoto: any) { + const input = event.target as HTMLInputElement; + if (input.files && input.files.length > 0) { + const file = input.files[0]; + + // Replace the existing photo with the new file + this.replacePhoto(existingPhoto, file); + } + } + + onFilesSelected(event: Event) { + const input = event.target as HTMLInputElement; + if (input.files && input.files.length > 0) { + this.zone.run(() => { + for (let i = 0; i < input!.files!.length; i++) { + this.selectedFiles.push(input!.files![i]); + } + this.cdr.detectChanges(); // Ou markForCheck ici si OnPush + }); + } + } + + + + replacePhoto(existingPhoto: any, newFile: File) { + const index = this.chat!.photos.indexOf(existingPhoto); + if (index > -1) { + this.chat!.photos.splice(index, 1); + } + + this.selectedFiles.push(newFile); + + // Délai court pour attendre la fin du cycle de détection du changement + setTimeout(() => { + this.cdr.detectChanges(); // Force la détection de changement + }, 0); + } + + + getFileUrl(file: File): string { + return URL.createObjectURL(file); + } + + saveChat() { - // Function to create a new chat - this.appService.createChat(this.chat!).subscribe({ + const formData = new FormData(); + formData.append('chat', JSON.stringify(this.chat)); + + this.selectedFiles.forEach((file) => { + formData.append('photos', file, file.name); + }); + + this.appService.createChat(formData).subscribe({ error: (error) => { console.error('error:', error); this.toastr.error('Erreur lors de la création du chat'); @@ -89,18 +149,27 @@ export class AnimauxEditComponent { }); } + removePhoto(file : File) { + const index = this.selectedFiles.indexOf(file); + console.log('🚀 ~ AnimauxEditComponent ~ removePhoto ~ index:', index); + if (index > -1) { + this.selectedFiles.splice(index, 1); + } + } + + updateChat() { - this.appService.updateChat(this.chat!).subscribe({ + const formData = new FormData(); + formData.append('chat', JSON.stringify(this.chat)); + + this.selectedFiles.forEach((file) => { + formData.append('photos', file, file.name); + }); + + this.appService.updateChat(this.chat!.id, formData).subscribe({ error: (error) => { console.error('error:', error); - if (error?.error?.message) { - this.toastr.error( - error.error.message, - 'Erreur de mise à jour du chat' - ); - } else { - this.toastr.error('Erreur de mise à jour du chat'); - } + this.toastr.error('Erreur de mise à jour du chat'); }, complete: () => { this.toastr.success('Chat mis à jour avec succès'); diff --git a/src/app/components/animaux/animaux-list/animaux-list.component.html b/src/app/components/animaux/animaux-list/animaux-list.component.html index c94f135..6a62981 100644 --- a/src/app/components/animaux/animaux-list/animaux-list.component.html +++ b/src/app/components/animaux/animaux-list/animaux-list.component.html @@ -56,12 +56,12 @@

Les chat
-
-

+

{{chat.association.nom}} - {{formatDate(chat.createdAt)}} diff --git a/src/app/components/animaux/animaux-list/animaux-list.component.ts b/src/app/components/animaux/animaux-list/animaux-list.component.ts index 556457a..3c78757 100644 --- a/src/app/components/animaux/animaux-list/animaux-list.component.ts +++ b/src/app/components/animaux/animaux-list/animaux-list.component.ts @@ -11,6 +11,7 @@ import { AuthService } from '@auth0/auth0-angular'; import { Subscription, firstValueFrom } from 'rxjs'; import { PaginatorState } from 'primeng/paginator'; import { FormBuilder, FormGroup } from '@angular/forms'; +import { environment } from 'src/environments/environment'; @Component({ selector: 'app-animaux-list', @@ -32,6 +33,7 @@ export class AnimauxListComponent { chats: Chat[] = []; favoris: Favori[] = []; associations: Association[] = []; + s3Url = environment.s3Url; private subscriptions = new Subscription(); diff --git a/src/app/services/app.service.ts b/src/app/services/app.service.ts index 03c0093..67283a5 100644 --- a/src/app/services/app.service.ts +++ b/src/app/services/app.service.ts @@ -68,22 +68,23 @@ export class AppService { ); } - updateChat(chat: Chat): Observable { - return this.http.put(this.api + '/chats/' + chat.id, chat).pipe( + updateChat(id: number, formData: FormData): Observable { + return this.http.put(this.api + `/chats/${id}`, formData).pipe( map((res: any) => res), share(), take(1) ); } - createChat(chat: Chat): Observable { - return this.http.post(this.api + '/chats', chat).pipe( + createChat(formData: FormData): Observable { + return this.http.post(this.api + '/chats', formData).pipe( map((res: any) => res), share(), take(1) ); } + getAllAsso(): Observable { return this.http.get(this.api + '/associations').pipe( map((res: any) => res), diff --git a/src/environments/environment.model.ts b/src/environments/environment.model.ts index d10aff6..8b253f7 100644 --- a/src/environments/environment.model.ts +++ b/src/environments/environment.model.ts @@ -13,4 +13,5 @@ export interface Environment { api: { serverUrl: string; }; + s3Url: string; } diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index f70fa38..e3637fd 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -15,4 +15,5 @@ export const environment: Environment = { api: { serverUrl: 'https://api.potits-chats.com', }, + s3Url: 'https://potits-chats.s3.eu-west-3.amazonaws.com/public/', }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index b3838af..ea67d27 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -15,4 +15,5 @@ export const environment: Environment = { api: { serverUrl: 'http://localhost:3000', }, + s3Url: 'https://potits-chats.s3.eu-west-3.amazonaws.com/public/', }; From 6943a1f503bfa93441ff6763c5109c87a73b3a74 Mon Sep 17 00:00:00 2001 From: FazCodeFR <30906528+FazCodeFR@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:41:06 +0200 Subject: [PATCH 3/3] Update et create cat --- .../animaux-details.component.html | 4 +- .../animaux-edit/animaux-edit.component.html | 56 ++++++++----------- .../animaux-edit/animaux-edit.component.ts | 36 ++++++------ .../animaux-list/animaux-list.component.html | 2 +- .../animaux-list/animaux-list.component.ts | 4 +- .../associations-details.component.html | 4 +- src/app/services/app.service.ts | 10 +++- 7 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/app/components/animaux/animaux-details/animaux-details.component.html b/src/app/components/animaux/animaux-details/animaux-details.component.html index 7898e94..a13692c 100644 --- a/src/app/components/animaux/animaux-details/animaux-details.component.html +++ b/src/app/components/animaux/animaux-details/animaux-details.component.html @@ -32,10 +32,10 @@

- +
- +

diff --git a/src/app/components/animaux/animaux-edit/animaux-edit.component.html b/src/app/components/animaux/animaux-edit/animaux-edit.component.html index 6ebfb02..0d96456 100644 --- a/src/app/components/animaux/animaux-edit/animaux-edit.component.html +++ b/src/app/components/animaux/animaux-edit/animaux-edit.component.html @@ -6,17 +6,21 @@

- - -
+

@@ -26,32 +30,12 @@

-
-
- -
- - -
-
-
-
- -
- - - @@ -229,8 +213,16 @@

- Sauvegarder + class="flex mx-auto mt-16 py-2 px-8 border-0 focus:outline-none rounded text-lg bg-orange-700 text-white hover:bg-orange-800 active:bg-orange-600 active:text-white focus-visible:outline-orange-700"> + Mettre à jour + +

\ No newline at end of file diff --git a/src/app/components/animaux/animaux-edit/animaux-edit.component.ts b/src/app/components/animaux/animaux-edit/animaux-edit.component.ts index 9bfec9a..86f3dca 100644 --- a/src/app/components/animaux/animaux-edit/animaux-edit.component.ts +++ b/src/app/components/animaux/animaux-edit/animaux-edit.component.ts @@ -2,11 +2,12 @@ import { Component, ElementRef, Input, ChangeDetectorRef, AfterViewChecked, Chan import { ToastrService } from 'ngx-toastr'; import { AppService } from '../../../services/app.service'; import { UserService } from '../../../services/user.service'; -import { Chat, Sexe } from '../../../interfaces/interfaces'; +import { Chat, Photo, Sexe } from '../../../interfaces/interfaces'; import { faMars, faTrash, faUpload, faVenus, faHeart } from '@fortawesome/free-solid-svg-icons'; import { faHeart as fasHeart } from '@fortawesome/free-regular-svg-icons'; import { environment } from 'src/environments/environment'; import { NgZone } from '@angular/core'; +import { Router } from '@angular/router'; @Component({ selector: 'app-animaux-edit', @@ -34,7 +35,8 @@ export class AnimauxEditComponent implements AfterViewChecked{ private toastr: ToastrService, public userService: UserService, private cdr: ChangeDetectorRef, - private zone: NgZone + private zone: NgZone, + private router: Router ) {} ngOnInit() { @@ -77,14 +79,6 @@ export class AnimauxEditComponent implements AfterViewChecked{ } as Chat; } - submitForm() { - if (!this.isCreationMode) { - this.updateChat(); - } else { - this.saveChat(); - } - } - onFileSelected(event: Event, existingPhoto: any) { const input = event.target as HTMLInputElement; @@ -117,10 +111,8 @@ export class AnimauxEditComponent implements AfterViewChecked{ } this.selectedFiles.push(newFile); - - // Délai court pour attendre la fin du cycle de détection du changement setTimeout(() => { - this.cdr.detectChanges(); // Force la détection de changement + this.cdr.detectChanges(); }, 0); } @@ -143,20 +135,32 @@ export class AnimauxEditComponent implements AfterViewChecked{ console.error('error:', error); this.toastr.error('Erreur lors de la création du chat'); }, - complete: () => { + next: (chat) => { this.toastr.success('Chat créé avec succès'); - }, + this.router.navigate([`/animaux/${chat.id}`]); + } }); } removePhoto(file : File) { const index = this.selectedFiles.indexOf(file); - console.log('🚀 ~ AnimauxEditComponent ~ removePhoto ~ index:', index); if (index > -1) { this.selectedFiles.splice(index, 1); } } + removePhotoOnline(photoName: string) { + this.appService.deleteChatPhoto(photoName).subscribe({ + error: (error) => { + console.error('error:', error); + this.toastr.error('Erreur lors de la suppression de la photo'); + }, + complete: () => { + this.chat!.photos = this.chat!.photos.filter((p) => p.url !== photoName); + }, + }); + } + updateChat() { const formData = new FormData(); diff --git a/src/app/components/animaux/animaux-list/animaux-list.component.html b/src/app/components/animaux/animaux-list/animaux-list.component.html index 6a62981..3bff5e9 100644 --- a/src/app/components/animaux/animaux-list/animaux-list.component.html +++ b/src/app/components/animaux/animaux-list/animaux-list.component.html @@ -38,7 +38,7 @@

Les chat
-
+
Ajouter un chat diff --git a/src/app/components/animaux/animaux-list/animaux-list.component.ts b/src/app/components/animaux/animaux-list/animaux-list.component.ts index 3c78757..558926b 100644 --- a/src/app/components/animaux/animaux-list/animaux-list.component.ts +++ b/src/app/components/animaux/animaux-list/animaux-list.component.ts @@ -12,6 +12,7 @@ import { Subscription, firstValueFrom } from 'rxjs'; import { PaginatorState } from 'primeng/paginator'; import { FormBuilder, FormGroup } from '@angular/forms'; import { environment } from 'src/environments/environment'; +import { UserService } from '../../../services/user.service'; @Component({ selector: 'app-animaux-list', @@ -55,7 +56,8 @@ export class AnimauxListComponent { private toastr: ToastrService, private fb: FormBuilder, public auth: AuthService, - @Inject(DOCUMENT) private doc: Document + @Inject(DOCUMENT) private doc: Document, + public userService: UserService, ) { this.form = this.fb.group({ ville: [''], diff --git a/src/app/components/associations/associations-details/associations-details.component.html b/src/app/components/associations/associations-details/associations-details.component.html index b5e1935..18f3024 100644 --- a/src/app/components/associations/associations-details/associations-details.component.html +++ b/src/app/components/associations/associations-details/associations-details.component.html @@ -26,7 +26,7 @@

- +