]> hackdaworld.org Git - outofuni/tavern2.git/commitdiff
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 2175bdfae18b17e987b6f138c53ee7aec62dc6bc..814cfb9afeab966211194de69eb534d47ee36725 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 b7d3bf12f562bc0db73f564ee54d0ddce895fe67..70b1a93996594f6c3d3b017c185ab7fead68bbd1 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 f246a71183bb69148c668305e146d9b89c94cc8a..0d2830dfc33dddd615c454b9a678c4c74c532c2c 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 14ba7a738a0cc06774a9b69085566c02393fb15d..59f9fab6bc73a747d4662aa6f9337abe41e2243f 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 0ffe964b17c0038520314349e0d6ffa1b3077071..218b16937ae027cfd302425ef52113aa03e984a5 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
                                })