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

Move timezone settings into autoload file #22623

Merged
merged 6 commits into from
Sep 5, 2018
Merged
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
3 changes: 0 additions & 3 deletions src/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -68,6 +67,4 @@ routes
redirectTo: `/${chrome.getInjected('kbnDefaultAppId', 'discover')}`
});

chrome.setRootController('kibana', KibanaRootController);

uiModules.get('kibana').run(showAppRedirectNotification);
34 changes: 0 additions & 34 deletions src/core_plugins/kibana/public/kibana_root_controller.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/core_plugins/timelion/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/ui/public/autoload/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ import './accessibility';
import './modules';
import './directives';
import './filters';
import './settings';
import './styles';
50 changes: 50 additions & 0 deletions src/ui/public/autoload/settings.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
28 changes: 0 additions & 28 deletions test/plugin_functional/plugins/visualize_embedding/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/dashboard_mode/public/dashboard_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions x-pack/plugins/ml/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/monitoring/public/monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand 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',
Expand Down