diff --git a/src/core_plugins/kibana/public/kibana.js b/src/core_plugins/kibana/public/kibana.js index 522b6b70870257..984706556800d6 100644 --- a/src/core_plugins/kibana/public/kibana.js +++ b/src/core_plugins/kibana/public/kibana.js @@ -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); diff --git a/src/core_plugins/kibana/public/kibana_root_controller.js b/src/core_plugins/kibana/public/kibana_root_controller.js deleted file mode 100644 index 830cd0bd16c7b9..00000000000000 --- a/src/core_plugins/kibana/public/kibana_root_controller.js +++ /dev/null @@ -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 } }); - } -} diff --git a/src/core_plugins/timelion/public/app.js b/src/core_plugins/timelion/public/app.js index ffadf7c9cdb1bc..316a9704b5c3d3 100644 --- a/src/core_plugins/timelion/public/app.js +++ b/src/core_plugins/timelion/public/app.js @@ -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(); diff --git a/src/ui/public/autoload/all.js b/src/ui/public/autoload/all.js index fba21aacd19848..b1aa11cb724946 100644 --- a/src/ui/public/autoload/all.js +++ b/src/ui/public/autoload/all.js @@ -21,4 +21,5 @@ import './accessibility'; import './modules'; import './directives'; import './filters'; +import './settings'; import './styles'; diff --git a/src/ui/public/autoload/settings.js b/src/ui/public/autoload/settings.js new file mode 100644 index 00000000000000..48505037dffe4c --- /dev/null +++ b/src/ui/public/autoload/settings.js @@ -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); + } +}); diff --git a/test/plugin_functional/plugins/visualize_embedding/public/app.js b/test/plugin_functional/plugins/visualize_embedding/public/app.js index 3f622c946a1159..4463feac27513d 100644 --- a/test/plugin_functional/plugins/visualize_embedding/public/app.js +++ b/test/plugin_functional/plugins/visualize_embedding/public/app.js @@ -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']); diff --git a/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js b/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js index ef2929f2ab2ff3..2b6997742280cc 100644 --- a/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js +++ b/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js @@ -38,7 +38,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()); @@ -47,9 +46,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); diff --git a/x-pack/plugins/ml/public/app.js b/x-pack/plugins/ml/public/app.js index ba1d17bdd9b8d8..ad76c56cfdf198 100644 --- a/x-pack/plugins/ml/public/app.js +++ b/x-pack/plugins/ml/public/app.js @@ -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(); diff --git a/x-pack/plugins/monitoring/public/monitoring.js b/x-pack/plugins/monitoring/public/monitoring.js index f564848d02c902..0e4528ba679c3b 100644 --- a/x-pack/plugins/monitoring/public/monitoring.js +++ b/x-pack/plugins/monitoring/public/monitoring.js @@ -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',