Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from spenceralger/TimefilterAutoRefresh
Browse files Browse the repository at this point in the history
Timefilter auto refresh
  • Loading branch information
grouma committed Dec 19, 2014
2 parents 64b9d7f + 1fdf755 commit 591a3a3
Show file tree
Hide file tree
Showing 82 changed files with 1,682 additions and 1,456 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function (grunt) {
return 'plugins/' + dirname(fileName) + '/index';
});

config.bundledPluginModuleIds = grunt.bundledPluginModuleIds = moduleIds;
config.bundled_plugin_module_ids = grunt.bundled_plugin_module_ids = moduleIds;

// load plugins
require('load-grunt-config')(grunt, {
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Kibana is an open source (Apache Licensed), browser based analytics and search d
- Elasticsearch version 1.4.0 or later
- ...and nothing else

*Note:* Groovy scripting must be enabled in Elasticsearch

## Installation

* Download: [http://www.elasticsearch.org/overview/kibana/installation/](http://www.elasticsearch.org/overview/kibana/installation/)
Expand Down
28 changes: 21 additions & 7 deletions src/kibana/components/agg_types/buckets/geo_hash.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
define(function (require) {
return function GeoHashAggDefinition(Private) {
return function GeoHashAggDefinition(Private, config) {
var _ = require('lodash');
var moment = require('moment');
var AggType = Private(require('components/agg_types/_agg_type'));
var defaultPrecision = 3;

function getPrecision(precision) {
var maxPrecision = _.parseInt(config.get('visualization:tileMap:maxPrecision'));

precision = parseInt(precision, 10);

if (isNaN(precision)) {
precision = defaultPrecision;
}

if (precision > maxPrecision) {
return maxPrecision;
}

return precision;
}

return new AggType({
name: 'geohash_grid',
Expand All @@ -15,14 +32,11 @@ define(function (require) {
},
{
name: 'precision',
default: 3,
default: defaultPrecision,
editor: require('text!components/agg_types/controls/precision.html'),
deserialize: getPrecision,
write: function (aggConfig, output) {
var precision = parseInt(aggConfig.params.precision, 10);
if (isNaN(precision)) {
precision = 3;
}
output.params.precision = precision;
output.params.precision = getPrecision(aggConfig.params.precision);
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/controls/precision.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="form-control"
type="range"
min="1"
max="9"
max="{{config.get('visualization:tileMap:maxPrecision')}}"
>
<div class="form-group vis-editor-agg-form-value">
{{params.precision}}
Expand Down
10 changes: 5 additions & 5 deletions src/kibana/components/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ define(function (require) {
]);

var configFile = JSON.parse(require('text!config'));
configFile.elasticsearch = (
window.location.protocol + '//' +
window.location.hostname +
(window.location.port ? ':' + window.location.port : '') +
'/elasticsearch');
configFile.elasticsearch = (function () {
var a = document.createElement('a');
a.href = 'elasticsearch';
return a.href;
}());

// allow the rest of the app to get the configFile easily
module.constant('configFile', configFile);
Expand Down
4 changes: 4 additions & 0 deletions src/kibana/components/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ define(function (require) {
value: 100,
description: 'Never show more than this many bar in date histograms, scale values if needed',
},
'visualization:tileMap:maxPrecision': {
value: 6,
description: 'The maximum geoHash size allowed in a tile map',
},
'csv:separator': {
value: ',',
description: 'Separate exported values with this string',
Expand Down
10 changes: 0 additions & 10 deletions src/kibana/components/courier/_pending_requests.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/kibana/components/courier/_request_queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
define(function (require) {
return function PendingRequestList() {
var _ = require('lodash');

/**
* Queue of pending requests, requests are removed as
* they are processed by fetch.[sourceType]().
* @type {Array}
*/
var queue = window.requestQueue = [];

queue.getPending = function (/* strategies.. */) {
var strategies = _.toArray(arguments);
return queue.filter(function (req) {
var strategyMatch = !strategies.length;
if (!strategyMatch) {
strategyMatch = strategies.some(function (strategy) {
return req.strategy === strategy;
});
}

return strategyMatch && req.canStart();
});
};

return queue;
};
});
10 changes: 6 additions & 4 deletions src/kibana/components/courier/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ define(function (require) {
var DocSource = Private(require('components/courier/data_source/doc_source'));
var SearchSource = Private(require('components/courier/data_source/search_source'));

var pendingRequests = Private(require('components/courier/_pending_requests'));
var requestQueue = Private(require('components/courier/_request_queue'));
var errorHandlers = Private(require('components/courier/_error_handlers'));

var fetch = Private(require('components/courier/fetch/fetch'));
var docLooper = self.docLooper = Private(require('components/courier/looper/doc'));
var searchLooper = self.searchLooper = Private(require('components/courier/looper/search'));

Expand Down Expand Up @@ -57,7 +59,7 @@ define(function (require) {
* individual errors are routed to their respective requests.
*/
self.fetch = function () {
return searchLooper.run();
fetch.searches();
};


Expand Down Expand Up @@ -106,12 +108,12 @@ define(function (require) {
searchLooper.stop();
docLooper.stop();

[].concat(pendingRequests.splice(0), this._errorHandlers.splice(0))
[].concat(requestQueue.splice(0), errorHandlers.splice(0))
.forEach(function (req) {
req.defer.reject(new Abort());
});

if (pendingRequests.length) {
if (requestQueue.length) {
throw new Error('Aborting all pending requests failed.');
}
};
Expand Down
62 changes: 21 additions & 41 deletions src/kibana/components/courier/data_source/_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define(function (require) {
var nextTick = require('utils/next_tick');

return function SourceAbstractFactory(Private, Promise, PromiseEmitter, timefilter) {
var pendingRequests = Private(require('components/courier/_pending_requests'));
var requestQueue = Private(require('components/courier/_request_queue'));
var errorHandlers = Private(require('components/courier/_error_handlers'));
var courierFetch = Private(require('components/courier/fetch/fetch'));

Expand Down Expand Up @@ -123,8 +123,7 @@ define(function (require) {
var self = this;

return new PromiseEmitter(function (resolve, reject, defer) {
var req = self._createRequest(defer);
pendingRequests.push(req);
self._createRequest(defer);
}, handler);
};

Expand Down Expand Up @@ -155,20 +154,22 @@ define(function (require) {
/**
* Fetch just this source ASAP
*
* ONLY USE IF YOU NEED THE RESULTS OTHERWISE USE .fetchPending()
* TO TRIGGER FETCHING ALL PENDING REQUESTS
* ONLY USE IF YOU WILL BE USING THE RESULTS
* provided by the returned promise, otherwise
* call #fetchPending()
*
* @async
*/
SourceAbstract.prototype.fetch = function () {
var self = this;
var req = _.first(self._myPending());
var req = _.first(self._myPendingReq());

if (!req) {
req = self._createRequest();
pendingRequests.push(req);
}

self.fetchPending();
courierFetch.these([req]);

return req.defer.promise;
};

Expand All @@ -177,61 +178,35 @@ define(function (require) {
* @async
*/
SourceAbstract.prototype.fetchPending = function () {
return courierFetch.these(this._pullMyPending());
return courierFetch.these(this._myPendingReq());
};

/**
* Cancel all pending requests for this dataSource
* @return {undefined}
*/
SourceAbstract.prototype.cancelPending = function () {
this._pullMyPending();
SourceAbstract.prototype.cancelPendingReq = function () {
_.invoke(this._myPendingReq(), 'abort');
};

/**
* Completely destroy the SearchSource.
* @return {undefined}
*/
SourceAbstract.prototype.destroy = function () {
this.cancelPending();
this.cancelPendingReq();
};

/*****
* PRIVATE API
*****/

SourceAbstract.prototype._myPending = function () {
return _.where(pendingRequests, { source: this });
};

SourceAbstract.prototype._pullMyPending = function () {
var self = this;
return pendingRequests.splice(0).filter(function (req) {
if (req.source !== self) {
pendingRequests.push(req);
return false;
}
return true;
});
SourceAbstract.prototype._myPendingReq = function (includeStarted) {
return _.where(requestQueue.getPending(), { source: this });
};

SourceAbstract.prototype._createRequest = function (defer) {
var self = this;

var req = {
source: self,
defer: defer || Promise.defer(),
strategy: self._fetchStrategy
};

if (self.history) {
// latest history at the top
self.history.unshift(req);
// trim all entries beyond 19/20
self.history.splice(20);
}

return req;
throw new Error('_createRequest must be implemented by subclass');
};

/**
Expand Down Expand Up @@ -279,6 +254,8 @@ define(function (require) {
}())
.then(function () {
if (type === 'search') {
flatState.body = flatState.body || {};

// defaults for the query
if (!flatState.body.query) {
flatState.body.query = {
Expand All @@ -289,7 +266,10 @@ define(function (require) {
var computedFields = flatState.index.getComputedFields();
flatState.body.fields = computedFields.fields;
flatState.body.script_fields = flatState.body.script_fields || {};
flatState.body.fielddata_fields = flatState.body.fielddata_fields || [];

_.extend(flatState.body.script_fields, computedFields.scriptFields);
flatState.body.fielddata_fields = _.union(flatState.body.fielddata_fields, computedFields.fielddataFields);


/**
Expand Down
9 changes: 5 additions & 4 deletions src/kibana/components/courier/data_source/_doc_send_to_es.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ define(function (require) {
var errors = require('errors');

return function (Promise, Private, es) {
var pendingRequests = Private(require('components/courier/_pending_requests'));
var requestQueue = Private(require('components/courier/_request_queue'));
var docStrategy = Private(require('components/courier/fetch/strategy/doc'));

/**
* Backend for doUpdate and doIndex
Expand Down Expand Up @@ -44,18 +45,18 @@ define(function (require) {

// clear the queue and filter out the removed items, pushing the
// unmatched ones back in.
pendingRequests.splice(0).filter(function (req) {
requestQueue.splice(0).filter(function (req) {
var isDoc = req.source._getType() === 'doc';
var keyMatches = isDoc && req.source._versionKey() === key;

if (keyMatches) {
// resolve the request with a copy of the response
req.defer.resolve(_.cloneDeep(fetchResp));
req.handleResponse(_.cloneDeep(fetchResp));
return;
}

// otherwise, put the request back into the queue
pendingRequests.push(req);
requestQueue.push(req);
});
});

Expand Down
5 changes: 5 additions & 0 deletions src/kibana/components/courier/data_source/doc_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define(function (require) {
return function DocSourceFactory(Private, Promise, es, sessionStorage) {
var sendToEs = Private(require('components/courier/data_source/_doc_send_to_es'));
var SourceAbstract = Private(require('components/courier/data_source/_abstract'));
var DocRequest = Private(require('components/courier/fetch/request/doc'));

var VersionConflict = errors.VersionConflict;
var RequestFailure = errors.RequestFailure;
Expand All @@ -23,6 +24,10 @@ define(function (require) {
* PUBLIC API
*****/

DocSource.prototype._createRequest = function (defer) {
return new DocRequest(this, defer);
};

/**
* List of methods that is turned into a chainable API in the constructor
* @type {Array}
Expand Down
Loading

0 comments on commit 591a3a3

Please sign in to comment.