/** * An element which displays the matches and non-matches for a regular expression against a set of * items. */ angular.module('quay').directive('regexMatchView', function () { var directiveDefinitionObject = { priority: 0, templateUrl: '/static/directives/regex-match-view.html', replace: false, transclude: true, restrict: 'C', scope: { 'regex': '=regex', 'items': '=items' }, controller: function($scope, $element) { $scope.filterMatches = function(regexstr, items, shouldMatch) { regexstr = regexstr || '.+'; try { var regex = new RegExp(regexstr); } catch (ex) { return null; } return items.filter(function(item) { var value = item['value']; var m = value.match(regex); var matches = !!(m && m[0].length == value.length); return matches == shouldMatch; }); }; } }; return directiveDefinitionObject; });