forked from IgniteUI/igniteui-angular-wrappers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
394 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { InMemoryDbService } from 'angular-in-memory-web-api'; | ||
export class ProductData implements InMemoryDbService { | ||
createDb() { | ||
let products = [ | ||
{ | ||
"ProductID": 1, | ||
"ProductName": "Chai", | ||
"DealerName": "A", | ||
"CategoryName": "Beverages", | ||
"ImageUrl": "../../images/samples/nw/categories/1.png", | ||
"InStock": 39, | ||
"Inventory": "" | ||
}, | ||
{ | ||
"ProductID": 2, | ||
"ProductName": "Chang", | ||
"DealerName": "B", | ||
"CategoryName": "Beverages", | ||
"ImageUrl": "../../images/samples/nw/categories/1.png", | ||
"InStock": 17, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 3, | ||
"ProductName": "Aniseed Syrup", | ||
"DealerName": "C", | ||
"CategoryName": "Condiments", | ||
"ImageUrl": "../../images/samples/nw/categories/2.png", | ||
"InStock": 13, | ||
"Inventory": "" | ||
}, | ||
{ | ||
"ProductID": 4, | ||
"ProductName": "Chef Anton\u0027s Cajun Seasoning", | ||
"DealerName": "D", | ||
"CategoryName": "Condiments", | ||
"ImageUrl": "../../images/samples/nw/categories/2.png", | ||
"InStock": 53, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 5, | ||
"ProductName": "Chef Anton\u0027s Gumbo Mix", | ||
"DealerName": "E", | ||
"CategoryName": "Condiments", | ||
"ImageUrl": "../../images/samples/nw/categories/2.png", | ||
"InStock": 0, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 6, | ||
"ProductName": "Grandma\u0027s Boysenberry Spread", | ||
"DealerName": "F", | ||
"CategoryName": "Condiments", | ||
"ImageUrl": "../../images/samples/nw/categories/2.png", | ||
"InStock": 120, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 7, | ||
"ProductName": "Uncle Bob\u0027s Organic Dried Pears", | ||
"DealerName": "G", | ||
"CategoryName": "Produce", | ||
"ImageUrl": "../../images/samples/nw/categories/7.png", | ||
"InStock": 15, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 8, | ||
"ProductName": "Northwoods Cranberry Sauce", | ||
"DealerName": "H", | ||
"CategoryName": "Condiments", | ||
"ImageUrl": "../../images/samples/nw/categories/2.png", | ||
"InStock": 6, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 9, | ||
"ProductName": "Mishi Kobe Niku", | ||
"DealerName": "I", | ||
"CategoryName": "Meat/Poultry", | ||
"ImageUrl": "../../images/samples/nw/categories/6.png", | ||
"InStock": 29, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 10, | ||
"ProductName": "Ikura", | ||
"DealerName": "J", | ||
"CategoryName": "Seafood", | ||
"ImageUrl": "../../images/samples/nw/categories/8.png", | ||
"InStock": 31, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 11, | ||
"ProductName": "Queso Cabrales", | ||
"DealerName": "K", | ||
"CategoryName": "Dairy Products", | ||
"ImageUrl": "../../images/samples/nw/categories/4.png", | ||
"InStock": 22, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 12, | ||
"ProductName": "Queso Manchego La Pastora", | ||
"DealerName": "J", | ||
"CategoryName": "Dairy Products", | ||
"ImageUrl": "../../images/samples/nw/categories/4.png", | ||
"InStock": 86, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 13, | ||
"ProductName": "Konbu", | ||
"DealerName": "K", | ||
"CategoryName": "Seafood", | ||
"ImageUrl": "../../images/samples/nw/categories/8.png", | ||
"InStock": 24, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 14, | ||
"ProductName": "Tofu", | ||
"DealerName": "L", | ||
"CategoryName": "Produce", | ||
"ImageUrl": "../../images/samples/nw/categories/7.png", | ||
"InStock": 35, | ||
"Inventory": "" | ||
}, | ||
{ | ||
|
||
"ProductID": 15, | ||
"ProductName": "Genen Shouyu", | ||
"DealerName": "M", | ||
"CategoryName": "Condiments", | ||
"ImageUrl": "../../images/samples/nw/categories/2.png", | ||
"InStock": 39, | ||
"Inventory": "" | ||
} | ||
]; | ||
return {products}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Component, Injectable, NgModule } from '@angular/core'; | ||
import { IgGridComponent } from "../../src/igniteui.angular2"; | ||
import { Http, Response, HttpModule } from '@angular/http'; | ||
import { Headers, RequestOptions } from '@angular/http'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import 'rxjs/add/operator/map'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { InMemoryWebApiModule } from 'angular-in-memory-web-api'; | ||
import { ProductData } from '../data/product-data'; | ||
|
||
declare var jQuery: any; | ||
|
||
|
||
@Injectable() | ||
export class ProductService { | ||
constructor(private http: Http) { } | ||
|
||
getAll() { | ||
let people$ = this.http | ||
.get("app/products").map((res: Response) => res.json()); | ||
return people$; | ||
} | ||
|
||
addProduct(ProductID, ProductName, DealerName, CategoryName, InStock): Observable<any> { | ||
let body = JSON.stringify({ ProductID, ProductName, DealerName, CategoryName, InStock }); | ||
let headers = new Headers({ 'Content-Type': 'application/json' }); | ||
let options = new RequestOptions({ headers: headers }); | ||
|
||
return this.http.post("app/products", body, options) | ||
.map(this.extractData); | ||
} | ||
|
||
|
||
private extractData(res: Response) { | ||
let body = res.json(); | ||
return body.data || { }; | ||
} | ||
|
||
private handleError (error: any) { | ||
let errMsg = (error.message) ? error.message : | ||
error.status ? `${error.status} - ${error.statusText}` : 'Server error'; | ||
console.error(errMsg); // log to console instead | ||
return Observable.throw(errMsg); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'my-app', | ||
templateUrl: "./igGrid-HTTPClientTemplate.html", | ||
providers: [ProductService] | ||
}) | ||
export class AppComponent { | ||
private gridOptions: IgGrid; | ||
private id: string; | ||
private products: any = []; | ||
errorMessage: string; | ||
private newId: number; | ||
|
||
constructor(private productService: ProductService) { | ||
this.productService.getAll().subscribe( | ||
res => { | ||
this.products = res.data; | ||
this.newId = this.products.length; | ||
}, | ||
error => this.errorMessage = <any>error | ||
); | ||
|
||
this.id = 'grid1'; | ||
|
||
this.gridOptions = { | ||
autoCommit: true, | ||
width: "100%", | ||
height: "400px", | ||
autoGenerateColumns: false, | ||
primaryKey: "ProductID", | ||
columns: [ | ||
{ key: "ProductID", headerText: "Product ID", width: "15%", dataType: "number" }, | ||
{ key: "ProductName", headerText: "Name", width: "35%", dataType: "string" }, | ||
{ key: "DealerName", headerText: "Dealer Name", width: "15%", dataType: "string" }, | ||
{ key: "CategoryName", headerText: "CategoryName", width: "25%", dataType: "string" }, | ||
{ key: "InStock", headerText: "InStock", width: "15%", dataType: "number" } | ||
], | ||
features: [ | ||
{ | ||
name: "Updating", | ||
editMode: "none", | ||
enableAddRow: false, | ||
enableDeleteRow: false | ||
} | ||
] | ||
} | ||
} | ||
|
||
addProduct(newProductName, newDealerName, newCategoryName, newInStock) { | ||
this.newId++; | ||
this.productService.addProduct(this.newId, newProductName, newDealerName, newCategoryName, newInStock) | ||
.subscribe( | ||
product => this.products.push(product), | ||
error => this.errorMessage = <any>error | ||
); | ||
} | ||
} | ||
|
||
@NgModule({ | ||
imports: [ BrowserModule, HttpModule, InMemoryWebApiModule.forRoot(ProductData) ], | ||
declarations: [ AppComponent, IgGridComponent ], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule {} | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule); |
Oops, something went wrong.