Browse Source

Changed regex typeahead lookup, also works with literal regex patterns

Torkel Ödegaard 10 years ago
parent
commit
dd8d6bc705
2 changed files with 17 additions and 1 deletions
  1. 12 1
      public/app/directives/metric.segment.js
  2. 5 0
      public/vendor/bootstrap/bootstrap.js

+ 12 - 1
public/app/directives/metric.segment.js

@@ -103,8 +103,19 @@ function (angular, app, _, $) {
             return value;
             return value;
           };
           };
 
 
+          $scope.matcher = function(item) {
+            var str = this.query;
+            if (str[0] === '/') { str = str.substring(1); }
+            if (str[str.length - 1] === '/') { str = str.substring(0, str.length-1); }
+            try {
+              return item.toLowerCase().match(str);
+            } catch(e) {
+              return false;
+            }
+          };
+
           $input.attr('data-provide', 'typeahead');
           $input.attr('data-provide', 'typeahead');
-          $input.typeahead({ source: $scope.source, minLength: 0, items: 10000, updater: $scope.updater });
+          $input.typeahead({ source: $scope.source, minLength: 0, items: 10000, updater: $scope.updater, matcher: $scope.matcher });
 
 
           var typeahead = $input.data('typeahead');
           var typeahead = $input.data('typeahead');
           typeahead.lookup = function () {
           typeahead.lookup = function () {

+ 5 - 0
public/vendor/bootstrap/bootstrap.js

@@ -2069,6 +2069,11 @@
   , move: function (e) {
   , move: function (e) {
       if (!this.shown) return
       if (!this.shown) return
 
 
+      // grafana change, shift+left paranthesis
+      if (e.shiftKey && e.keyCode === 40) {
+        return;
+      }
+
       switch(e.keyCode) {
       switch(e.keyCode) {
         case 9: // tab
         case 9: // tab
         case 13: // enter
         case 13: // enter