diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-12-12 11:59:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-12 11:59:29 -0500 |
commit | 7d8b3b712274613b20c299efc48e4041e3fc6d72 (patch) | |
tree | 585ffdf67ea07d78efaedbebf42da2e8a446e9cd /recipeBuddy/src/app/recipe-card/recipe-card.component.ts | |
parent | afd1a8106feca31ab644fbb412c87eca69bfd737 (diff) | |
parent | 47254348140fce18c985e9a0ffb592390b226c80 (diff) |
Merge pull request #28 from tuckerevans/elim
Elim
Diffstat (limited to 'recipeBuddy/src/app/recipe-card/recipe-card.component.ts')
-rw-r--r-- | recipeBuddy/src/app/recipe-card/recipe-card.component.ts | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/recipeBuddy/src/app/recipe-card/recipe-card.component.ts b/recipeBuddy/src/app/recipe-card/recipe-card.component.ts new file mode 100644 index 0000000..490f2ab --- /dev/null +++ b/recipeBuddy/src/app/recipe-card/recipe-card.component.ts @@ -0,0 +1,71 @@ +import {Component,OnInit} from '@angular/core'; +import{BackendService} from '../REST_service/backend.service'; +import{Recipe} from '../DataModels/recipe'; +import {RecipePassService} from '../recipePass/recipe-pass.service'; +//import { Observable } from "rxjs/Rx"; + + +/** + * @title Card with multiple sections + */ +@Component({ + selector: 'RecipeCardComponent', + templateUrl: 'recipe-card.component.html', + styleUrls: ['recipe-card.component.css'] +}) +export class RecipeCardComponent implements OnInit { + + constructor(private restService: BackendService, + private recipePass: RecipePassService) {} + + + recipes: Recipe[] = []; //array of recipe objects + recipe: Recipe = new Recipe(0,"","",[],[],0,0,0,0,[],[]); + + ngOnInit() { + this.restService.getRecipes().subscribe( + res => { + var i: number; + for(i = 0; i < res.length; i++) { + this.restService.getRecipe(res[i]).subscribe( + res2 => { + this.recipes = [...this.recipes, res2] + console.log(res2.photos) + }, err => {/*Deal with error*/}, () => {/*Code for complete observable*/} + + ); + } + }, + err => { +//Deal with error + }, + () => { +//Complete observable + } +); + } + + + cookPage(thisrecipe){ + /**Code here to go to cook page for recipe with id */ + this.recipePass.setRecipe(thisrecipe); + } + + edit(thisrecipe) { + /**Code here to edit recipe with id */ + this.recipePass.setRecipe(thisrecipe); + } + + delete(id) { + /**Code here to delete recipe with id */ + this.restService.getRecipe(id).subscribe(res => this.recipe = res) + var txt = confirm("Are you sure you want to delete " + this.recipe.name + "?"); + if(txt == true) + { + alert(this.recipe.name + " was deleted."); + this.restService.deleteRecipe(id).subscribe(); + } + window.location.reload(); +} + +} |