Explorar o código

Added query input binding

Rashid Khan %!s(int64=13) %!d(string=hai) anos
pai
achega
e54982d42d

+ 1 - 1
config.js

@@ -30,7 +30,7 @@ var config = new Settings(
     timefield:      '@timestamp', 
     timefield:      '@timestamp', 
     //indexpattern:  '"logstash-"yyyy.mm.dd',
     //indexpattern:  '"logstash-"yyyy.mm.dd',
     indexpattern:   '"shakespeare"', 
     indexpattern:   '"shakespeare"', 
-    modules:        ['histogram','map','pie','table'], 
+    modules:        ['histogram','map','pie','table','stringquery'], 
 
 
     defaultfields:  ['line_text'],
     defaultfields:  ['line_text'],
     perpage:        50,
     perpage:        50,

+ 20 - 13
dashboards.js

@@ -2,6 +2,16 @@ var dashboards =
 {
 {
   title: "Infinite Monkey Dashboard",
   title: "Infinite Monkey Dashboard",
   rows: [
   rows: [
+    {
+      height: "30px",
+      panels: [
+        {
+          type    : "stringquery",
+          span    : 12,
+          group   : "mainsearch"
+        }
+      ]
+    },
     {
     {
       height: "300px",
       height: "300px",
       panels: [
       panels: [
@@ -11,12 +21,8 @@ var dashboards =
           span    : 6,
           span    : 6,
           show    : ['lines','stack'],
           show    : ['lines','stack'],
           fill    : 1,
           fill    : 1,
-          query   : [
-            { label : "US", query : "country:US", color: '#86B32D' },
-            { label : "CN", query : "country:CN", color: '#BF3030' },
-            { label : "IN", query : "country:IN", color: '#1D7373' }
-          ],
-          color   : "#7BA4AF"
+          query   : [{ label : "lines", query : "*", color: '#86B32D' } ],
+          group   : "mainsearch"
         },
         },
         {
         {
           title   : "World Monkeys",
           title   : "World Monkeys",
@@ -25,7 +31,9 @@ var dashboards =
           field   : "country",
           field   : "country",
           span    : 6,
           span    : 6,
           size    : 500,
           size    : 500,
-          query   : "*"
+          query   : "*",
+          group   : "mainsearch"
+
         }
         }
       ]
       ]
     },
     },
@@ -33,7 +41,7 @@ var dashboards =
       height: "300px",
       height: "300px",
       panels: [
       panels: [
         {
         {
-          title   : "Hamlet vs Macbeth",
+          title   : "Plays",
           type    : "pie",
           type    : "pie",
           span    : 4,
           span    : 4,
           size    : 8,
           size    : 8,
@@ -41,17 +49,16 @@ var dashboards =
           colors  : ['#BF3030','#1D7373','#86B32D','#A60000','#006363','#679B00'],
           colors  : ['#BF3030','#1D7373','#86B32D','#A60000','#006363','#679B00'],
           field   : 'country',
           field   : 'country',
           //query   : { query: "*", field: "country"}
           //query   : { query: "*", field: "country"}
-          query   : [
-            { label : "Hamlet", query : "play_name:Hamlet", color: '#86B32D' },
-            { label : "Macbeth", query : "play_name:macbeth", color: '#BF3030' },
-          ]
+          query   : { field : "play_name", query : "*" },
+          group   : "mainsearch"
         },
         },
         {
         {
           title   : "Newest Lines",
           title   : "Newest Lines",
           type    : "table",
           type    : "table",
           span    : 8,
           span    : 8,
           query   : "*",
           query   : "*",
-          fields  : ['@timestamp','speaker','text_entry']
+          fields  : ['@timestamp','speaker','text_entry'],
+          group   : "mainsearch"
         }
         }
       ]
       ]
     }
     }

+ 7 - 0
panels/histogram/module.js

@@ -14,6 +14,13 @@ angular.module('kibana.histogram', [])
       ? _d[k] : $scope.panel[k];
       ? _d[k] : $scope.panel[k];
   });
   });
 
 
