Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions db.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"id": 1,
"name": "Sprite",
"cost": 0.5,
"remaining": 10
"remaining": 4
},
{
"id": 2,
"name": "Coke",
"cost": 0.5,
"remaining": 10
"remaining": 7
},
{
"id": 3,
"name": "Dr. Pepper",
"cost": 0.75,
"remaining": 10
"remaining": 8
},
{
"id": 4,
Expand Down
1 change: 1 addition & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ <h1>
{{title}}
</h1>
<app-insert-coin></app-insert-coin>
<app-select-item></app-select-item>
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';


@Component({
selector: 'app-root',
templateUrl: './app.component.html',
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { InsertCoinComponent } from './insert-coin/insert-coin.component';

import { ItemService } from './item/item.service';
import { BalanceService } from './balance/balance.service';
import { SelectItemComponent } from './select-item/select-item.component';

@NgModule({
declarations: [
AppComponent,
InsertCoinComponent
InsertCoinComponent,
SelectItemComponent
],
imports: [
BrowserModule,
Expand Down
3 changes: 2 additions & 1 deletion src/app/insert-coin/insert-coin.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<p class="display -sm-width">{{ coinBalance? (coinBalance | currency:'USD':true): 'INSERT COIN' }}</p>
<p class="display -sm-width">{{ coinBalance? (coinBalance | currency:'EUR':true): 'INSERT COIN' }}</p>
<button class="button -yellow" (click)='addBalance(.05)'>05c</button>
<button class="button -blue" (click)='addBalance(.10)'>10c</button>
<button class="button -green" (click)='addBalance(.25)'>25c</button>
<button class="button" (click)='returnCoins()'>Return Coins</button>
6 changes: 6 additions & 0 deletions src/app/insert-coin/insert-coin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ export class InsertCoinComponent implements OnInit {
this.balanceService.addBalance(amount);
}

returnCoins() {
this.balanceService.setBalance(0);
alert('Coins Return!');
}


}
Empty file.
7 changes: 7 additions & 0 deletions src/app/select-item/select-item.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<li *ngFor='let item of items'>
<input type="radio" [value]="item.id"
(change)='onItemSelected(item)' name="item-list">
{{item.name}}
</li>

<button class="button" (click)='getDrink()'>Dispense</button>
25 changes: 25 additions & 0 deletions src/app/select-item/select-item.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { SelectItemComponent } from './select-item.component';

describe('SelectItemComponent', () => {
let component: SelectItemComponent;
let fixture: ComponentFixture<SelectItemComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SelectItemComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(SelectItemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
37 changes: 37 additions & 0 deletions src/app/select-item/select-item.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Component, OnInit } from '@angular/core';
import { ItemService } from '../item/item.service';
import { BalanceService } from '../balance/balance.service';


@Component({
selector: 'app-select-item',
templateUrl: './select-item.component.html',
styleUrls: ['./select-item.component.css']
})
export class SelectItemComponent implements OnInit {
public items;

constructor(public itemService: ItemService, public balanceService: BalanceService) { }
// constructor(public balanceService: BalanceService) { }
ngOnInit() {
this.itemService.onItemsRetrieved((items)=>{
this.items = items;
})
}

onItemSelected(item) {
this.itemService.setSelectedItem(item);
}

getDrink() {
if (this.itemService.hasSufficientBalance(this.balanceService.getBalance())){
this.itemService.dispenseItem(()=>{
alert("You got " + this.itemService.getSelectedItem().name);
this.balanceService.deductBalance(this.itemService.getSelectedItem().cost);
})
} else {
alert("Not Enough money");
}
}

}