Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timepicker conf #3908

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/kibana/components/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,79 @@ define(function () {
'format:currency:defaultPattern': {
type: 'string',
value: '($0,0.[00])'
},
'timepicker:timeDefaults': {
type: 'json',
value: JSON.stringify({
from: 'now-15m',
to: 'now'
}, null, 2)
},
'timepicker:quickRanges': {
type: 'json',
value: JSON.stringify([
{ from: 'now/d', to: 'now/d', display: 'Today', section: 0 },
{ from: 'now/w', to: 'now/w', display: 'This week', section: 0 },
{ from: 'now/M', to: 'now/M', display: 'This month', section: 0 },
{ from: 'now/y', to: 'now/y', display: 'This year', section: 0 },
{ from: 'now/d', to: 'now', display: 'The day so far', section: 0 },
{ from: 'now/w', to: 'now', display: 'Week to date', section: 0 },
{ from: 'now/M', to: 'now', display: 'Month to date', section: 0 },
{ from: 'now/y', to: 'now', display: 'Year to date', section: 0 },

{ from: 'now-1d/d', to: 'now-1d/d', display: 'Yesterday', section: 1 },
{ from: 'now-2d/d', to: 'now-2d/d', display: 'Day before yesterday', section: 1 },
{ from: 'now-7d/d', to: 'now-7d/d', display: 'This day last week', section: 1 },
{ from: 'now-1w/w', to: 'now-1w/w', display: 'Previous week', section: 1 },
{ from: 'now-1M/M', to: 'now-1M/M', display: 'Previous month', section: 1 },
{ from: 'now-1y/y', to: 'now-1y/y', display: 'Previous year', section: 1 },

{ from: 'now-15m', to: 'now', display: 'Last 15 minutes', section: 2 },
{ from: 'now-30m', to: 'now', display: 'Last 30 minutes', section: 2 },
{ from: 'now-1h', to: 'now', display: 'Last 1 hour', section: 2 },
{ from: 'now-4h', to: 'now', display: 'Last 4 hours', section: 2 },
{ from: 'now-12h', to: 'now', display: 'Last 12 hours', section: 2 },
{ from: 'now-24h', to: 'now', display: 'Last 24 hours', section: 2 },
{ from: 'now-7d', to: 'now', display: 'Last 7 days', section: 2 },

{ from: 'now-30d', to: 'now', display: 'Last 30 days', section: 3 },
{ from: 'now-60d', to: 'now', display: 'Last 60 days', section: 3 },
{ from: 'now-90d', to: 'now', display: 'Last 90 days', section: 3 },
{ from: 'now-6M', to: 'now', display: 'Last 6 months', section: 3 },
{ from: 'now-1y', to: 'now', display: 'Last 1 year', section: 3 },
{ from: 'now-2y', to: 'now', display: 'Last 2 years', section: 3 },
{ from: 'now-5y', to: 'now', display: 'Last 5 years', section: 3 },
], null, 2)
},
'timepicker:refreshIntervalDefaults': {
type: 'json',
value: JSON.stringify({
display: 'Off',
pause: false,
section: 0,
value: 0
}, null, 2)
},
'timepicker:refreshIntervals': {
type: 'json',
value: JSON.stringify([
{ value : 0, display: 'Off', section: 0},

{ value : 5000, display: '5 seconds', section: 1},
{ value : 10000, display: '10 seconds', section: 1},
{ value : 30000, display: '30 seconds', section: 1},
{ value : 45000, display: '45 seconds', section: 1},

{ value : 60000, display: '1 minute', section: 2},
{ value : 300000, display: '5 minutes', section: 2},
{ value : 900000, display: '15 minutes', section: 2},
{ value : 1800000, display: '30 minutes', section: 2},

{ value : 3600000, display: '1 hour', section: 3},
{ value : 7200000, display: '2 hour', section: 3},
{ value : 43200000, display: '12 hour', section: 3},
{ value : 86400000, display: '1 day', section: 3}
], null, 2)
}
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/components/courier/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define(function (require) {

var DocSource = Private(require('components/courier/data_source/doc_source'));
var SearchSource = Private(require('components/courier/data_source/search_source'));
var searchStrategy = Private(require('components/courier/fetch/strategy/search'));

var requestQueue = Private(require('components/courier/_request_queue'));
var errorHandlers = Private(require('components/courier/_error_handlers'));
Expand Down Expand Up @@ -59,7 +60,7 @@ define(function (require) {
* individual errors are routed to their respective requests.
*/
self.fetch = function () {
fetch.searches().then(function () {
fetch.fetchQueued(searchStrategy).then(function () {
searchLooper.restart();
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/kibana/components/courier/data_source/_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(function (require) {
var errorHandlers = Private(require('components/courier/_error_handlers'));
var courierFetch = Private(require('components/courier/fetch/fetch'));

function SourceAbstract(initialState) {
function SourceAbstract(initialState, strategy) {
var self = this;
self._instanceid = _.uniqueId('data_source');

Expand Down Expand Up @@ -38,7 +38,7 @@ define(function (require) {
});

self.history = [];
self._fetchStrategy = courierFetch.strategies[self._getType()];
self._fetchStrategy = strategy;
}

/*****
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/components/courier/data_source/doc_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ define(function (require) {
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 docStrategy = Private(require('components/courier/fetch/strategy/doc'));

_(DocSource).inherits(SourceAbstract);
function DocSource(initialState) {
DocSource.Super.call(this, initialState);
DocSource.Super.call(this, initialState, docStrategy);
}

DocSource.prototype.onUpdate = SourceAbstract.prototype.onResults;
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/components/courier/data_source/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ define(function (require) {
var SourceAbstract = Private(require('components/courier/data_source/_abstract'));
var SearchRequest = Private(require('components/courier/fetch/request/search'));
var SegmentedRequest = Private(require('components/courier/fetch/request/segmented'));
var searchStrategy = Private(require('components/courier/fetch/strategy/search'));

_(SearchSource).inherits(SourceAbstract);
function SearchSource(initialState) {
SearchSource.Super.call(this, initialState);
SearchSource.Super.call(this, initialState, searchStrategy);
}

// expose a ready state for the route setup to read
Expand Down
21 changes: 2 additions & 19 deletions src/kibana/components/courier/fetch/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ define(function (require) {
return function fetchService(Private, Promise) {
var _ = require('lodash');

var strategies = this.strategies = {
doc: Private(require('components/courier/fetch/strategy/doc')),
search: Private(require('components/courier/fetch/strategy/search'))
};

var requestQueue = Private(require('components/courier/_request_queue'));
var fetchThese = Private(require('components/courier/fetch/_fetch_these'));

Expand All @@ -19,21 +14,9 @@ define(function (require) {
else return fetchThese(requests);
}

/**
* Fetch all pending docs that are ready to be fetched
* @async
*/
this.docs = _.partial(fetchQueued, strategies.doc);

/**
* Fetch all pending search requests
* @async
*/
this.searches = _.partial(fetchQueued, strategies.search);

this.fetchQueued = fetchQueued;

function fetchASource(source, strategy) {
strategy = strategy || strategies[source._getType()];
var defer = Promise.defer();

fetchThese([
Expand Down Expand Up @@ -89,4 +72,4 @@ define(function (require) {
});
};
};
});
});
5 changes: 3 additions & 2 deletions src/kibana/components/courier/looper/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ define(function (require) {
return function DocLooperService(Private) {
var fetch = Private(require('components/courier/fetch/fetch'));
var Looper = Private(require('components/courier/looper/_looper'));
var docStrategy = Private(require('components/courier/fetch/strategy/doc'));

/**
* The Looper which will manage the doc fetch interval
* @type {Looper}
*/
var docLooper = new Looper(1500, function () {
fetch.docs();
fetch.fetchQueued(docStrategy);
});

return docLooper;
};
});
});
2 changes: 1 addition & 1 deletion src/kibana/components/courier/looper/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ define(function (require) {

return searchLooper;
};
});
});
47 changes: 22 additions & 25 deletions src/kibana/components/timefilter/timefilter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
define(function (require) {
require('modules')
.get('kibana')
.service('timefilter', function (Private, globalState, $rootScope) {
.service('timefilter', function (Private, globalState, $rootScope, config) {

var _ = require('lodash');
var angular = require('angular');
Expand All @@ -27,35 +27,32 @@

self.enabled = false;

var timeDefaults = {
from: 'now-15m',
to: 'now'
};
initConfig();
$rootScope.$on('init:config', initConfig);

var refreshIntervalDefaults = {
display: 'Off',
pause: false,
section: 0,
value: 0
};
function initConfig() {
var timeDefaults = config.get('timepicker:timeDefaults');

// These can be date math strings or moments.
self.time = _.defaults(globalState.time || {}, timeDefaults);
self.refreshInterval = _.defaults(globalState.refreshInterval || {}, refreshIntervalDefaults);
var refreshIntervalDefaults = config.get('timepicker:refreshIntervalDefaults');

globalState.on('fetch_with_changes', function () {
// clone and default to {} in one
var newTime = _.defaults({}, globalState.time, timeDefaults);
var newRefreshInterval = _.defaults({}, globalState.refreshInterval, refreshIntervalDefaults);
// These can be date math strings or moments.
self.time = _.defaults(globalState.time || {}, timeDefaults);
self.refreshInterval = _.defaults(globalState.refreshInterval || {}, refreshIntervalDefaults);

if (newTime) {
if (newTime.to) newTime.to = convertISO8601(newTime.to);
if (newTime.from) newTime.from = convertISO8601(newTime.from);
}
globalState.on('fetch_with_changes', function () {
// clone and default to {} in one
var newTime = _.defaults({}, globalState.time, timeDefaults);
var newRefreshInterval = _.defaults({}, globalState.refreshInterval, refreshIntervalDefaults);

self.time = newTime;
self.refreshInterval = newRefreshInterval;
});
if (newTime) {
if (newTime.to) newTime.to = convertISO8601(newTime.to);
if (newTime.from) newTime.from = convertISO8601(newTime.from);
}

self.time = newTime;
self.refreshInterval = newRefreshInterval;
});
}

$rootScope.$$timefilter = self;

Expand Down
39 changes: 0 additions & 39 deletions src/kibana/components/timepicker/quick_ranges.js

This file was deleted.

23 changes: 0 additions & 23 deletions src/kibana/components/timepicker/refresh_intervals.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/kibana/components/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ define(function (require) {

require('directives/input_datetime');
require('directives/inequality');
require('components/timepicker/quick_ranges');
require('components/timepicker/refresh_intervals');
require('components/timepicker/time_units');

module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals) {
module.directive('kbnTimepicker', function (config, timeUnits) {
return {
restrict: 'E',
scope: {
Expand All @@ -22,7 +20,7 @@ define(function (require) {
activeTab: '='
},
template: html,
controller: function ($scope) {
controller: function ($scope, $element) {
var init = function () {
$scope.setMode($scope.mode);
};
Expand All @@ -33,7 +31,9 @@ define(function (require) {

if (_.isUndefined($scope.mode)) $scope.mode = 'quick';

var quickRanges = config.get('timepicker:quickRanges');
$scope.quickLists = _(quickRanges).groupBy('section').values().value();
var refreshIntervals = config.get('timepicker:refreshIntervals');
$scope.refreshLists = _(refreshIntervals).groupBy('section').values().value();

$scope.relative = {
Expand Down
7 changes: 4 additions & 3 deletions src/kibana/directives/pretty_duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ define(function (require) {
var datemath = require('utils/datemath');
var moment = require('moment');

require('components/timepicker/quick_ranges');
require('components/timepicker/time_units');

module.directive('prettyDuration', function (config, quickRanges, timeUnits) {
module.directive('prettyDuration', function (config, timeUnits) {
return {
restrict: 'E',
scope: {
Expand All @@ -18,6 +17,8 @@ define(function (require) {
var dateFormat = config.get('dateFormat');

var lookupByRange = {};

var quickRanges = config.get('timepicker:quickRanges');
_.each(quickRanges, function (frame) {
lookupByRange[frame.from + ' to ' + frame.to] = frame;
});
Expand Down Expand Up @@ -72,4 +73,4 @@ define(function (require) {
};
});

});
});