From 1439befc46bd7562ec7a2bea6e2d23f166ab8a6d Mon Sep 17 00:00:00 2001 From: tanshu Date: Wed, 16 Mar 2016 21:11:08 +0530 Subject: [PATCH] Fix: Errors in the comparators in Tokenizer Feature: Product list shows more information --- brewman/static/base.html | 2 +- brewman/static/partial/product-detail.html | 1 - brewman/static/partial/product-list.html | 54 ++++++++++++++++++++-- brewman/static/scripts/angular_service.js | 6 +-- brewman/static/scripts/product.js | 43 ++++++++++++++++- brewman/views/product.py | 10 ++-- 6 files changed, 100 insertions(+), 16 deletions(-) diff --git a/brewman/static/base.html b/brewman/static/base.html index 9fedb2f3..a4ebc8a9 100644 --- a/brewman/static/base.html +++ b/brewman/static/base.html @@ -12,7 +12,7 @@ - + diff --git a/brewman/static/partial/product-detail.html b/brewman/static/partial/product-detail.html index ce0412f2..8368d18c 100644 --- a/brewman/static/partial/product-detail.html +++ b/brewman/static/partial/product-detail.html @@ -55,7 +55,6 @@ {{pg.Name}} -
Save diff --git a/brewman/static/partial/product-list.html b/brewman/static/partial/product-list.html index 95bd941b..e751cd38 100644 --- a/brewman/static/partial/product-list.html +++ b/brewman/static/partial/product-list.html @@ -2,14 +2,37 @@
+ placeholder="Search: n:Name, u:Units, s:Sold, p:Purchased, a:Active, t:Type and e:true for extended properties"> Add
- +
+ + + + All + Yes + No + + + + + + All + Yes + No + + + + + + {{pg}} + + +
@@ -18,7 +41,7 @@ - + @@ -27,10 +50,31 @@ - + - +
Price Yield TypeIs Active?Details
{{item.Code}} {{item.Name}} ({{showExtended ? item.Fraction + ' ' + item.FractionUnits + ' = 1 ' : ''}}{{item.Units}}){{item.Price | currency}}{{item.CostPrice | currency}} {{item.ProductYield * 100 | number:2}}% {{item.ProductGroup}}{{item.IsActive}} +
+
+ + {{ item.IsPurchased ? "shopping_cart" : "remove_shopping_cart" }} + + {{ item.IsPurchased ? "Purchased" : "Made" }} +
+
+ + {{ item.IsSold ? "restaurant_menu" : "import_contacts" }} + + {{ item.IsSold ? "Sold" : "Used" }} +
+
+ + {{ item.IsActive ? "visibility" : "visibility_off" }} + + {{ item.IsActive ? "Active" : "Deactivated" }} +
+
+
diff --git a/brewman/static/scripts/angular_service.js b/brewman/static/scripts/angular_service.js index c7a3ecf3..2de838e1 100644 --- a/brewman/static/scripts/angular_service.js +++ b/brewman/static/scripts/angular_service.js @@ -264,9 +264,9 @@ overlordService.factory('Tokenizer', ['$filter', function ($filter) { comparators = { 'text': function (obj, text) { if (text.indexOf('!') === 0) { - return obj.toLowerCase().indexOf(text.substr(1)) <= -1; + return !obj.toLowerCase().includes(text.substr(1).toLowerCase()); } else { - return obj.toLowerCase().indexOf(text) > -1; + return obj.toLowerCase().includes(text.toLowerCase()); } }, 'date': function (obj, text) { @@ -333,7 +333,7 @@ overlordService.factory('Tokenizer', ['$filter', function ($filter) { key = key.substring(1, key.length - 1).trim(); } if (value.indexOf("'") !== -1 || value.indexOf('"') !== -1) { - value = key.substring(1, value.length - 1).trim(); + value = value.substring(1, value.length - 1).trim(); } if (value !== '') { accumulator.push({Key: key, Value: value}); diff --git a/brewman/static/scripts/product.js b/brewman/static/scripts/product.js index 406f7fa0..5de37ebb 100644 --- a/brewman/static/scripts/product.js +++ b/brewman/static/scripts/product.js @@ -4,6 +4,45 @@ var ProductListController = ['$scope', '$location', '$routeParams', 'Tokenizer', $scope.search = $routeParams.q || ''; $scope.showExtended = false; $scope.info = products; + $scope.product_groups = _.reduce(products, function (acculumator, item) { + if (!acculumator.includes(item.ProductGroup)){ + acculumator.push(item.ProductGroup); + } + return acculumator; + },[]).sort(); + $scope.isPurchased = function (isPurchased) { + if (arguments.length === 0) { + return $scope._isPurchased; + } + $scope._isPurchased = isPurchased; + var re = /(('[p]'|"[p]"|[p]+)\s*:\s*('[^']+'|"[^"]+"|[^\s]+))/gi, + matches = $scope.search.match(re), + st = isPurchased === 'null' ? '' : 'p:' + isPurchased; + $scope.search = (matches === null) ? $scope.search.trim() + ' ' + st : $scope.search.replace(re, st); + }; + + $scope.isSold = function (isSold) { + if (arguments.length === 0) { + return $scope._isSold; + } + $scope._isSold = isSold; + var re = /(('[s]'|"[s]"|[s]+)\s*:\s*('[^']+'|"[^"]+"|[^\s]+))/gi, + matches = $scope.search.match(re), + st = isSold === 'null' ? '' : 's:' + isSold; + $scope.search = (matches === null) ? $scope.search.trim() + ' ' + st : $scope.search.replace(re, st); + }; + + $scope.productGroup = function (productGroup) { + if (arguments.length === 0) { + + return $scope._productGroup; + } + $scope._productGroup = productGroup; + var re = /(('[t]'|"[t]"|[t]+)\s*:\s*('[^']+'|"[^"]+"|[^\s]+))/gi, + matches = $scope.search.match(re), + st = 't:"' + productGroup + '"'; + $scope.search = (matches === null) ? $scope.search.trim() + ' ' + st : $scope.search.replace(re, st); + }; $scope.$watch('search', function (value) { $scope.filterProducts(value); @@ -16,8 +55,10 @@ var ProductListController = ['$scope', '$location', '$routeParams', 'Tokenizer', $scope.searchInfo = { comparator: { 'n': {'Col': 'Name', 'Comparator': 'text'}, - 'a': {'Col': 'IsActive', 'Comparator': 'boolean'}, 'u': {'Col': 'Units', 'Comparator': 'text'}, + 'a': {'Col': 'IsActive', 'Comparator': 'boolean'}, + 's': {'Col': 'IsSold', 'Comparator': 'boolean'}, + 'p': {'Col': 'IsPurchased', 'Comparator': 'boolean'}, 't': {'Col': 'ProductGroup', 'Comparator': 'text'}, 'y': {'Col': 'ProductYield', 'Comparator': 'numeric'} }, diff --git a/brewman/views/product.py b/brewman/views/product.py index ccd562e7..466c9823 100644 --- a/brewman/views/product.py +++ b/brewman/views/product.py @@ -155,11 +155,11 @@ def show_list(request): Product.name).all() products = [] for item in list: - products.append({'Code': item.code, 'Name': item.name, 'Units': item.units, 'Price': item.price, - 'ProductGroup': item.product_group.name, 'IsActive': item.is_active, - 'Fraction': item.fraction, 'FractionUnits': item.fraction_units, - 'ProductYield': item.product_yield, 'IsFixture': item.is_fixture, - 'Url': request.route_url('product_id', id=item.id)}) + products.append({'Code': item.code, 'Name': item.name, 'Units': item.units, 'CostPrice': item.price, + 'SalePrice': item.sale_price, 'ProductGroup': item.product_group.name, + 'IsActive': item.is_active, 'Fraction': item.fraction, 'FractionUnits': item.fraction_units, + 'IsPurchased': item.is_purchased, 'IsSold': item.is_sold, 'ProductYield': item.product_yield, + 'IsFixture': item.is_fixture, 'Url': request.route_url('product_id', id=item.id)}) return products