Commit f68c55e3 by Torkel Ödegaard

removed non relevant kibana code

parent 566f6ebd
......@@ -8,7 +8,7 @@ function (angular, app, _) {
var module = angular.module('kibana.controllers');
module.controller('PulldownCtrl', function($scope, $rootScope, $timeout,ejsResource, querySrv) {
module.controller('PulldownCtrl', function($scope, $rootScope, $timeout,ejsResource) {
var _d = {
collapse: false,
notice: false,
......@@ -18,8 +18,6 @@ function (angular, app, _) {
_.defaults($scope.pulldown,_d);
$scope.init = function() {
$scope.querySrv = querySrv;
// Provide a combined skeleton for panels that must interact with panel and row.
// This might create name spacing issues.
$scope.panel = $scope.pulldown;
......
......@@ -8,7 +8,7 @@ function (angular, app, _) {
var module = angular.module('kibana.controllers');
module.controller('RowCtrl', function($scope, $rootScope, $timeout,ejsResource, querySrv) {
module.controller('RowCtrl', function($scope, $rootScope, $timeout,ejsResource) {
var _d = {
title: "Row",
height: "150px",
......@@ -22,7 +22,6 @@ function (angular, app, _) {
_.defaults($scope.row,_d);
$scope.init = function() {
$scope.querySrv = querySrv;
$scope.reset_panel();
};
......
......@@ -9,21 +9,6 @@ define(['angular', 'jquery', 'underscore', 'moment'], function (angular, $, _, m
};
});
module.filter('pinnedQuery', function(querySrv) {
return function( items, pinned) {
var ret = _.filter(querySrv.ids,function(id){
var v = querySrv.list[id];
if(!_.isUndefined(v.pin) && v.pin === true && pinned === true) {
return true;
}
if((_.isUndefined(v.pin) || v.pin === false) && pinned === false) {
return true;
}
});
return ret;
};
});
/*
Filter an array of objects by elasticsearch version requirements
*/
......
<div class="row-fluid">
<style>
.querySelect .query {
margin-right: 5px;
}
.querySelect .selected {
border: 3px solid;
}
.querySelect .unselected {
border: 0px solid;
}
</style>
<div class="span2" style="margin-left:0px">
<label class="small">Queries</label>
<select class="input-small" ng-change="set_refresh(true);" ng-model="panel.queries.mode" ng-options="f for f in ['all','pinned','unpinned','selected']"></select>
</div>
<div class="span9 querySelect" ng-show="panel.queries.mode == 'selected'">
<label class="small">Selected Queries</label>
<span ng-style="{'border-color': querySrv.list[id].color}" ng-class="{selected:_.contains(panel.queries.ids,id),unselected:!_.contains(panel.queries.ids,id)}" ng-repeat="id in querySrv.ids" ng-click="panel.queries.ids = _.toggleInOut(panel.queries.ids,id);set_refresh(true);" class="query pointer badge">
<i class="icon-circle" ng-style="{color: querySrv.list[id].color}"></i>
<span> {{querySrv.list[id].alias || querySrv.list[id].query}}</span>
</span>
</div>
</div>
......@@ -4,7 +4,6 @@ define([
'./fields',
'./filterSrv',
'./kbnIndex',
'./querySrv',
'./timer',
'./panelMove',
'./esVersion',
......
......@@ -69,7 +69,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
// Store a reference to this
var self = this;
var filterSrv,querySrv;
var filterSrv;
this.current = _.clone(_dash);
this.last = {};
......@@ -130,49 +130,8 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
}
};
// Since the dashboard is responsible for index computation, we can compute and assign the indices
// here before telling the panels to refresh
this.refresh = function() {
if(self.current.index.interval !== 'none') {
if(_.isUndefined(filterSrv)) {
return;
}
if(filterSrv.idsByType('time').length > 0) {
var _range = filterSrv.timeRange('last');
kbnIndex.indices(_range.from,_range.to,
self.current.index.pattern,self.current.index.interval
).then(function (p) {
if(p.length > 0) {
self.indices = p;
} else {
// Option to not failover
if(self.current.failover) {
self.indices = [self.current.index.default];
} else {
// Do not issue refresh if no indices match. This should be removed when panels
// properly understand when no indices are present
alertSrv.set('No results','There were no results because no indices were found that match your'+
' selected time span','info',5000);
return false;
}
}
// Don't resolve queries until indices are updated
querySrv.resolve().then(function(){$rootScope.$broadcast('refresh');});
});
} else {
if(self.current.failover) {
self.indices = [self.current.index.default];
querySrv.resolve().then(function(){$rootScope.$broadcast('refresh');});
} else {
alertSrv.set("No time filter",
'Timestamped indices are configured without a failover. Waiting for time filter.',
'info',5000);
}
}
} else {
self.indices = [self.current.index.default];
querySrv.resolve().then(function(){$rootScope.$broadcast('refresh');});
}
$rootScope.$broadcast('refresh');
};
var dash_defaults = function(dashboard) {
......@@ -200,12 +159,9 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
// Delay this until we're sure that querySrv and filterSrv are ready
$timeout(function() {
// Ok, now that we've setup the current dashboard, we can inject our services
querySrv = $injector.get('querySrv');
filterSrv = $injector.get('filterSrv');
// Make sure these re-init
querySrv.init();
filterSrv.init();
},0).then(function() {
// Call refresh to calculate the indices and notify the panels that we're ready to roll
self.refresh();
......
define([
'angular',
'underscore',
'config',
'kbn'
],
function (angular, _, config, kbn) {
'use strict';
var module = angular.module('kibana.services');
module.service('querySrv', function(dashboard, ejsResource, filterSrv, $q) {
// Create an object to hold our service state on the dashboard
dashboard.current.services.query = dashboard.current.services.query || {};
_.defaults(dashboard.current.services.query,{
list : {},
ids : [],
});
this.colors = [
"#7EB26D","#EAB839","#6ED0E0","#EF843C","#E24D42","#1F78C1","#BA43A9","#705DA0", //1
"#508642","#CCA300","#447EBC","#C15C17","#890F02","#0A437C","#6D1F62","#584477", //2
"#B7DBAB","#F4D598","#70DBED","#F9BA8F","#F29191","#82B5D8","#E5A8E2","#AEA2E0", //3
"#629E51","#E5AC0E","#64B0C8","#E0752D","#BF1B00","#0A50A1","#962D82","#614D93", //4
"#9AC48A","#F2C96D","#65C5DB","#F9934E","#EA6460","#5195CE","#D683CE","#806EB7", //5
"#3F6833","#967302","#2F575E","#99440A","#58140C","#052B51","#511749","#3F2B5B", //6
"#E0F9D7","#FCEACA","#CFFAFF","#F9E2D2","#FCE2DE","#BADFF4","#F9D9F9","#DEDAF7" //7
];
// For convenience
var ejs = ejsResource(config.elasticsearch);
// Holds all actual queries, including all resolved abstract queries
var resolvedQueries = [];
// Defaults for generic query object
var _query = {
alias: '',
pin: false,
type: 'lucene',
enable: true
};
// Defaults for specific query types
var _dTypes = {
"lucene": {
query: "*"
},
"regex": {
query: ".*"
},
"topN": {
query: "*",
field: "_type",
size: 5,
union: 'AND'
}
};
// query type meta data that is not stored on the dashboard object
this.queryTypes = {
lucene: {
require:">=0.17.0",
icon: "icon-circle",
resolve: function(query) {
// Simply returns itself
var p = $q.defer();
p.resolve(_.extend(query,{parent:query.id}));
return p.promise;
}
},
regex: {
require:">=0.90.3",
icon: "icon-circle",
resolve: function(query) {
// Simply returns itself
var p = $q.defer();
p.resolve(_.extend(query,{parent:query.id}));
return p.promise;
}
},
topN : {
require:">=0.90.3",
icon: "icon-cog",
resolve: function(q) {
var suffix = '';
if (q.union === 'AND') {
suffix = ' AND (' + (q.query||'*') + ')';
} else if (q.union === 'OR') {
suffix = ' OR (' + (q.query||'*') + ')';
}
var request = ejs.Request().indices(dashboard.indices);
// Terms mode
request = request
.facet(ejs.TermsFacet('query')
.field(q.field)
.size(q.size)
.facetFilter(ejs.QueryFilter(
ejs.FilteredQuery(
ejs.QueryStringQuery(q.query || '*'),
filterSrv.getBoolFilter(filterSrv.ids)
)))).size(0);
var results = request.doSearch();
// Like the regex and lucene queries, this returns a promise
return results.then(function(data) {
var _colors = kbn.colorSteps(q.color,data.facets.query.terms.length);
var i = -1;
return _.map(data.facets.query.terms,function(t) {
++i;
return self.defaults({
query : q.field+':"'+kbn.addslashes('' + t.term)+'"'+suffix,
alias : t.term + (q.alias ? " ("+q.alias+")" : ""),
type : 'lucene',
color : _colors[i],
parent : q.id
});
});
});
}
}
};
// Save a reference to this
var self = this;
this.init = function() {
self.list = dashboard.current.services.query.list;
self.ids = dashboard.current.services.query.ids;
// Check each query object, populate its defaults
_.each(self.list,function(query) {
query = self.defaults(query);
});
if (self.ids.length === 0) {
self.set({});
}
};
// This is used both for adding queries and modifying them. If an id is passed,
// the query at that id is updated
this.set = function(query,id) {
if(!_.isUndefined(id)) {
if(!_.isUndefined(self.list[id])) {
_.extend(self.list[id],query);
return id;
} else {
return false;
}
} else {
// Query must have an id and color already
query.id = _.isUndefined(query.id) ? nextId() : query.id;
query.color = query.color || colorAt(query.id);
// Then it can get defaults
query = self.defaults(query);
self.list[query.id] = query;
self.ids.push(query.id);
return query.id;
}
};
this.defaults = function(query) {
_.defaults(query,_query);
_.defaults(query,_dTypes[query.type]);
query.color = query.color || colorAt(query.id);
return query;
};
this.remove = function(id) {
if(!_.isUndefined(self.list[id])) {
delete self.list[id];
// This must happen on the full path also since _.without returns a copy
self.ids = dashboard.current.services.query.ids = _.without(self.ids,id);
return true;
} else {
return false;
}
};
// These are the only query types that can be returned by a compound query.
this.toEjsObj = function (q) {
switch(q.type)
{
case 'lucene':
return ejs.QueryStringQuery(q.query || '*');
case 'regex':
return ejs.RegexpQuery('_all',q.query);
default:
return false;
}
};
//
this.getQueryObjs = function(ids) {
if(_.isUndefined(ids)) {
return resolvedQueries;
} else {
return _.flatten(_.map(ids,function(id) {
return _.where(resolvedQueries,{parent:id});
}));
}
};
// BROKEN
this.idsByMode = function(config) {
switch(config.mode)
{
case 'all':
return _.pluck(_.where(self.list,{enable:true}),'id');
case 'pinned':
return _.pluck(_.where(self.list,{pin:true,enable:true}),'id');
case 'unpinned':
return _.pluck(_.where(self.list,{pin:false,enable:true}),'id');
case 'selected':
return _.intersection(_.pluck(_.where(self.list,{enable:true}),'id'),config.ids);
default:
return _.pluck(_.where(self.list,{enable:true}),'id');
}
};
// This populates the internal query list and returns a promise containing it
this.resolve = function() {
// Find ids of all abstract queries
// Get a list of resolvable ids, constrast with total list to get abstract ones
return $q.all(_.map(self.ids,function(q) {
return self.queryTypes[self.list[q].type].resolve(_.clone(self.list[q])).then(function(data){
return data;
});
})).then(function(data) {
resolvedQueries = _.flatten(data);
_.each(resolvedQueries,function(q,i) {
q.id = i;
});
return resolvedQueries;
});
};
var nextId = function() {
var idCount = dashboard.current.services.query.ids.length;
if(idCount > 0) {
// Make a sorted copy of the ids array
var ids = _.clone(dashboard.current.services.query.ids).sort();
return kbn.smallestMissing(ids);
} else {
// No ids currently in list
return 0;
}
};
var colorAt = function(id) {
return self.colors[id % self.colors.length];
};
self.init();
});
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment