diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.html b/src/app/modules/admin/components/formulaire/formulaire.component.html index 5d65f00..c30ea4f 100644 --- a/src/app/modules/admin/components/formulaire/formulaire.component.html +++ b/src/app/modules/admin/components/formulaire/formulaire.component.html @@ -1,5 +1,5 @@
-
+
Ajouter une plante - + diff --git a/src/app/modules/admin/pages/page-modifier/page-modifier.component.html b/src/app/modules/admin/pages/page-modifier/page-modifier.component.html index de5769d..a7a2fe3 100644 --- a/src/app/modules/admin/pages/page-modifier/page-modifier.component.html +++ b/src/app/modules/admin/pages/page-modifier/page-modifier.component.html @@ -1,2 +1,2 @@

Modifier la plante

- + diff --git a/src/app/modules/admin/pages/page-modifier/page-modifier.component.ts b/src/app/modules/admin/pages/page-modifier/page-modifier.component.ts index 0f439fb..a656787 100644 --- a/src/app/modules/admin/pages/page-modifier/page-modifier.component.ts +++ b/src/app/modules/admin/pages/page-modifier/page-modifier.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; -import { ActivatedRoute, Router } from '@angular/router'; +import { FormBuilder,FormGroup} from '@angular/forms'; +import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { Plant } from '../../models/plant'; import { AdminService } from '../../services/admin.service'; @@ -10,10 +10,8 @@ import { AdminService } from '../../services/admin.service'; styleUrls: ['./page-modifier.component.scss'] }) export class PageModifierComponent implements OnInit { - plantForm: FormGroup; - updatePlantForm: FormGroup; - plantInfos: any; - plantId: any; + editPlant!: Plant; + plantId!: string; @@ -21,61 +19,54 @@ export class PageModifierComponent implements OnInit { private router: Router, private fb: FormBuilder, private route: ActivatedRoute) { - this.updatePlantForm = new FormGroup({}); - this.plantForm = this.initForm(); } ngOnInit(): void { - /** Pour récuperer l'id de la plante à modifier **/ - this.plantId = this.route.snapshot.paramMap.get('id'); + /** Pour récuperer l'id de la plante à modifier et appel Api**/ + this.route.paramMap.subscribe((params : ParamMap) => { + const id = params.get('id') + if( id != null){ + this.plantId = id; + console.log(this.plantId); - /** Appel Api **/ - this.adminService - .getPlantById(this.plantId) - .subscribe((plantInfos: any) => { - this.plantInfos = plantInfos; - console.log(this.plantInfos); - console.log(this.plantInfos.product_name); - }); - } - - /** Méthode qui initialise les champs du formulaire avec les infos du db Json **/ - private initForm(plant?: Plant): FormGroup { - - return this.fb.group({ - nom:[plant ? plant.name : ''], - price: [plant ? plant.price : ''], - quantity: [plant ? plant.quantity : ''], - category: [plant ? plant.category : ''], - rating: [plant ? plant.rating : ''], - inStock: [plant ? plant.inStock : ['']], + this.adminService + .getPlantById(this.plantId) + .subscribe((plantData: any) => { + this.editPlant = plantData; + console.log(this.editPlant); + console.log(this.editPlant.name); + }); + } }); + } + /** Méthode qui envoie les champs modifiés pour mise à jour **/ - public onSubmit(): void { - const nameValue = this.updatePlantForm.value['nameFc']; - const priceValue = this.updatePlantForm.value['priceFc']; - const ratingValue = this.updatePlantForm.value['ratingFc']; - const quantityValue = this.updatePlantForm.value['quantityFc']; - const categoryValue = this.updatePlantForm.value['categoryFc']; - const inStockValue = this.updatePlantForm.value['inStockFc']; - const urlPicture = "https//picsum.photos/id/18/200/300"; + public update(event: any): void { + console.log(event); + // const nameValue = this.updatePlantForm.value['nameFc']; + // const priceValue = this.updatePlantForm.value['priceFc']; + // const ratingValue = this.updatePlantForm.value['ratingFc']; + // const quantityValue = this.updatePlantForm.value['quantityFc']; + // const categoryValue = this.updatePlantForm.value['categoryFc']; + // const inStockValue = this.updatePlantForm.value['inStockFc']; + // const urlPicture = "https//picsum.photos/id/18/200/300"; - const plant: Plant = { - id: this.plantId, - name: nameValue, - price: priceValue, - quantity: quantityValue, - rating: ratingValue, - category: categoryValue, - inStock: [inStockValue], - urlPicture - }; - this.adminService.updatePlant(plant)?.subscribe((resp) => { - this.router.navigate(['admin']); - }); + // const plant: Plant = { + // id: this.plantId, + // name: nameValue, + // price: priceValue, + // quantity: quantityValue, + // rating: ratingValue, + // category: categoryValue, + // inStock: [inStockValue], + // urlPicture + // }; + // this.adminService.updatePlant(plant)?.subscribe((resp) => { + // this.router.navigate(['admin']); + // }); } }