| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- angular.module('kibana.hits', [])
- .controller('hits', function($scope, eventBus) {
- var _id = _.uniqueId();
- // Set and populate defaults
- var _d = {
- query : "*",
- group : "default",
- style : { "font-size": '36pt', "font-weight": "bold" },
- }
- _.defaults($scope.panel,_d)
- $scope.init = function () {
- eventBus.register($scope,'time', function(event,time){set_time(time)});
- eventBus.register($scope,'query', function(event, query) {
- $scope.panel.query = query;
- $scope.get_data();
- });
- // Now that we're all setup, request the time from our group
- eventBus.broadcast($scope.$id,$scope.panel.group,'get_time')
- }
- $scope.get_data = function() {
- // Make sure we have everything for the request to complete
- if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.panel.time))
- return
- var request = $scope.ejs.Request().indices($scope.panel.index);
- var results = request
- .query(ejs.FilteredQuery(
- ejs.QueryStringQuery($scope.panel.query || '*'),
- ejs.RangeFilter(config.timefield)
- .from($scope.panel.time.from)
- .to($scope.panel.time.to)
- )
- )
- .size(0)
- .doSearch();
- // Populate scope when we have results
- results.then(function(results) {
- if(_.isUndefined(results)) {
- $scope.panel.error = 'Your query was unsuccessful';
- return;
- }
- $scope.panel.error = false;
- $scope.hits = results.hits.total;
- });
- }
- function set_time(time) {
- $scope.panel.time = time;
- $scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
- $scope.get_data();
- }
- $scope.init();
- })
|