modifier ok
This commit is contained in:
parent
1b5b7f0e3e
commit
7d8e72e4ac
5 changed files with 129 additions and 120 deletions
|
|
@ -10,7 +10,7 @@ import { Plant } from '../../models/plant';
|
|||
export class FormulaireComponent implements OnInit {
|
||||
plantForm!: FormGroup;
|
||||
@Input()buttonLabel!:String;
|
||||
@Input() plantInfos!: Plant;
|
||||
@Input() plantInfos!: any;
|
||||
@Output() submitted = new EventEmitter();
|
||||
|
||||
constructor(private fb : FormBuilder) {
|
||||
|
|
@ -19,12 +19,12 @@ export class FormulaireComponent implements OnInit {
|
|||
ngOnInit(): void {
|
||||
console.log(this.plantInfos);
|
||||
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]),
|
||||
nameFc: new FormControl(this.plantInfos.product_name, [Validators.required]),
|
||||
priceFc: new FormControl(this.plantInfos.product_price, [Validators.required]),
|
||||
quantityFc: new FormControl(this.plantInfos.product_qty, [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]),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ export class Plant {
|
|||
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
|
||||
public id?: string
|
||||
){}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ export class PageModifierComponent implements OnInit {
|
|||
const id = params.get('id')
|
||||
if( id != null){
|
||||
this.plantId = id;
|
||||
console.log(this.plantId);
|
||||
//console.log(this.plantId);
|
||||
|
||||
this.adminService
|
||||
.getPlantById(this.plantId)
|
||||
.subscribe((plantData: any) => {
|
||||
this.editPlant = plantData;
|
||||
console.log(this.editPlant);
|
||||
console.log(this.editPlant.name);
|
||||
//console.log(this.editPlant);
|
||||
//console.log(this.editPlant.name);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -44,29 +44,39 @@ export class PageModifierComponent implements OnInit {
|
|||
|
||||
|
||||
/** Méthode qui envoie les champs modifiés pour mise à jour **/
|
||||
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";
|
||||
public update(plant: any): void {
|
||||
//console.log(plant);
|
||||
const nameValue = plant.nameFc;
|
||||
const priceValue = plant.priceFc;
|
||||
const ratingValue = plant.ratingFc;
|
||||
const quantityValue = plant.quantityFc;
|
||||
const categoryValue = plant.categoryFc;
|
||||
const inStockValue = plant.inStockFc;
|
||||
|
||||
// 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 plante: any = {
|
||||
id: this.plantId,
|
||||
product_name: nameValue,
|
||||
product_price: priceValue,
|
||||
product_qty: quantityValue,
|
||||
product_rating: ratingValue,
|
||||
product_breadcrumb_label: categoryValue,
|
||||
product_instock: [inStockValue],
|
||||
product_url_picture : "https//picsum.photos/id/18/200/300",
|
||||
product_discount_code : "",
|
||||
product_color: "",
|
||||
product_unitprice_ati: "",
|
||||
product_unitprice_tf: "",
|
||||
product_discount_tf: "",
|
||||
product_discount_ati: "",
|
||||
product_url_page: "",
|
||||
product_shipping_method: null,
|
||||
product_image_source: "",
|
||||
product_seller: "market place",
|
||||
product_web_only: "non"
|
||||
};
|
||||
this.adminService.updatePlant(plante)?.subscribe((resp) => {
|
||||
this.router.navigate(['admin']);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export class AdminService {
|
|||
//console.log("avant mapping: ", tabObj);
|
||||
// Ici grâce à la méthode .map() on transforme tout les objet json du tableau en instance de notre classe Plant()
|
||||
return tabObj.map((obj: any) => {
|
||||
return new Plant(obj.product_name, obj.product_price,obj.product_quantity,obj.product_instock,obj.product_breadcrumb_label,obj.product_image_source,obj.product_rating,obj.id);
|
||||
return new Plant(obj.product_name, obj.product_price,obj.product_qty,obj.product_instock,obj.product_breadcrumb_label,obj.product_image_source,obj.product_rating,obj.id);
|
||||
})
|
||||
}));
|
||||
//this.collection$ = this.httpClient.get<Plant[]>(`${this.apiUrl}/list_products`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue