Feature: Product list allows for displaying extended information and search bar shows the legend.
This commit is contained in:
1 parent
30442ffecb
commit
0436a5de2c
3 files changed
+46
-32
No files matched your search
@@ -2,8 +2,8 @@
|
||||
|
||||
var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', function ($scope, $location, $routeParams, products) {
|
||||
$scope.search = $routeParams.q || '';
|
||||
$scope.show_extended = false;
|
||||
$scope.info = products;
|
||||
var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g;
|
||||
|
||||
$scope.isTrue = function (value) {
|
||||
value = value.toLowerCase();
|
||||
@@ -16,6 +16,31 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', functi
|
||||
$scope.filterProducts(newValue);
|
||||
}, true);
|
||||
|
||||
$scope.parseFilterString = function (q, defaultKey) {
|
||||
var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g;
|
||||
var matches = [];
|
||||
if (angular.isUndefined(defaultKey)) {
|
||||
defaultKey = 'n';
|
||||
}
|
||||
var m = q.match(re);
|
||||
_.forEach(m, function (item) {
|
||||
item = item.toLowerCase();
|
||||
if (item.indexOf(':') === -1) {
|
||||
matches.push({'key': defaultKey, 'value': item});
|
||||
} else {
|
||||
var key = item.substr(0, item.indexOf(':')).toLowerCase();
|
||||
var value = item.substr(item.indexOf(':') + 1, item.length).trim().toLowerCase();
|
||||
if (value.indexOf("'") !== 0 || value.indexOf('"') !== 0) {
|
||||
value = value.substring(1, value.length - 2).trim();
|
||||
}
|
||||
if (key !== '' && value !== '') {
|
||||
matches.push({'key': key, 'value': value});
|
||||
}
|
||||
}
|
||||
});
|
||||
return matches;
|
||||
};
|
||||
|
||||
$scope.filterProducts = _.debounce(function (q) {
|
||||
if (q !== $scope._search) {
|
||||
$scope._search = q;
|
||||
@@ -25,35 +50,20 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', functi
|
||||
$location.path('/Products').search({'q': q}).replace();
|
||||
}
|
||||
$scope.$apply(function () {
|
||||
$scope.products = $scope.doFilter(q);
|
||||
var matches = $scope.parseFilterString(q);
|
||||
$scope.show_extended = _.any(matches, function (item) {
|
||||
return ((item.key === 'e' || item.key === 'ext') && $scope.isTrue(item.value));
|
||||
});
|
||||
$scope.products = $scope.doFilter(q, matches);
|
||||
});
|
||||
}
|
||||
}, 350);
|
||||
$scope.doFilter = _.memoize(function (q) {
|
||||
var matches = [], i, len;
|
||||
if (angular.isUndefined(q) || q === '') {
|
||||
$scope.doFilter = _.memoize(function (q, matches) {
|
||||
var i, len = matches.length;
|
||||
if (len <= 0) {
|
||||
return $scope.info;
|
||||
}
|
||||
var m = q.match(re);
|
||||
_.forEach(m, function (item) {
|
||||
item = item.toLowerCase();
|
||||
if (item.indexOf(':') === -1) {
|
||||
matches.push({'key': 'n', 'value': item});
|
||||
} else {
|
||||
var key = item.substr(0, item.indexOf(':')).toLowerCase();
|
||||
var value = item.substr(item.indexOf(':') + 1, item.length).trim().toLowerCase();
|
||||
if (value.indexOf("'") === 0 || value.indexOf('"') === 0) {
|
||||
value = value.substring(1, value.length - 2);
|
||||
}
|
||||
if (key !== '' && value !== '' && _.any(['a', 'u', 'g'], function (item) {
|
||||
return item === key;
|
||||
})) {
|
||||
matches.push({'key': key, 'value': value});
|
||||
}
|
||||
}
|
||||
});
|
||||
return _.filter($scope.info, function (item) {
|
||||
len = matches.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
var match = matches[i];
|
||||
if (match.key === 'n') {
|
||||
@@ -61,7 +71,7 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', functi
|
||||
return false;
|
||||
}
|
||||
} else if (match.key === 'a') {
|
||||
if (item.IsActive === $scope.isTrue(match.value)) {
|
||||
if (item.IsActive !== $scope.isTrue(match.value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (match.key === 'u') {
|
||||
|
||||
Reference in new issue
Block a user