From f68c55e38fbdd54c0b3c3caf854dd4baa83482bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 26 Dec 2013 22:45:36 +0100 Subject: [PATCH] removed non relevant kibana code --- src/app/controllers/pulldown.js | 4 +- src/app/controllers/row.js | 3 +- src/app/filters/all.js | 15 -- src/app/partials/querySelect.html | 24 --- src/app/services/all.js | 1 - src/app/services/dashboard.js | 50 +----- src/app/services/querySrv.js | 261 ------------------------------ 7 files changed, 5 insertions(+), 353 deletions(-) delete mode 100644 src/app/partials/querySelect.html delete mode 100644 src/app/services/querySrv.js diff --git a/src/app/controllers/pulldown.js b/src/app/controllers/pulldown.js index ed00ba12740..abda589384d 100644 --- a/src/app/controllers/pulldown.js +++ b/src/app/controllers/pulldown.js @@ -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; diff --git a/src/app/controllers/row.js b/src/app/controllers/row.js index 6c9d34d46dd..fb156324a4d 100644 --- a/src/app/controllers/row.js +++ b/src/app/controllers/row.js @@ -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(); }; diff --git a/src/app/filters/all.js b/src/app/filters/all.js index 986a6eadc4a..e4ffe7088c8 100644 --- a/src/app/filters/all.js +++ b/src/app/filters/all.js @@ -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 */ diff --git a/src/app/partials/querySelect.html b/src/app/partials/querySelect.html deleted file mode 100644 index 8a994aa42ea..00000000000 --- a/src/app/partials/querySelect.html +++ /dev/null @@ -1,24 +0,0 @@ -
- -
- - -
-
- - - - {{querySrv.list[id].alias || querySrv.list[id].query}} - -
-
diff --git a/src/app/services/all.js b/src/app/services/all.js index 9f1c27d8425..99ed5f22ac2 100644 --- a/src/app/services/all.js +++ b/src/app/services/all.js @@ -4,7 +4,6 @@ define([ './fields', './filterSrv', './kbnIndex', - './querySrv', './timer', './panelMove', './esVersion', diff --git a/src/app/services/dashboard.js b/src/app/services/dashboard.js index bf04823fabc..a58be55624f 100644 --- a/src/app/services/dashboard.js +++ b/src/app/services/dashboard.js @@ -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(); diff --git a/src/app/services/querySrv.js b/src/app/services/querySrv.js deleted file mode 100644 index 3bb9324e5ba..00000000000 --- a/src/app/services/querySrv.js +++ /dev/null @@ -1,261 +0,0 @@ -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