diff --git a/daidokoro/src/app/component/recipe-detail/recipe-detail.component.html b/daidokoro/src/app/component/recipe-detail/recipe-detail.component.html index f411fb3..2d72b82 100644 --- a/daidokoro/src/app/component/recipe-detail/recipe-detail.component.html +++ b/daidokoro/src/app/component/recipe-detail/recipe-detail.component.html @@ -3,3 +3,5 @@

{{recipe?.$description}}

+Recette 1 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 83cc959..f6d6fd5 100644 --- a/daidokoro/src/app/component/recipe-form/recipe-form.component.html +++ b/daidokoro/src/app/component/recipe-form/recipe-form.component.html @@ -1,25 +1,32 @@
- + - + - + + + + + +
+ Selected Image +
- + - - 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 0ba7fc2..d542a76 100644 --- a/daidokoro/src/app/component/recipe-form/recipe-form.component.ts +++ b/daidokoro/src/app/component/recipe-form/recipe-form.component.ts @@ -4,11 +4,12 @@ import {FormControl, FormGroup, ReactiveFormsModule, FormArray, FormBuilder} fro import { Ingredient } from '../../model/ingredient.model'; import { Unity } from '../../model/unity'; import { IngredientService } from '../../service/ingredient.service'; -import {NgFor} from "@angular/common"; +import {NgFor, NgIf} from "@angular/common"; + @Component({ selector: 'app-recipe-form', standalone: true, - imports: [ReactiveFormsModule,NgFor], + imports: [ReactiveFormsModule, NgFor, NgIf], templateUrl: './recipe-form.component.html', styleUrl: './recipe-form.component.css' }) @@ -16,6 +17,7 @@ export class RecipeFormComponent { @Output() formSubmitted = new EventEmitter(); ingredientsList: Ingredient[] = []; unity = Object.values(Unity); + imageBase64: string | null = null; constructor(private formBuilder: FormBuilder, private ingredientService : IngredientService){} @@ -23,13 +25,15 @@ export class RecipeFormComponent { this.ingredientService.getAll().subscribe(ingredients => { this.ingredientsList = ingredients; }); + } recipeForm: FormGroup = this.formBuilder.group({ id: new FormControl('', { nonNullable: true }), name: new FormControl('', { nonNullable: true }), description: new FormControl('', { nonNullable: true }), - ingredients: this.formBuilder.array([]) + ingredients: this.formBuilder.array([this.newIngredient()]), + image: new FormControl('', {nonNullable: false}) }); get ingredients():FormArray{ @@ -48,7 +52,25 @@ export class RecipeFormComponent { this.ingredients.push(this.newIngredient()); } removeIngredient(index: number) { - this.ingredients.removeAt(index); + if (this.ingredients.length > 1) { + + this.ingredients.removeAt(index); + } else { + + } + } + + onFileChange(event: Event) { + const input = event.target as HTMLInputElement; + if (input.files && input.files[0]) { + const file = input.files[0]; + const reader = new FileReader(); + reader.onload = () => { + this.imageBase64 = reader.result as string; + this.recipeForm.patchValue({image: this.imageBase64}); + }; + reader.readAsDataURL(file); + } } onSubmit() { @@ -62,11 +84,13 @@ export class RecipeFormComponent { quantity: ingredient.quantity, unit: ingredient.unit, 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.addIngredient() } } 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 737a844..ee162c2 100644 --- a/daidokoro/src/app/component/recipe-list/recipe-list.component.html +++ b/daidokoro/src/app/component/recipe-list/recipe-list.component.html @@ -79,7 +79,8 @@
- Recette 1 + Recette 1

{{recipe.$name}}

{{recipe.$description}}

diff --git a/daidokoro/src/app/model/recipe.model.ts b/daidokoro/src/app/model/recipe.model.ts index a160f8f..b2632c0 100644 --- a/daidokoro/src/app/model/recipe.model.ts +++ b/daidokoro/src/app/model/recipe.model.ts @@ -5,5 +5,6 @@ export interface Recipe { $name : string, $description: string, $createdAt : Date, - $ingredients: QuantifiedIngredient[] + $ingredients: QuantifiedIngredient[], + $image?: string }