-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
191 lines (161 loc) · 4.01 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import {Component, EventEmitter } from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
/**
* Navigation component goes here
*/
@Component({
selector: "nav",
template: `<div>Navigation goes here</div>`
})
export class Navigation {
constructor(){}
}
/**
* Breadcrump component goes here
*/
@Component({
selector: "breadcrump",
template: `<div>Breadcrump goes here</div>`
})
export class Breadcrump {
constructor(){}
}
/**
* Product Model
*/
export class Product {
constructor(
public sku: string,
public name: string,
public imageUrl: string,
public departments: string[],
public price: number
){}
}
@Component({
selector: 'price-display',
inputs: ['price'],
template:`
<div class="price-display">\${{ price }}</div>
`
})
export class PriceDisplay{
price: number;
}
@Component({
selector: 'product-img',
inputs:['product'],
host: {class: 'ui small image'},
template:`<img [src]="product.imageUrl" class="product-image"/>`
})
export class ProductImage{
product: Product;
constructor(){}
}
@Component({
selector: 'product-dept',
inputs:['product'],
template:`
<div class="product-department">
Product depatment appears here
</div>
`
})
export class ProductDepartment{
product: Product;
constructor(){}
}
/**
* Product Row component has three more components
*/
@Component({
selector: 'product-row',
directives: [ProductImage, ProductDepartment, PriceDisplay],
inputs: ['product'],
template: `
<product-img [product] = "product"></product-img>
<div class="content">
<div class="header">{{product.name}}</div>
<div class="meta">
<div class="product-sku">SKU# {{ product.sku }}</div>
</div>
<div class="description">
<product-dept [input] = "product"></product-dept>
</div>
<price-display [price] = "product.price"></price-display>
</div>
`
})
export class ProductRow {
product: Product;
constructor(){
}
}
/**
* Product List component goes here
*/
@Component({
selector: 'product-list',
directives: [ProductRow],
inputs: ['productList: productList'],
outputs: ['onProductSelected'],
template: `
<div class="ui items">
<product-row *ngFor="#p of productList"
[product] = 'p'
(click) = 'clicked(p)'>
</product-row>
</div>`
})
export class ProductList{
productList: Product[];
currentProduct: Product;
onProductSelected: EventEmitter <Product>;
constructor(){
this.onProductSelected = new EventEmitter();
}
clicked(product: Product): void {
this.currentProduct = product;
this.onProductSelected.emit(this.currentProduct);
}
}
/**
* App EntryPoint starts here
*/
@Component({
selector: 'inventory-app',
directives: [ProductList],
template: `
<div class="inventory-app">
<product-list
[productList] = "products"
[onProductSelected] = "onProductSelection($event)"
></product-list>
</div>
`
})
class InventoryApp {
products: Product[];
constructor() {
this.products = [
new Product('MYSHOES', 'Black Running Shoes',
'/resources/images/products/black-shoes.jpg',
['Men', 'Shoes', 'Running Shoes'],
109.99),
new Product(
'NEATOJACKET', 'Blue Jacket',
'/resources/images/products/blue-jacket.jpg',
['Women', 'Apparel', 'Jackets & Vests'],
238.99),
new Product(
'NICEHAT', 'A Nice Black Hat',
'/resources/images/products/black-hat.jpg',
['Men', 'Accessories', 'Hats'],
29.99)
];
}
onProductSelection (product: Product) : void{
console.log("Product selected : ", product);
}
}
bootstrap(InventoryApp);