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
Empty file.
4 changes: 4 additions & 0 deletions src/app/dispense-item/dispense-item.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>
dispense-item works!
<button class="button" (click)='dispenseItem()'>Dispense Item</button>
</p>
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();
});
});
28 changes: 28 additions & 0 deletions src/app/dispense-item/dispense-item.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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.css']
})
export class DispenseItemComponent implements OnInit {

constructor(private itemService: ItemService, private balanceService: BalanceService) { }

ngOnInit() {
}
dispenseItem() {
const currentBalance = this.balanceService.getBalance();
if (this.itemService.hasSufficientBalance(currentBalance)) {
alert("insufficient balance");
}
else if (this.itemService.hasRemaining()) {
alert("none left");
}
else ( this.itemService.dispenseItem((item)=> {
(this.balanceService.deductBalance(item.cost))
// alert('enjoy your ', item);
})
};
Empty file.
4 changes: 4 additions & 0 deletions src/app/select-item/select-item.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<li *ngFor='let item of items'>
<input type='radio' [value]='item.id'
name='items-list' (change)='onItemSelected(item)'>{{item.name}}
</li>
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();
});
});
23 changes: 23 additions & 0 deletions src/app/select-item/select-item.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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']
})
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);
}

}