From 994f8ee685d9db04d575ceabee869b9e948684c2 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Fri, 6 Dec 2019 15:17:32 -0500 Subject: Add convert form data to Recipe Object --- .../src/app/add-recipe/add-recipe.component.ts | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'recipeBuddy') diff --git a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts index b0e5ce5..eaa45d2 100644 --- a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts +++ b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts @@ -5,6 +5,12 @@ import { FormControl } from '@angular/forms'; import { FormBuilder } from '@angular/forms'; import { FormArray } from '@angular/forms'; +import { Recipe } from '../DataModels/recipe'; +import { Ingredient } from '../DataModels/ingredient' +import { Step } from '../DataModels/step'; +import { BackendService } from '../REST_service/backend.service'; + + @Component({ selector: 'app-add-recipe', templateUrl: './add-recipe.component.html', @@ -34,7 +40,9 @@ export class AddRecipeComponent { tags: [''], photos: [''] }); - constructor(private fb: FormBuilder) { } + constructor(private fb: FormBuilder, + private restService: BackendService + ) { } ngOnInit() { } @@ -65,4 +73,40 @@ export class AddRecipeComponent { }) ); } + + onSubmit() { + console.log('In Submit') + var formData = this.recipeForm.value; + + var ingredients = [] + var i; + for (i = 0; i < formData.ingredients.length; i++) { + ingredients.push(new Ingredient(formData.ingredients[0].ingrName, + formData.ingredients[0].amount, + formData.ingredients[0].unit, + "" + )); + } + + var steps = [] + for (i = 0; i < formData.ingredients.length; i++) { + steps.push(new Step(formData.steps[0].instruct, + formData.steps[0].timer + )); + } + + var recipe = new Recipe (0, //id + formData.recipeName, //name + formData.desc, //description + ingredients, //ingredients + steps, //steps + formData.servingSize, //servingSize + formData.cookTime, //cookTime + 0, //timesCooked + 0, //rating + formData.tags, //tags + formData.photos //photos + ); + console.log(JSON.stringify(recipe)) + } } -- cgit v1.1