|
|
@ -6,11 +6,13 @@ import { RecipeService } from '../recipe.service';
|
|
|
|
import { MatInputModule } from '@angular/material/input';
|
|
|
|
import { MatInputModule } from '@angular/material/input';
|
|
|
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
|
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
|
|
import { MatButton } from '@angular/material/button';
|
|
|
|
import { MatButton } from '@angular/material/button';
|
|
|
|
|
|
|
|
import { MatOption } from '@angular/material/core';
|
|
|
|
|
|
|
|
import { MatSelect } from '@angular/material/select';
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'app-recipe-add',
|
|
|
|
selector: 'app-recipe-add',
|
|
|
|
standalone: true,
|
|
|
|
standalone: true,
|
|
|
|
imports: [ReactiveFormsModule, FormsModule, MatFormFieldModule, MatInputModule, MatButton, MatFormFieldModule],
|
|
|
|
imports: [ReactiveFormsModule, FormsModule, MatFormFieldModule, MatOption, MatSelect, MatInputModule, MatButton, MatFormFieldModule],
|
|
|
|
templateUrl: './recipe-add.component.html',
|
|
|
|
templateUrl: './recipe-add.component.html',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class RecipeAddComponent {
|
|
|
|
export class RecipeAddComponent {
|
|
|
@ -25,6 +27,9 @@ export class RecipeAddComponent {
|
|
|
|
ingredients: Ingredient[] = [];
|
|
|
|
ingredients: Ingredient[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
selectedFilename: string = '';
|
|
|
|
selectedFilename: string = '';
|
|
|
|
|
|
|
|
getIngredient(n: number): Ingredient {
|
|
|
|
|
|
|
|
return this.ingredients.find(v => v.id === n)!
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#recipeId: number = -1;
|
|
|
|
#recipeId: number = -1;
|
|
|
|
@Input()
|
|
|
|
@Input()
|
|
|
@ -47,7 +52,6 @@ export class RecipeAddComponent {
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private formBuilder: FormBuilder, private recipes: RecipeService, private router: Router) {
|
|
|
|
constructor(private formBuilder: FormBuilder, private recipes: RecipeService, private router: Router) {
|
|
|
|
this.ingredients = this.recipes.getAllIngredients();
|
|
|
|
this.ingredients = this.recipes.getAllIngredients();
|
|
|
|
console.log(this.ingredients);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onSubmit(): void {
|
|
|
|
onSubmit(): void {
|
|
|
@ -71,13 +75,19 @@ export class RecipeAddComponent {
|
|
|
|
|
|
|
|
|
|
|
|
onAddIngredient(): void {
|
|
|
|
onAddIngredient(): void {
|
|
|
|
const value = this.createForm.value;
|
|
|
|
const value = this.createForm.value;
|
|
|
|
|
|
|
|
console.log(value);
|
|
|
|
|
|
|
|
|
|
|
|
if (!value.selectedIngredient) {
|
|
|
|
if (!value.selectedIngredient) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const id = parseInt(value.selectedIngredient!);
|
|
|
|
const id = parseInt(value.selectedIngredient!);
|
|
|
|
if (this.ingredientEntries.find((ingredient) => ingredient.idIngredient === id)) {
|
|
|
|
if (this.ingredientEntries.find((ingredient) => ingredient.idIngredient === id)) {
|
|
|
|
|
|
|
|
console.log("oh");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("ah");
|
|
|
|
|
|
|
|
console.log(this.ingredients.find(v => v.id === id)?.name)
|
|
|
|
|
|
|
|
console.log(this.ingredients);
|
|
|
|
this.ingredientEntries.push({
|
|
|
|
this.ingredientEntries.push({
|
|
|
|
idIngredient: id,
|
|
|
|
idIngredient: id,
|
|
|
|
idRecipe: -1,
|
|
|
|
idRecipe: -1,
|
|
|
|