+  if (!(_.isUndefined($scope.panel.group))) {
+    $scope.$on($scope.panel.group+"-query", function(event, query) {
+      $scope.panel.query[0].query = query;
+      $scope.get_data();
+    });
+  }
+
   $scope.get_data = function() {
   $scope.get_data = function() {
     var request = $scope.ejs.Request().indices($scope.index);
     var request = $scope.ejs.Request().indices($scope.index);
     
     

+ 8 - 0
panels/map/module.js

@@ -14,6 +14,14 @@ angular.module('kibana.map', [])
       ? _d[k] : $scope.panel[k];
       ? _d[k] : $scope.panel[k];
   });
   });
 
 
+
+  if (!(_.isUndefined($scope.panel.group))) {
+    $scope.$on($scope.panel.group+"-query", function(event, query) {
+      $scope.panel.query = query;
+      $scope.get_data();
+    });
+  }
+
   $scope.get_data = function() {
   $scope.get_data = function() {
     var request = $scope.ejs.Request().indices($scope.index);
     var request = $scope.ejs.Request().indices($scope.index);
 
 

+ 7 - 0
panels/pie/module.js

@@ -18,6 +18,13 @@ angular.module('kibana.pie', [])
       ? _d[k] : $scope.panel[k];
       ? _d[k] : $scope.panel[k];
   });
   });
 
 
+  if (!(_.isUndefined($scope.panel.group)) && !(_.isArray($scope.panel.query))) {
+    $scope.$on($scope.panel.group+"-query", function(event, query) {
+      $scope.panel.query.query = query;
+      $scope.get_data();
+    });
+  }
+
   $scope.get_data = function() {
   $scope.get_data = function() {
     var request = $scope.ejs.Request().indices($scope.index);
     var request = $scope.ejs.Request().indices($scope.index);
 
 

+ 7 - 0
panels/stringquery/module.html

@@ -0,0 +1,7 @@
+<div ng-controller='stringquery'>
+  <h4 ng-hide="_.isUndefined(panel.title)">{{panel.title}}</h4>
+    <form class="form-search">
+      <input type="text" class="input-medium search-query" ng-model="query" style="width:90%">
+      <button type="submit" class="btn" ng-click="send_query(query)">Search</button>
+    </form>
+</div>

+ 20 - 0
panels/stringquery/module.js

@@ -0,0 +1,20 @@
+angular.module('kibana.stringquery', [])
+.controller('stringquery', function($scope, $rootScope) {
+
+  // Set and populate defaults
+  var _d = {
+    query   : "*",
+    size    : 100,
+    sort    : [config.timefield,'desc'],
+  }
+  _.each(_d, function(v, k) {
+    $scope.panel[k] = _.isUndefined($scope.panel[k]) 
+      ? _d[k] : $scope.panel[k];
+  });
+
+  if (!(_.isUndefined($scope.panel.group))) {
+    $scope.send_query = function(query) {
+      $rootScope.$broadcast($scope.panel.group+"-query", query)  
+    }
+  }
+})

+ 8 - 2
panels/table/module.js

@@ -12,6 +12,13 @@ angular.module('kibana.table', [])
       ? _d[k] : $scope.panel[k];
       ? _d[k] : $scope.panel[k];
   });
   });
 
 
+  if (!(_.isUndefined($scope.panel.group))) {
+    $scope.$on($scope.panel.group+"-query", function(event, query) {
+      $scope.panel.query = query;
+      $scope.get_data();
+    });
+  }
+
   $scope.get_data = function() {
   $scope.get_data = function() {
     var request = $scope.ejs.Request().indices($scope.index);
     var request = $scope.ejs.Request().indices($scope.index);
 
 
@@ -30,7 +37,6 @@ angular.module('kibana.table', [])
 
 
     // Populate scope when we have results
     // Populate scope when we have results
     results.then(function(results) {
     results.then(function(results) {
-      console.log(results)
       $scope.hits = results.hits.total;
       $scope.hits = results.hits.total;
       $scope.data = results.hits.hits;
       $scope.data = results.hits.hits;
       /*
       /*
@@ -55,4 +61,4 @@ angular.module('kibana.table', [])
     $scope.get_data();
     $scope.get_data();
   });
   });
 
 
-})
+})