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": 8
},
{
"id": 2,
"name": "Coke",
"cost": 0.5,
"remaining": 10
"remaining": 8
},
{
"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>
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:'USD':true): myMassage }}</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 @@ -11,6 +11,8 @@ export class InsertCoinComponent implements OnInit {
coinBalance = 0;
constructor(public balanceService: BalanceService) { }

myMassage = "Insert Coin"

ngOnInit() {
this.balanceService.onBalanceUpdated((balance) => {
this.coinBalance = balance;
Expand All @@ -20,5 +22,9 @@ export class InsertCoinComponent implements OnInit {
addBalance(amount) {
this.balanceService.addBalance(amount);
}
returnCoins() {
this.balanceService.setBalance(0);
alert('Coins returned')
}

}
Empty file.
14 changes: 14 additions & 0 deletions src/app/select-item/select-item.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<li *ngFor='let item of items'>
<!-- <input type="radio" [value]='item.id' name='items-list' (change)='onItemSelected(item)'> -->
{{item.name}}
<!-- <h2><i>{{item.cost}}</i></h2> -->
<!-- <button type="button" (click)='onItemSelected(item)'>{{item.name}}</button> -->
<!-- <button type="button" (click)='onItemPrice(item)'>{{item.name}}</button> -->
<!-- <input type="button" (click)='onChangeItem(item) [value]=""> -->
<button type="button" (click)='onChangeItem(item)'>Dispense</button>
</li>


<!-- <p>{{title}}</p>
<input [(ngModel)]="title" type="text"> -->
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();
});
});
35 changes: 35 additions & 0 deletions src/app/select-item/select-item.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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) { }

ngOnInit() {
this.itemService.onItemsRetrieved((items)=>{
this.items = items;
})
}
onItemSelected(item){
this.itemService.setSelectedItem(item)
}

onChangeItem(item){
this.itemService.setSelectedItem(item)
if(this.itemService.hasSufficientBalance(this.balanceService.getBalance())){
console.log("fatih")
this.itemService.dispenseItem(console.log("yeah"))
this.balanceService.deductBalance(this.itemService.getSelectedItem().cost);
}
else{
let item = '.display -sm-width';
console.log("item")
}
}
}
2 changes: 0 additions & 2 deletions src/styles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* You can add global styles to this file, and also import other style files */

body { background-color: #B33323; }

h1 { color: #FFF; font-family: 'Helvetica Neue', sans-serif; font-size: 75px; font-weight: bold; letter-spacing: -1px; line-height: 1; }
h2 { color: #FFF; font-family: 'Open Sans', sans-serif; font-size: 30px; font-weight: 300; line-height: 32px; margin: 0 0 72px; }

Expand Down