From: hackbard Date: Mon, 17 Oct 2016 20:28:20 +0000 (+0200) Subject: update views + reduced providers in main app X-Git-Url: https://hackdaworld.org/gitweb/?p=outofuni%2Ftavern2.git;a=commitdiff_plain;h=74001e08303ce797811fc91816a67c2006fe0a25 update views + reduced providers in main app --- diff --git a/lib/app_component.dart b/lib/app_component.dart index 2175bdf..814cfb9 100644 --- a/lib/app_component.dart +++ b/lib/app_component.dart @@ -6,8 +6,8 @@ import 'package:angular2_rbi/directives.dart'; import 'product_component.dart'; import 'product_category_component.dart'; import 'product_detail_component.dart'; -import 'product_service.dart'; -import 'product_category_service.dart'; + +import 'tables_component.dart'; @Component( selector: 'my-app', @@ -18,8 +18,6 @@ import 'product_category_service.dart'; MaterialLayout ], providers: const [ - ProductService, - ProductCategoryService, ROUTER_PROVIDERS ] ) @@ -40,6 +38,11 @@ import 'product_category_service.dart'; path: '/product/:id', name: 'ProductDetail', component: ProductDetailComponent + ), + const Route( + path: '/tables', + name: 'Tables', + component: TablesComponent ) ]) diff --git a/lib/product_category_component.dart b/lib/product_category_component.dart index b7d3bf1..70b1a93 100644 --- a/lib/product_category_component.dart +++ b/lib/product_category_component.dart @@ -29,8 +29,13 @@ class ProductCategoryComponent implements OnInit { ProductCategoryComponent(this._prodcatSrv,this._router); Future createProductCategory() async { - await _prodcatSrv.createProdCategory(new_prod_category_name); - await ngOnInit(); + String id = await _prodcatSrv.createProdCategory( + new_prod_category_name + ); + product_categories.add(new ProductCategory( + id,new_prod_category_name,'product_cetegory' + )); + new_prod_category_name=''; } Future ngOnInit() async { diff --git a/lib/product_category_service.dart b/lib/product_category_service.dart index f246a71..0d2830d 100644 --- a/lib/product_category_service.dart +++ b/lib/product_category_service.dart @@ -35,9 +35,9 @@ class ProductCategoryService { } } - Future createProdCategory(String name) async { + Future createProdCategory(String name) async { try { - await _http.post( + var res = await _http.post( _posturl, headers: {'Content-Type': 'application/json'}, body: JSON.encode({ @@ -45,6 +45,7 @@ class ProductCategoryService { 'type': 'product_category' }) ); + return(JSON.decode(res.body)['id']); } catch(e) { throw _handleError(e); diff --git a/lib/product_detail_component.dart b/lib/product_detail_component.dart index 14ba7a7..59f9fab 100644 --- a/lib/product_detail_component.dart +++ b/lib/product_detail_component.dart @@ -70,9 +70,12 @@ class ProductDetailComponent implements OnInit { await _prodSrv.updateProd( prod.id, prod_name, - double.parse(prod_price), + prod_price, prod_category ); + prod.price=prod_price; + prod.name=prod_name; + prod.category=prod_category; } } diff --git a/lib/product_service.dart b/lib/product_service.dart index 0ffe964..218b169 100644 --- a/lib/product_service.dart +++ b/lib/product_service.dart @@ -57,7 +57,7 @@ class ProductService { } } - Future createProduct(String name,double price,String cat) async { + Future createProduct(String name,double pri,String cat) async { try { var url=_server+'/'+_db; var response = await _http.post( @@ -65,7 +65,7 @@ class ProductService { headers: {'Content-Type': 'application/json'}, body: JSON.encode({ 'name': name, - 'price': price, + 'price': pri, 'type': 'product', 'category': cat })