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
2 changes: 1 addition & 1 deletion db.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"id": 2,
"name": "Coke",
"cost": 0.5,
"remaining": 10
"remaining": 0
},
{
"id": 3,
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ <h1>
{{title}}
</h1>
<app-insert-coin></app-insert-coin>
<app-select-item></app-select-item>
<app-dispense-item></app-dispense-item>
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import { Component } from '@angular/core';
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'ngCola';
title = 'Scotty-Cola';
}
6 changes: 5 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ 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';
import { DispenseItemComponent } from './dispense-item/dispense-item.component';

@NgModule({
declarations: [
AppComponent,
InsertCoinComponent
InsertCoinComponent,
SelectItemComponent,
DispenseItemComponent
],
imports: [
BrowserModule,
Expand Down
1 change: 1 addition & 0 deletions src/app/dispense-item/dispense-item.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button class="button -full-width" (click)="dispenseItem()">dispense</button>
Empty file.
25 changes: 25 additions & 0 deletions src/app/dispense-item/dispense-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 { DispenseItemComponent } from './dispense-item.component';

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

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

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
37 changes: 37 additions & 0 deletions src/app/dispense-item/dispense-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-dispense-item',
templateUrl: './dispense-item.component.html',
styleUrls: ['./dispense-item.component.scss'],
providers: []
})
export class DispenseItemComponent implements OnInit {
constructor(private itemService: ItemService, private balanceService: BalanceService) { }

ngOnInit() { }

dispenseItem() {
const currentBalance = this.balanceService.getBalance();
if(!this.hasSufficientBalance(currentBalance)) return;
if(!this.hasRemaining()) return;
this.itemService.dispenseItem((item) => {
alert('Enjoy your ' + item.name);
this.balanceService.deductBalance(item.cost);
});
}

hasSufficientBalance(currentBalance) {
const hasBalance = this.itemService.hasSufficientBalance(currentBalance);
if(!hasBalance) alert('Insufficient balance');
return hasBalance;
}

hasRemaining() {
const remaining = this.itemService.hasRemaining();
if(!remaining) alert('Stop kicking the machine...No remaining inventory for this item');
return remaining;
}
}
1 change: 1 addition & 0 deletions src/app/insert-coin/insert-coin.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
<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>
4 changes: 4 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,8 @@ export class InsertCoinComponent implements OnInit {
this.balanceService.addBalance(amount);
}

returnCoins(){
this.balanceService.setBalance(0);
alert('Coins returned!');
}
}
2 changes: 1 addition & 1 deletion src/app/item/item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ItemService {
.map((res:Response) => res.json());
}

dispenseItem(callback: any): void {
dispenseItem(callback: any): void {
this.selectedItem.remaining -= 1;
this.put(this.selectedItem).subscribe(callback);
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/select-item/select-item.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.select-item__selectable-item {
list-style: none;
padding: 12px 12px 12px 2px;
font-family: 'Helvetica Neue', sans-serif; font-size: 14px;
}

.select-item__selectable-item-list {
padding: 0;
}
18 changes: 18 additions & 0 deletions src/app/select-item/select-item.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<p>
Pick a Soda
</p>
<ul class="select-item__selectable-item-list">


<li *ngFor='let item of items'>
<button (click)='onItemSelected(item)'>{{item.name}}</button>



</li>

<p>{{title}}</p>
<input [(ngModel)]="title" type='text'>


</ul>
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();
});
});
25 changes: 25 additions & 0 deletions src/app/select-item/select-item.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component, OnInit } from '@angular/core';
import { ItemService } from '../item/item.service';


@Component({
selector: 'app-select-item',
templateUrl: './select-item.component.html',
styleUrls: ['./select-item.component.css'],
providers: []

})
export class SelectItemComponent implements OnInit {
public items;
constructor(public itemService: ItemService) { }

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

onItemSelected(item) {
this.itemService.setSelectedItem(item);
}
}
3 changes: 2 additions & 1 deletion src/styles.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* You can add global styles to this file, and also import other style files */

body { background-color: #B33323; }
body { background-color: #B33323;
background-image: url(http://i.imgur.com/PkoiW5k.pn)}

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