From d9800d3ae51d1056dc1d137008459b8ebae537ab Mon Sep 17 00:00:00 2001 From: Sana EL HIRI Date: Mon, 21 Mar 2022 20:51:17 +0100 Subject: [PATCH 1/3] cette branche vient remplacer feature/modifier qui est corrompue --- src/app/modules/admin/admin-routing.module.ts | 2 +- .../formulaire/formulaire.component.html | 234 ++++++++---------- .../formulaire/formulaire.component.scss | 75 ++++++ .../formulaire/formulaire.component.ts | 28 ++- src/app/modules/admin/models/plant.ts | 2 +- .../page-modifier.component.html | 3 +- .../page-modifier.component.scss | 5 + .../page-modifier/page-modifier.component.ts | 68 ++++- .../page-tableau/page-tableau.component.html | 4 +- .../modules/admin/services/admin.service.ts | 9 + 10 files changed, 293 insertions(+), 137 deletions(-) diff --git a/src/app/modules/admin/admin-routing.module.ts b/src/app/modules/admin/admin-routing.module.ts index e7225ab..ac27963 100644 --- a/src/app/modules/admin/admin-routing.module.ts +++ b/src/app/modules/admin/admin-routing.module.ts @@ -6,7 +6,7 @@ import { PageTableauComponent } from './pages/page-tableau/page-tableau.componen const routes: Routes = [ { path: '', redirectTo: 'tableau', pathMatch: 'full'}, - { path: 'modifier', component: PageModifierComponent }, + { path: 'modifier/:id', component: PageModifierComponent }, { path: 'ajouter', component: PageAjouterComponent }, { path: 'tableau', component: PageTableauComponent }, ]; diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.html b/src/app/modules/admin/components/formulaire/formulaire.component.html index 0b8b45e..45bc618 100644 --- a/src/app/modules/admin/components/formulaire/formulaire.component.html +++ b/src/app/modules/admin/components/formulaire/formulaire.component.html @@ -1,126 +1,108 @@ -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - - -
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.scss b/src/app/modules/admin/components/formulaire/formulaire.component.scss index e69de29..1b527e6 100644 --- a/src/app/modules/admin/components/formulaire/formulaire.component.scss +++ b/src/app/modules/admin/components/formulaire/formulaire.component.scss @@ -0,0 +1,75 @@ +.login-form { + height: 100vh; + padding-top: 40px; + background-color: #f5f5f5; +} + +.form-plant { + width: 100%; + max-width: 330px; + padding: 15px; + margin-top: 50px; + margin-left: auto; + margin-right: auto; + border: solid 1px; + border-radius: 10px; + background-color: #64c982; + border-color: #64c982; +} + +.form-plant .checkbox { + font-weight: 400; +} + +.form-plant .form-floating:focus-within { + z-index: 2; +} + +.form-plant input[type="email"] { + margin-bottom: 10px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} + +.form-plant input[type="color"] { + border: none; + margin-bottom: 10px; + margin-top: -70px; + margin-left: 100px; + border-radius: 50%; + width: 100px; + height: 100px; +} + +.form-plant input[type="color"]::-webkit-color-swatch { + border: none; + margin-top: -15px; + border-radius: 80%; + width: 80px; + height: 80px; +} + +.form-plant input[type="text"] { + margin-bottom: 10px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} + +.form-plant input[type="date"] { + margin-bottom: 10px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} + +.form-plant input[type="password"] { + margin-bottom: 10px; + border-top-left-radius: 0; + border-top-right-radius: 0; +} + +.btn-outline-success { + margin-top: 10px; + background-color: #ffff; + color: #64c982 !important; + border-color: #64c982 !important; +} diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.ts b/src/app/modules/admin/components/formulaire/formulaire.component.ts index d3730f6..5457afe 100644 --- a/src/app/modules/admin/components/formulaire/formulaire.component.ts +++ b/src/app/modules/admin/components/formulaire/formulaire.component.ts @@ -1,5 +1,7 @@ -import { Component, OnInit } from '@angular/core'; -import { FormGroup } from '@angular/forms'; +import { Component, Input, OnInit } from '@angular/core'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { Plant } from '../../models/plant'; +import { AdminService } from '../../services/admin.service'; @Component({ selector: 'app-formulaire', @@ -8,10 +10,26 @@ import { FormGroup } from '@angular/forms'; }) export class FormulaireComponent implements OnInit { plantForm!: FormGroup; - constructor() {} + @Input() buttonLabel!: string; + @Input() plantInfos: any; + @Input() isAdd : boolean = true; - ngOnInit(): void {} + constructor(private formBuilder: FormBuilder) {} - onSubmit(){} + ngOnInit(): void { + this.plantForm = this.formBuilder.group( + { + nameFc: new FormControl(this.plantInfos.product_name, [Validators.required]), + priceFc: new FormControl(this.plantInfos.product_price, [Validators.required]), + quantityFc: new FormControl(this.plantInfos.product_quantity, [Validators.required]), + inStockFc: new FormControl(this.plantInfos.product_instock, [Validators.required]), + categoryFc: new FormControl(this.plantInfos.product_breadcrumb_label, [Validators.required]), + ratingFc: new FormControl(this.plantInfos.product_rating, [Validators.required]), + }); + } + + addPlant(){} + + updatePlant(){} } diff --git a/src/app/modules/admin/models/plant.ts b/src/app/modules/admin/models/plant.ts index e334571..5de6238 100644 --- a/src/app/modules/admin/models/plant.ts +++ b/src/app/modules/admin/models/plant.ts @@ -5,7 +5,7 @@ export class Plant { public name: string='', public price: number =1, public quantity: number= 0, - public instock: boolean= true, + public instock: string[]=['disponible', 'patriellement disponible', 'non disponible'], public category:Category, public urlPicture: string = "https//picsum.photos/id/18/200/300", public rating: number = 0, 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 1c0ec6f..de5769d 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 +1,2 @@ -

page-modifier works!

+

Modifier la plante

+ diff --git a/src/app/modules/admin/pages/page-modifier/page-modifier.component.scss b/src/app/modules/admin/pages/page-modifier/page-modifier.component.scss index e69de29..8a0fa8b 100644 --- a/src/app/modules/admin/pages/page-modifier/page-modifier.component.scss +++ b/src/app/modules/admin/pages/page-modifier/page-modifier.component.scss @@ -0,0 +1,5 @@ +h1{ + color: rgba(0, 0, 0, 0.658); + font-size: 28px; + margin-top: 20px; +} 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 70691bc..23a6585 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,4 +1,8 @@ import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Plant } from '../../models/plant'; +import { AdminService } from '../../services/admin.service'; @Component({ selector: 'app-page-modifier', @@ -6,10 +10,72 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./page-modifier.component.scss'] }) export class PageModifierComponent implements OnInit { + plantForm: FormGroup; + updatePlantForm: FormGroup; + plantInfos: any; + plantId: any; - constructor() { } + + + constructor(private adminService: AdminService, + 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'); + + /** 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 : ['']], + }); + } + + + /** 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"; + + 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']); + }); } } diff --git a/src/app/modules/admin/pages/page-tableau/page-tableau.component.html b/src/app/modules/admin/pages/page-tableau/page-tableau.component.html index 1799f8b..f3617e7 100644 --- a/src/app/modules/admin/pages/page-tableau/page-tableau.component.html +++ b/src/app/modules/admin/pages/page-tableau/page-tableau.component.html @@ -20,9 +20,9 @@ {{products.price}} {{products.quantity}} {{products.instock}} - + {{products.category}} {{products.rating}} - + diff --git a/src/app/modules/admin/services/admin.service.ts b/src/app/modules/admin/services/admin.service.ts index c4d1aa5..5e70439 100644 --- a/src/app/modules/admin/services/admin.service.ts +++ b/src/app/modules/admin/services/admin.service.ts @@ -45,4 +45,13 @@ export class AdminService { // getData(): Observable { // return this.httpClient.get(`${this.apiUrl}/list_products`); // } + + /** Récupérer une plante par son Id **/ + getPlantById(id: any): Observable { + return this.httpClient.get(`${this.apiUrl}/list_products/${id}`); + } + /** Modifier Plante **/ + updatePlant(plant: Plant): Observable { + return this.httpClient.put(`${this.apiUrl}/list_products/${plant.id}`, plant); + } } From 03a825ec76766bcfa0984de822d2e517ec22bc69 Mon Sep 17 00:00:00 2001 From: Sana EL HIRI Date: Tue, 22 Mar 2022 09:42:03 +0100 Subject: [PATCH 2/3] inStock --- src/app/modules/admin/models/plant.ts | 2 +- .../admin/pages/page-modifier/page-modifier.component.ts | 4 ++-- .../admin/pages/page-tableau/page-tableau.component.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/modules/admin/models/plant.ts b/src/app/modules/admin/models/plant.ts index 5de6238..ba4acd6 100644 --- a/src/app/modules/admin/models/plant.ts +++ b/src/app/modules/admin/models/plant.ts @@ -5,7 +5,7 @@ export class Plant { public name: string='', public price: number =1, public quantity: number= 0, - public instock: string[]=['disponible', 'patriellement disponible', 'non disponible'], + public inStock: string[]=['disponible', 'patriellement disponible', 'non disponible'], public category:Category, public urlPicture: string = "https//picsum.photos/id/18/200/300", public rating: number = 0, 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 23a6585..0f439fb 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 @@ -48,7 +48,7 @@ export class PageModifierComponent implements OnInit { quantity: [plant ? plant.quantity : ''], category: [plant ? plant.category : ''], rating: [plant ? plant.rating : ''], - inStock: [plant ? plant.instock : ['']], + inStock: [plant ? plant.inStock : ['']], }); } @@ -70,7 +70,7 @@ export class PageModifierComponent implements OnInit { quantity: quantityValue, rating: ratingValue, category: categoryValue, - instock: [inStockValue], + inStock: [inStockValue], urlPicture }; this.adminService.updatePlant(plant)?.subscribe((resp) => { diff --git a/src/app/modules/admin/pages/page-tableau/page-tableau.component.html b/src/app/modules/admin/pages/page-tableau/page-tableau.component.html index f3617e7..3509686 100644 --- a/src/app/modules/admin/pages/page-tableau/page-tableau.component.html +++ b/src/app/modules/admin/pages/page-tableau/page-tableau.component.html @@ -19,7 +19,7 @@ {{products.name}} {{products.price}} {{products.quantity}} - {{products.instock}} + {{products.inStock}} {{products.category}} {{products.rating}} From 19d48cc995fa5c577ad61308c3a292890bc6199b Mon Sep 17 00:00:00 2001 From: Vincent Ramiere Date: Tue, 22 Mar 2022 09:44:39 +0100 Subject: [PATCH 3/3] modif inStock --- src/app/modules/admin/models/plant.ts | 2 +- .../admin/pages/page-tableau/page-tableau.component.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/modules/admin/models/plant.ts b/src/app/modules/admin/models/plant.ts index e334571..04890b5 100644 --- a/src/app/modules/admin/models/plant.ts +++ b/src/app/modules/admin/models/plant.ts @@ -5,7 +5,7 @@ export class Plant { public name: string='', public price: number =1, public quantity: number= 0, - public instock: boolean= true, + public inStock: boolean= true, public category:Category, public urlPicture: string = "https//picsum.photos/id/18/200/300", public rating: number = 0, diff --git a/src/app/modules/admin/pages/page-tableau/page-tableau.component.html b/src/app/modules/admin/pages/page-tableau/page-tableau.component.html index 1799f8b..5cdaa12 100644 --- a/src/app/modules/admin/pages/page-tableau/page-tableau.component.html +++ b/src/app/modules/admin/pages/page-tableau/page-tableau.component.html @@ -19,7 +19,7 @@ {{products.name}} {{products.price}} {{products.quantity}} - {{products.instock}} + {{products.inStock}} {{products.rating}}