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

use refreshIntervalDefaults from config #3977

Closed
wants to merge 5 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
24 changes: 18 additions & 6 deletions src/kibana/components/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,24 @@ define(function () {
},
'timepicker:timeDefaults': {
type: 'json',
value: JSON.stringify({
from: 'now-15m',
to: 'now',
mode: 'quick'
}, null, 2)
value: [
'{',
' "from": "now-15m",',
' "to": "now",',
' "mode": "quick"',
'}'
].join('\n')
},
'timepicker:refreshIntervalDefaults': {
type: 'json',
value: [
'{',
' "display": "Off",',
' "pause": false,',
' "value": 0',
'}'
].join('\n')
}
};
};
});
});
41 changes: 21 additions & 20 deletions src/kibana/components/timefilter/timefilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@

self.enabled = false;

var timeDefaults = config.get('timepicker:timeDefaults');
self.init = _.once(function () {
return config.init()
.then(self.consumeDefaults);
});

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

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

if (newTime) {
if (newTime.to) newTime.to = convertISO8601(newTime.to);
if (newTime.from) newTime.from = convertISO8601(newTime.from);
}
if (newTime) {
if (newTime.to) newTime.to = convertISO8601(newTime.to);
if (newTime.from) newTime.from = convertISO8601(newTime.from);
}

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

$rootScope.$$timefilter = self;
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/utils/routes/_setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(function (require) {
return function routeSetup(Promise, kbnSetup, config, $route, kbnUrl, courier, Notifier, Private, $rootScope) {
return function routeSetup(Promise, kbnSetup, config, $route, kbnUrl, courier, Notifier, Private, $rootScope, timefilter) {
var _ = require('lodash');
var errors = require('errors');
var NoDefaultIndexPattern = errors.NoDefaultIndexPattern;
Expand All @@ -15,6 +15,7 @@ define(function (require) {
return Promise.all([
kbnSetup(),
config.init(),
timefilter.init(),
courier.SearchSource.ready,
$rootScope.kibana && $rootScope.kibana.ready
])
Expand Down
23 changes: 17 additions & 6 deletions test/unit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,28 @@
}

function loadSpecs(specListJson) {
var deps = JSON.parse(specListJson);
deps.unshift('sinon/sinon');
deps.unshift('kibana');

var specs = JSON.parse(specListJson);
sessionStorage.clear();
localStorage.clear();

require(deps, bootstrap);
require(
[
'kibana',
'sinon/sinon',
'modules'
].concat(specs),
bootstrap
);
}

function bootstrap(kibana, sinon) {
function bootstrap(kibana, sinon, modules) {
modules.get('kibana').config(function ($provide) {
$provide.decorator('timefilter', function ($delegate) {
$delegate.consumeDefaults();
return $delegate;
});
});

kibana.load(function () {
var xhr = sinon.useFakeXMLHttpRequest();

Expand Down