diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.html b/src/app/modules/admin/components/formulaire/formulaire.component.html
index 45bc618..5d65f00 100644
--- a/src/app/modules/admin/components/formulaire/formulaire.component.html
+++ b/src/app/modules/admin/components/formulaire/formulaire.component.html
@@ -1,108 +1,104 @@
+
diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.ts b/src/app/modules/admin/components/formulaire/formulaire.component.ts
index 5457afe..9bce5b6 100644
--- a/src/app/modules/admin/components/formulaire/formulaire.component.ts
+++ b/src/app/modules/admin/components/formulaire/formulaire.component.ts
@@ -10,24 +10,26 @@ import { AdminService } from '../../services/admin.service';
})
export class FormulaireComponent implements OnInit {
plantForm!: FormGroup;
- @Input() buttonLabel!: string;
- @Input() plantInfos: any;
- @Input() isAdd : boolean = true;
- constructor(private formBuilder: FormBuilder) {}
+ @Input() plantInfos!: Plant;
+ @Input()buttonLabel!:String;
+ constructor(private fb : FormBuilder, private adminService: AdminService) {
+
+ }
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]),
- });
+ this.plantForm = this.fb.group({
+ nameFc: new FormControl(this.plantInfos.name, [Validators.required]),
+ priceFc: new FormControl(this.plantInfos.price, [Validators.required]),
+ quantityFc: new FormControl(this.plantInfos.quantity, [Validators.required]),
+ inStockFc: new FormControl(this.plantInfos.inStock, [Validators.required]),
+ categoryFc: new FormControl(this.plantInfos.category, [Validators.required]),
+ ratingFc: new FormControl(this.plantInfos.rating, [Validators.required]),
+ });
}
+
+
addPlant(){}
updatePlant(){}
diff --git a/src/app/modules/admin/models/plant.ts b/src/app/modules/admin/models/plant.ts
index ba4acd6..b6d2bf4 100644
--- a/src/app/modules/admin/models/plant.ts
+++ b/src/app/modules/admin/models/plant.ts
@@ -5,8 +5,8 @@ export class Plant {
public name: string='',
public price: number =1,
public quantity: number= 0,
- public inStock: string[]=['disponible', 'patriellement disponible', 'non disponible'],
- public category:Category,
+ public inStock: string[]=['disponible','partiellement disponible', 'non disponible'],
+ public category:string[]=['plantes fleuries','orchides','cactus et plantes grasses','bonsas','plantes vertes','palmier dintrieur'],
public urlPicture: string = "https//picsum.photos/id/18/200/300",
public rating: number = 0,
public id?: number
diff --git a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html
index a60afc4..15502b2 100644
--- a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html
+++ b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html
@@ -1 +1,2 @@
-page-ajouter works!
+Ajouter une plante
+
diff --git a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.scss b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.scss
index e69de29..8a0fa8b 100644
--- a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.scss
+++ b/src/app/modules/admin/pages/page-ajouter/page-ajouter.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-ajouter/page-ajouter.component.ts b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.ts
index c6a0844..bda58f2 100644
--- a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.ts
+++ b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.ts
@@ -1,15 +1,61 @@
import { Component, OnInit } from '@angular/core';
+import {
+ FormBuilder,
+ FormControl,
+ FormGroup,
+ Validators,
+} from '@angular/forms';
+import { Router } from '@angular/router';
+import { FormulaireComponent } from '../../components/formulaire/formulaire.component';
+import { Plant } from '../../models/plant';
+import { AdminService } from '../../services/admin.service';
+
+
+
@Component({
selector: 'app-page-ajouter',
templateUrl: './page-ajouter.component.html',
- styleUrls: ['./page-ajouter.component.scss']
+ styleUrls: ['./page-ajouter.component.scss'],
})
export class PageAjouterComponent implements OnInit {
+ public plantForm: FormGroup;
+ public isAdd: boolean = false;
- constructor() { }
- ngOnInit(): void {
+ constructor(private fb: FormBuilder, private router: Router, private adminService: AdminService) {
+ this.plantForm = new FormGroup({});
+ this.isAdd = false;
}
+ ngOnInit(): void {
+
+ }
+
+ public onSubmit(): void {
+ const nameValue = this.plantForm.value['nameFC'];
+ const priceValue = this.plantForm.value['priceFc'];
+ const quantityValue = this.plantForm.value['quantityFc'];
+ const inStockValue = this.plantForm.value['inStockFC'];
+ const categoryValue = this.plantForm.value['categotyFC'];
+ const urlPicture: string = 'https//picsum.photos/id/18/200/300';
+ const ratingValue = this.plantForm.value['ratingFc'];
+ const idValue = this.plantForm.value[''];
+
+ const plant : Plant = {
+ name: nameValue,
+ price: priceValue,
+ quantity: quantityValue,
+ inStock: [inStockValue],
+ category: [categoryValue],
+ urlPicture: 'https//picsum.photos/id/18/200/300',
+ rating: ratingValue,
+ id: idValue,
+ };
+ console.log("coco",plant);
+
+ this.adminService.addPlant(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 3509686..c32cab0 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
@@ -27,3 +27,4 @@
+
diff --git a/src/app/modules/admin/services/admin.service.ts b/src/app/modules/admin/services/admin.service.ts
index 5e70439..aa94aa9 100644
--- a/src/app/modules/admin/services/admin.service.ts
+++ b/src/app/modules/admin/services/admin.service.ts
@@ -5,7 +5,7 @@ import { environment } from 'src/environments/environment';
import { Plant } from '../models/plant';
@Injectable({
- providedIn: 'root'
+ providedIn: 'root',
})
export class AdminService {
public collection$!: Observable;
@@ -37,6 +37,9 @@ export class AdminService {
})
}
+ addPlant(plant: Plant): Observable | void {
+ return this.httpClient.post(`${this.apiUrl}`, plant);
+ }
onClickDelete(id: number): Observable {
return this.httpClient.delete(`${this.apiUrl}/list_products/${id}`).pipe(
tap(() => this.refreshCollection())