X-Git-Url: https://hackdaworld.org/gitweb/?p=outofuni%2Ftavern2.git;a=blobdiff_plain;f=lib%2Fproduct_component.dart;fp=lib%2Fproduct_component.dart;h=6fb5461cb7095d3191aa8166e03392b4cc79e93a;hp=ed08975fdc6f6f47b340641ee8765ea3e5085621;hb=b2028ca4879e48884436ee0c2aee7fae6ddaeb5a;hpb=3307c69f4b16867ba7522626b6b0acf2d6d9a478 diff --git a/lib/product_component.dart b/lib/product_component.dart index ed08975..6fb5461 100644 --- a/lib/product_component.dart +++ b/lib/product_component.dart @@ -27,8 +27,9 @@ class ProductComponent implements OnInit { final RouteParams _routeParams; final Router _router; - String prod_category_id; + String catid; String prod_category_name; + String prod_name; double prod_price; int prodcnt; @@ -39,67 +40,33 @@ class ProductComponent implements OnInit { ProductComponent(this._prodSrv,this._prodcatSrv, this._routeParams,this._router) { prod_category_name='Category'; - prod_category_id='ID'; } Future ngOnInit() async { - var catid=_routeParams.get('id'); + catid=_routeParams.get('id'); if(catid!=null) { products = await (_prodSrv.getByCategory(catid)); prodcat = await (_prodcatSrv.getById(catid)); } prod_category_name=prodcat.name; - prod_category_id=prodcat.id; prodcnt=products.length; } Future updateProductCategory() async { - bool doupdate=false; - bool changecat=false; - if(prodcat.id!=prod_category_id) { - doupdate=true; - changecat=true; - } if(prodcat.name!=prod_category_name) { - doupdate=true; - } - if(doupdate) { - if(changecat) { - for(Product prod in products) { - print('Debug: change category of '+ - prod.name); - await _prodSrv.updateProd( - prod.id, - prod.name, - prod.price, - prod_category_id - ); - } - } - print('Debug: Updating product category '+ - prodcat.name+'/'+prodcat.id+' -> '+ - prod_category_name+'/'+prod_category_id); await _prodcatSrv.updateProdCategory( - prodcat.id, - prod_category_name, - prod_category_id + catid, + prod_category_name ); + _router.navigate(['ProductCategories']); } } Future deleteProductCategory() async { - bool delete=false; - if(products.length==0) { - delete=true; - } - else { - print('Debug: Not deleting anything!'); - } - if(delete) { - print('Debug: Deleting product category '+ - prodcat.name+'/'+prodcat.id); - await _prodcatSrv.deleteProdCategory(prodcat.doc_id); - } + print('Debug: Deleting product category '+ + prodcat.name+'/'+prodcat.id); + await _prodcatSrv.deleteProdCategory(prodcat.id); + _router.navigate(['ProductCategories']); } Future createProduct() async { @@ -107,9 +74,15 @@ class ProductComponent implements OnInit { return; print('Debug: Creating product '+prod_name+'/'+ prod_price.toString()); - await _prodSrv.createProduct(prod_name, + String id = await _prodSrv.createProduct(prod_name, double.parse(prod_price), - prod_category_id); + catid); + // instead of executing ngOnInit to 'reload' content + products.add(new Product( + id,prod_name,double.parse(prod_price),'product',catid + )); + prod_name=''; + prod_price=''; } choose(Product prod) {