diff options
8 files changed, 143 insertions, 6 deletions
diff --git a/recipeBuddy/src/app/add-recipe/add-recipe.component.html b/recipeBuddy/src/app/add-recipe/add-recipe.component.html index 76095f9..11277f9 100644 --- a/recipeBuddy/src/app/add-recipe/add-recipe.component.html +++ b/recipeBuddy/src/app/add-recipe/add-recipe.component.html @@ -59,7 +59,7 @@ </mat-form-field> <mat-form-field class="quarter-width"> <input matInput placeholder="Units" type="text" - formControlName="units"> + formControlName="unit"> </mat-form-field> <button matSuffix mat-mini-fab (click)="rmIngredient(i)" type="button" style="margin-left: 10px"> diff --git a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts index 5109c34..3c32ae7 100644 --- a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts +++ b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts @@ -29,7 +29,7 @@ export class AddRecipeComponent { this.fb.group({ ingrName: [''], amount: ['', Validators.pattern('^[0-9]*(\.[0-9]*)?$')], - units: [''] + unit: [''] }) ]), steps: this.fb.array([ @@ -61,7 +61,7 @@ export class AddRecipeComponent { this.fb.group({ ingrName: [''], amount: ['', Validators.pattern('^[0-9]*(\.[0-9]*)?$')], - units: [''] + unit: [''] }) ); } @@ -93,10 +93,10 @@ export class AddRecipeComponent { var ingredients = [] var i; for (i = 0; i < formData.ingredients.length; i++) { - var tmp_amount = parseFloat(formData.ingredients[0].amount) - ingredients.push(new Ingredient(formData.ingredients[0].ingrName, + var tmp_amount = parseFloat(formData.ingredients[i].amount) + ingredients.push(new Ingredient(formData.ingredients[i].ingrName, (isNaN(tmp_amount) ? 0 : tmp_amount), - formData.ingredients[0].unit, + formData.ingredients[i].unit, "" )); } diff --git a/recipeBuddy/src/app/app-routing.module.ts b/recipeBuddy/src/app/app-routing.module.ts index 0084f01..ae67546 100644 --- a/recipeBuddy/src/app/app-routing.module.ts +++ b/recipeBuddy/src/app/app-routing.module.ts @@ -5,6 +5,7 @@ import { CookPageComponent } from './cook-page/cook-page.component'; import { PreCookPopUpComponent } from './pre-cook-pop-up/pre-cook-pop-up.component'; import { AddRecipeComponent } from './add-recipe/add-recipe.component'; import { EditRecipeComponent } from './edit-recipe/edit-recipe.component'; +import { ShoppingCartComponent } from './shopping-cart/shopping-cart.component'; const routes: Routes = [ { path: '', redirectTo: '/cook', pathMatch: 'full' }, @@ -12,6 +13,7 @@ const routes: Routes = [ { path: 'add', component: AddRecipeComponent }, { path: 'cook', component: CookPageComponent }, { path: 'edit', component: EditRecipeComponent }, + { path: 'cart', component: ShoppingCartComponent } ]; @NgModule({ diff --git a/recipeBuddy/src/app/app.module.ts b/recipeBuddy/src/app/app.module.ts index a978053..76fbc66 100644 --- a/recipeBuddy/src/app/app.module.ts +++ b/recipeBuddy/src/app/app.module.ts @@ -6,6 +6,7 @@ import { MatDialogModule } from '@angular/material'; import { AppComponent } from './app.component'; import { CookPageComponent} from './cook-page/cook-page.component'; +import { ShoppingCartComponent } from './shopping-cart/shopping-cart.component'; import { AppRoutingModule } from './app-routing.module'; @@ -22,6 +23,8 @@ import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; import { MatToolbarModule } from '@angular/material/toolbar'; import { EditRecipeComponent } from './edit-recipe/edit-recipe.component'; +import { MatListModule } from '@angular/material/list'; +import { MatDividerModule } from '@angular/material/divider'; @NgModule({ declarations: [ @@ -30,6 +33,7 @@ import { EditRecipeComponent } from './edit-recipe/edit-recipe.component'; PreCookPopUpComponent, AddRecipeComponent, EditRecipeComponent, + ShoppingCartComponent ], imports: [ BrowserModule, @@ -43,6 +47,9 @@ import { EditRecipeComponent } from './edit-recipe/edit-recipe.component'; MatIconModule, MatButtonModule, MatToolbarModule, + MatDividerModule, + MatListModule, + FormsModule ], bootstrap: [AppComponent], }) diff --git a/recipeBuddy/src/app/shopping-cart/shopping-cart.component.css b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.css new file mode 100644 index 0000000..4c11ade --- /dev/null +++ b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.css @@ -0,0 +1,13 @@ +.column { + float: left; + width: 33.33%; + +} + + +.row:after { + content: ""; + display: table; + clear: both; + +}
\ No newline at end of file diff --git a/recipeBuddy/src/app/shopping-cart/shopping-cart.component.html b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.html new file mode 100644 index 0000000..a4e87ab --- /dev/null +++ b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.html @@ -0,0 +1,28 @@ +<div class="row"> + <div class="column"> + <h1> Recipes </h1> + <mat-selection-list #rlist> + <mat-list-option *ngFor="let recipe of recipes" [value]="recipe"> + {{recipe.name}} + </mat-list-option> + </mat-selection-list> + </div> + <div class="column"> + <h1> Ingredients </h1> + <div *ngFor="let selectedRecipe of rlist.selectedOptions.selected"> + <h3>{{selectedRecipe.value.name}}</h3> + <mat-selection-list #ilist> + <mat-list-option *ngFor="let ing of selectedRecipe.value.ingredients" [value]="ing" (click)="addIngredient(ing)"> + {{ing.name}} {{ing.amount}} {{ing.unit}} + </mat-list-option> + </mat-selection-list> + </div> + </div> + <div class="column"> + <h1> Shopping List </h1> + <mat-list #clist *ngFor="let cartItem of ingredients"> + <mat-list-item>{{cartItem.name}} {{cartItem.amount}} {{cartItem.unit}}</mat-list-item> + <mat-divider></mat-divider> + </mat-list> + </div> +</div>
\ No newline at end of file diff --git a/recipeBuddy/src/app/shopping-cart/shopping-cart.component.spec.ts b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.spec.ts new file mode 100644 index 0000000..5d77354 --- /dev/null +++ b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ShoppingCartComponent } from './shopping-cart.component'; + +describe('ShoppingCartComponent', () => { + let component: ShoppingCartComponent; + let fixture: ComponentFixture<ShoppingCartComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ShoppingCartComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ShoppingCartComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts new file mode 100644 index 0000000..26808ee --- /dev/null +++ b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts @@ -0,0 +1,62 @@ +import { Component, OnInit } from '@angular/core'; +import { MatSelectModule } from '@angular/material/select'; +import { MatDividerModule } from '@angular/material/divider'; +import { BackendService } from '../REST_service/backend.service'; +import { FormsModule } from '@angular/forms'; +import { Recipe } from '../DataModels/recipe'; +import { Ingredient } from '../DataModels/ingredient'; + + + + + +@Component({ + selector: 'shopping-cart.component', + templateUrl: './shopping-cart.component.html', + styleUrls: ['./shopping-cart.component.css'] +}) +export class ShoppingCartComponent implements OnInit { + + recipes: Recipe[] = []; + ingredients : Ingredient[] = []; + units: string[] = []; + amounts: number[] = []; + types: string[] = []; + rIDs: number[] = []; + + + + constructor( private restService: BackendService) { + + this.restService.getRecipes().subscribe( + res => { + var i: number; + for(i = 0; i < res.length; i++) { + this.restService.getRecipe(res[i]).subscribe( + res2 => { + this.recipes.push(res2) + }); + } + }); + + } + + + + ngOnInit() { + } + + addAll(): void { + + } + addRecipe(id: number): void { + + } + addIngredient(ing: Ingredient): void { + this.ingredients.push(ing); + + } + printList(): void { + + } +} |