diff options
Diffstat (limited to 'recipeBuddy/src/app/recipe-card')
4 files changed, 173 insertions, 0 deletions
diff --git a/recipeBuddy/src/app/recipe-card/recipe-card.component.css b/recipeBuddy/src/app/recipe-card/recipe-card.component.css new file mode 100644 index 0000000..b29ad9a --- /dev/null +++ b/recipeBuddy/src/app/recipe-card/recipe-card.component.css @@ -0,0 +1,28 @@ +.example-viewport { + height: 1000px; + width: 100%; + display: flex; + margin-left: auto; + margin-right: auto; +} +button{ + float: left; + padding: 10px; +} +.example-card { + float: left; + width: 100%; + margin: 10px; +} +.example-card:hover { + border: solid; +} +#card-title { + font-weight: bold; + cursor: pointer; +} +#cardContainer { + width: 35%; + padding: 5%; + float: left; +} diff --git a/recipeBuddy/src/app/recipe-card/recipe-card.component.html b/recipeBuddy/src/app/recipe-card/recipe-card.component.html new file mode 100644 index 0000000..eaba29a --- /dev/null +++ b/recipeBuddy/src/app/recipe-card/recipe-card.component.html @@ -0,0 +1,49 @@ +<cdk-virtual-scroll-viewport [itemSize]="1" class="example-viewport"> +<div *cdkVirtualFor="let recipe of recipes" class="example-test"> +<div id="cardContainer"> + <mat-card class="example-card"> + <mat-card-header> + <div id="card-title"> + <button mat-button routerLink="/preCook" routerLinkActive="active" + (click)="cookPage(recipe)"> + <mat-card-title>{{recipe.name}}</mat-card-title> + </button> + </div> + </mat-card-header> + <mat-card-actions matSuffix> + <div id="edit"> + <button mat-button (click)="edit(recipe)" routerLink="/" + routerLinkActive="active"> + <mat-icon>edit</mat-icon> + </button> + </div> + <div id="cart"> + <button mat-button routerLink="/cart" routerLinkActive="active"> + <mat-icon>shopping_cart</mat-icon> + </button> + </div> + <div id="delete"> + <button mat-button (click)="delete(recipe.id)"> + <mat-icon>delete</mat-icon> + </button> + </div> + </mat-card-actions> + + <div *ngIf="recipe.photos.length > 0; else elseBlock" id="imgContainer"> + <img mat-card-image style="margin-top: 20px; height: 300px" src={{recipe.photos[0]}} +alt="Photo of recipe"> + </div> + <ng-template #elseBlock> + <img mat-card-image style="margin-top: 20px" + src="https://seeklogo.net/wp-content/themes/seeklogo-2017/images/not-available.jpg" + alt="No image available" + height="300px"> + </ng-template> + <div id="ratingContainer"> + <p>Rating: {{recipe.rating}}</p> + </div> + </mat-card> + </div> + </div> +</cdk-virtual-scroll-viewport> + diff --git a/recipeBuddy/src/app/recipe-card/recipe-card.component.spec.ts b/recipeBuddy/src/app/recipe-card/recipe-card.component.spec.ts new file mode 100644 index 0000000..ea6f5b7 --- /dev/null +++ b/recipeBuddy/src/app/recipe-card/recipe-card.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RecipeCardComponent } from './recipe-card.component'; + +describe('RecipeCardComponent', () => { + let component: RecipeCardComponent; + let fixture: ComponentFixture<RecipeCardComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ RecipeCardComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(RecipeCardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); 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(); +} + +} |