update views + reduced providers in main app
authorhackbard <hackbard@hackdaworld.org>
Mon, 17 Oct 2016 20:28:20 +0000 (22:28 +0200)
committerhackbard <hackbard@hackdaworld.org>
Mon, 17 Oct 2016 20:28:20 +0000 (22:28 +0200)
lib/app_component.dart
lib/product_category_component.dart
lib/product_category_service.dart
lib/product_detail_component.dart
lib/product_service.dart

index 2175bdf..814cfb9 100644 (file)
@@ -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
        )
 ])
 
index b7d3bf1..70b1a93 100644 (file)
@@ -29,8 +29,13 @@ class ProductCategoryComponent implements OnInit {
        ProductCategoryComponent(this._prodcatSrv,this._router);
 
        Future<Null> 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<Null> ngOnInit() async {
index f246a71..0d2830d 100644 (file)
@@ -35,9 +35,9 @@ class ProductCategoryService {
                }
        }
 
-       Future<Null> createProdCategory(String name) async {
+       Future<String> 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);
index 14ba7a7..59f9fab 100644 (file)
@@ -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;
                }
        }
 
index 0ffe964..218b169 100644 (file)
@@ -57,7 +57,7 @@ class ProductService {
                }
        }
 
-       Future<Null> createProduct(String name,double price,String cat) async {
+       Future<String> 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
                                })