Move timezone settings into autoload file (#22623) (#22706)

* Move timezone settings into autoload file

* Remove applying setting from timelion

* Remove manual set from ML

* Remove manual set from monitoring

* Remove now obsolete code from embedding test plugin
This commit is contained in:
Tim Roes 2018-09-05 12:03:59 +02:00 committed by GitHub
parent 242afa77c4
commit 46709c62b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 52 additions and 84 deletions

View file

@ -59,7 +59,6 @@ import 'ui/agg_types';
import 'ui/timepicker';
import { showAppRedirectNotification } from 'ui/notify';
import 'leaflet';
import { KibanaRootController } from './kibana_root_controller';
routes.enable();
@ -68,6 +67,4 @@ routes
redirectTo: `/${chrome.getInjected('kbnDefaultAppId', 'discover')}`
});
chrome.setRootController('kibana', KibanaRootController);
uiModules.get('kibana').run(showAppRedirectNotification);

View file

@ -1,34 +0,0 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import moment from 'moment-timezone';
export function KibanaRootController($scope, courier, config) {
config.watch('dateFormat:tz', setDefaultTimezone, $scope);
config.watch('dateFormat:dow', setStartDayOfWeek, $scope);
function setDefaultTimezone(tz) {
moment.tz.setDefault(tz);
}
function setStartDayOfWeek(day) {
const dow = moment.weekdays().indexOf(day);
moment.updateLocale(moment.locale(), { week: { dow } });
}
}

View file

@ -18,7 +18,6 @@
*/
import _ from 'lodash';
import moment from 'moment-timezone';
import { DocTitleProvider } from 'ui/doc_title';
import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry';
@ -101,9 +100,6 @@ app.controller('timelion', function (
$scope.page = config.get('timelion:showTutorial', true) ? 1 : 0;
$scope.setPage = (page) => $scope.page = page;
// TODO: For some reason the Kibana core doesn't correctly do this for all apps.
moment.tz.setDefault(config.get('dateFormat:tz'));
timefilter.enableAutoRefreshSelector();
timefilter.enableTimeRangeSelector();

View file

@ -21,4 +21,5 @@ import './accessibility';
import './modules';
import './directives';
import './filters';
import './settings';
import './styles';

View file

@ -0,0 +1,50 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Autoload this file if we want some of the top level settings applied to a plugin.
* Currently this file makes sure the following settings are applied globally:
* - dateFormat:tz (meaning the Kibana time zone will be used in your plugin)
* - dateFormat:dow (meaning the Kibana configured start of the week will be used in your plugin)
*/
import moment from 'moment-timezone';
import chrome from '../chrome';
function setDefaultTimezone(tz) {
moment.tz.setDefault(tz);
}
function setStartDayOfWeek(day) {
const dow = moment.weekdays().indexOf(day);
moment.updateLocale(moment.locale(), { week: { dow } });
}
const uiSettings = chrome.getUiSettingsClient();
setDefaultTimezone(uiSettings.get('dateFormat:tz'));
setStartDayOfWeek(uiSettings.get('dateFormat:dow'));
uiSettings.subscribe(({ key, newValue }) => {
if (key === 'dateFormat:tz') {
setDefaultTimezone(newValue);
} else if (key === 'dateFormat:dow') {
setStartDayOfWeek(newValue);
}
});

View file

@ -37,34 +37,6 @@ import 'uiExports/savedObjectTypes';
import 'uiExports/fieldFormats';
import 'uiExports/search';
// ----------- TODO Remove once https://github.com/elastic/kibana/pull/22623 is merged
import moment from 'moment-timezone';
function setDefaultTimezone(tz) {
moment.tz.setDefault(tz);
}
function setStartDayOfWeek(day) {
const dow = moment.weekdays().indexOf(day);
moment.updateLocale(moment.locale(), { week: { dow } });
}
const uiSettings = chrome.getUiSettingsClient();
setDefaultTimezone(uiSettings.get('dateFormat:tz'));
setStartDayOfWeek(uiSettings.get('dateFormat:dow'));
uiSettings.subscribe(({ key, newValue }) => {
if (key === 'dateFormat:tz') {
setDefaultTimezone(newValue);
} else if (key === 'dateFormat:dow') {
setStartDayOfWeek(newValue);
}
});
// ----------------- END OF REMOVAL ----------
import { Main } from './components/main';
const app = uiModules.get('apps/firewallDemoPlugin', ['kibana']);

View file

@ -37,7 +37,6 @@ import 'leaflet';
import { showAppRedirectNotification } from 'ui/notify';
import { DashboardConstants, createDashboardEditUrl } from 'plugins/kibana/dashboard/dashboard_constants';
import { KibanaRootController } from 'plugins/kibana/kibana_root_controller';
uiModules.get('kibana')
.config(dashboardConfigProvider => dashboardConfigProvider.turnHideWriteControlsOn());
@ -46,9 +45,8 @@ routes.enable();
routes.otherwise({ redirectTo: defaultUrl() });
chrome
.setRootController('kibana', function ($controller, $scope, courier, config) {
.setRootController('kibana', function () {
chrome.showOnlyById('kibana:dashboard');
$controller(KibanaRootController, { $scope, courier, config });
});
uiModules.get('kibana').run(showAppRedirectNotification);

View file

@ -34,14 +34,6 @@ import 'plugins/ml/components/loading_indicator';
import 'plugins/ml/settings';
import uiRoutes from 'ui/routes';
import moment from 'moment-timezone';
import { uiModules } from 'ui/modules';
const uiModule = uiModules.get('kibana');
uiModule.run((config) => {
// Set the timezone for moment formatting to that configured in Kibana.
moment.tz.setDefault(config.get('dateFormat:tz'));
});
if (typeof uiRoutes.enable === 'function') {
uiRoutes.enable();

View file

@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import moment from 'moment-timezone';
import uiRoutes from 'ui/routes';
import chrome from 'ui/chrome';
import 'ui/autoload/all';
@ -20,9 +19,6 @@ import 'plugins/monitoring/views/all';
const uiSettings = chrome.getUiSettingsClient();
// Allow UTC times to be entered for Absolute Time range in timepicker
moment.tz.setDefault(uiSettings.get('dateFormat:tz'));
// default timepicker default to the last hour
uiSettings.overrideLocalDefault('timepicker:timeDefaults', JSON.stringify({
from: 'now-1h',