This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/regex-match-view.js
Joseph Schorr 8e863b8cf5 Implement new create and manager trigger UI
Implements the new trigger setup user interface, which is now a linear workflow found on its own page, rather than a tiny modal dialog

Fixes #1187
2017-02-28 16:51:42 -05:00

36 lines
No EOL
988 B
JavaScript

/**
* 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;
});