-
{{ ingredient.$name }}
+
+
+
+
+
{{ ingredient.name }}
+
{{ ingredient.description }}
+
+
+
+
+
+
+
diff --git a/daidokoro/src/app/component/ingredients/ingredients.component.ts b/daidokoro/src/app/component/ingredients/ingredients.component.ts
index af71741..7610110 100644
--- a/daidokoro/src/app/component/ingredients/ingredients.component.ts
+++ b/daidokoro/src/app/component/ingredients/ingredients.component.ts
@@ -1,45 +1,62 @@
-import {Component, OnInit} from '@angular/core';
-import {IngredientService} from "../../service/ingredient.service";
-import {Ingredient} from "../../model/ingredient.model";
-import {NgFor} from "@angular/common";
-import {LoginService} from "../../service/login.service";
-import {Link} from "../../model/link.model";
-import {LinkService} from "../../service/link.service";
+import { Component, OnInit } from '@angular/core';
+import { IngredientService } from "../../service/ingredient.service";
+import { Ingredient } from "../../model/ingredient.model";
+import { NgFor, NgIf } from "@angular/common";
+import { FormsModule } from "@angular/forms";
+import { HttpClient } from "@angular/common/http";
@Component({
selector: 'app-ingredients',
standalone: true,
imports: [
NgFor,
+ NgIf,
+ FormsModule
],
+ providers: [IngredientService, HttpClient],
templateUrl: './ingredients.component.html',
styleUrl: './ingredients.component.css'
})
-export class IngredientsComponent implements OnInit{
+export class IngredientsComponent implements OnInit {
ingredients: Ingredient[] = [];
- links: Link[] = this.linkService.getLinks()
+ newIngredient: Ingredient = { id: '0', name: '', description: '' };
+ editIngredient: Ingredient | null = null;
- constructor(private ingredientService : IngredientService,private loginService: LoginService,private linkService : LinkService) {}
+ constructor(private ingredientService: IngredientService) {}
ngOnInit() {
+ this.loadIngredients();
+ }
+
+ loadIngredients() {
this.ingredientService.getAll().subscribe(ingredients => {
this.ingredients = ingredients;
});
}
- onClickLogin(event: Event): void {
- event.preventDefault(); // Prevent the default anchor behavior
- this.loginService.login();
+ addIngredient() {
+ this.ingredientService.add(this.newIngredient).subscribe(ingredient => {
+ this.ingredients.push(ingredient);
+ this.newIngredient = { id: '0', name: '', description: '' };
+ });
}
- onClickLogout(event: Event): void {
- event.preventDefault(); // Prevent the default anchor behavior
- this.loginService.logout();
+ edit(ingredient: Ingredient) {
+ this.editIngredient = { ...ingredient };
}
- isLogged(): boolean {
- return this.loginService.isLogged();
+ updateIngredient() {
+ if (this.editIngredient) {
+ this.ingredientService.update(this.editIngredient).subscribe(updatedIngredient => {
+ const index = this.ingredients.findIndex(i => i.id === updatedIngredient.id);
+ this.ingredients[index] = updatedIngredient;
+ this.editIngredient = null;
+ });
+ }
}
+ cancelEdit() {
+ this.editIngredient = null;
+ }
}
diff --git a/daidokoro/src/app/component/recipe-form/recipe-form.component.html b/daidokoro/src/app/component/recipe-form/recipe-form.component.html
index 5292f49..daed1fb 100644
--- a/daidokoro/src/app/component/recipe-form/recipe-form.component.html
+++ b/daidokoro/src/app/component/recipe-form/recipe-form.component.html
@@ -122,7 +122,7 @@
@@ -132,7 +132,7 @@
Complete the form to enable the button.
-
+
diff --git a/daidokoro/src/app/component/recipe-form/recipe-form.component.ts b/daidokoro/src/app/component/recipe-form/recipe-form.component.ts
index e2d7b77..0d101ef 100644
--- a/daidokoro/src/app/component/recipe-form/recipe-form.component.ts
+++ b/daidokoro/src/app/component/recipe-form/recipe-form.component.ts
@@ -83,14 +83,17 @@ export class RecipeFormComponent {
$ingredients: this.recipeForm.value.ingredients!.map((ingredient: any) => ({
quantity: ingredient.quantity,
unit: ingredient.unit,
- ingredient: this.ingredientsList.find(ing => ing.$name === ingredient.ingredient)
+ ingredient: this.ingredientsList.find(ing => ing.name === ingredient.ingredient)
})),
$image: this.recipeForm.value.image
};
this.formSubmitted.emit(recipe);
this.recipeForm.reset()
this.ingredients.clear()
+ this.imageBase64 = null;
this.addIngredient()
+ }else{
+ alert("Veuillez remplir tous les champs")
}
}
}
diff --git a/daidokoro/src/app/component/recipe-list/recipe-list.component.html b/daidokoro/src/app/component/recipe-list/recipe-list.component.html
index ee162c2..b37388b 100644
--- a/daidokoro/src/app/component/recipe-list/recipe-list.component.html
+++ b/daidokoro/src/app/component/recipe-list/recipe-list.component.html
@@ -90,7 +90,7 @@