Merge pull request #6759 from bevacqua/feature/config-switch-dow

Added advanced setting to tweak starting day of week
This commit is contained in:
Spencer 2016-04-20 19:57:52 -05:00
commit 40b2645db9
5 changed files with 34 additions and 25 deletions

View file

@ -11,6 +11,7 @@ compatible with other configuration settings. Deleting a custom setting removes
`dateFormat`:: The format to use for displaying pretty-formatted dates. `dateFormat`:: The format to use for displaying pretty-formatted dates.
`dateFormat:tz`:: The timezone that Kibana uses. The default value of `Browser` uses the timezone detected by the browser. `dateFormat:tz`:: The timezone that Kibana uses. The default value of `Browser` uses the timezone detected by the browser.
`dateFormat:scaled`:: These values define the format used to render ordered time-based data. Formatted timestamps must `dateFormat:scaled`:: These values define the format used to render ordered time-based data. Formatted timestamps must
`dateFormat:dow`:: This property defines what day weeks should start on.
adapt to the interval between measurements. Keys are http://en.wikipedia.org/wiki/ISO_8601#Time_intervals[ISO8601 intervals]. adapt to the interval between measurements. Keys are http://en.wikipedia.org/wiki/ISO_8601#Time_intervals[ISO8601 intervals].
`defaultIndex`:: Default is `null`. This property specifies the default index. `defaultIndex`:: Default is `null`. This property specifies the default index.
`metaFields`:: An array of fields outside of `_source`. Kibana merges these fields into the document when displaying the `metaFields`:: An array of fields outside of `_source`. Kibana merges these fields into the document when displaying the

View file

@ -2,8 +2,10 @@ import moment from 'moment-timezone';
import _ from 'lodash'; import _ from 'lodash';
export default function configDefaultsProvider() { export default function configDefaultsProvider() {
// wrapped in provider so that a new instance is given to each app/test const weekdays = moment.weekdays().slice();
const [defaultWeekday] = weekdays;
// wrapped in provider so that a new instance is given to each app/test
return { return {
'buildNum': { 'buildNum': {
readonly: true readonly: true
@ -46,6 +48,12 @@ export default function configDefaultsProvider() {
' <a href="http://en.wikipedia.org/wiki/ISO_8601#Time_intervals" target="_blank">' + ' <a href="http://en.wikipedia.org/wiki/ISO_8601#Time_intervals" target="_blank">' +
'ISO8601 intervals.</a>' 'ISO8601 intervals.</a>'
}, },
'dateFormat:dow': {
value: defaultWeekday,
description: 'What day should weeks start on?',
type: 'select',
options: weekdays
},
'defaultIndex': { 'defaultIndex': {
value: null, value: null,
description: 'The index to access if no index is set', description: 'The index to access if no index is set',

View file

@ -19,11 +19,9 @@ uiRoutes
uiModules uiModules
.get('kibana') .get('kibana')
.service('timefilter', function (Private, globalState, $rootScope, config) { .service('timefilter', function (Private, globalState, $rootScope, config) {
let Events = Private(EventsProvider); let Events = Private(EventsProvider);
let diff = Private(UtilsDiffTimePickerValsProvider); let diff = Private(UtilsDiffTimePickerValsProvider);
function convertISO8601(stringTime) { function convertISO8601(stringTime) {
let obj = moment(stringTime, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true); let obj = moment(stringTime, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true);
return obj.isValid() ? obj : stringTime; return obj.isValid() ? obj : stringTime;

View file

@ -1,3 +1,4 @@
import moment from 'moment';
import UiModules from 'ui/modules'; import UiModules from 'ui/modules';
import chromeNavControlsRegistry from 'ui/registry/chrome_nav_controls'; import chromeNavControlsRegistry from 'ui/registry/chrome_nav_controls';
import { once, clone } from 'lodash'; import { once, clone } from 'lodash';
@ -6,7 +7,7 @@ import toggleHtml from './kbn_global_timepicker.html';
UiModules UiModules
.get('kibana') .get('kibana')
.directive('kbnGlobalTimepicker', (timefilter, globalState, $rootScope) => { .directive('kbnGlobalTimepicker', (timefilter, globalState, $rootScope, config) => {
const listenForUpdates = once($scope => { const listenForUpdates = once($scope => {
$scope.$listen(timefilter, 'update', (newVal, oldVal) => { $scope.$listen(timefilter, 'update', (newVal, oldVal) => {
globalState.time = clone(timefilter.time); globalState.time = clone(timefilter.time);
@ -18,6 +19,12 @@ UiModules
return { return {
template: toggleHtml, template: toggleHtml,
link: ($scope, $el, attrs) => { link: ($scope, $el, attrs) => {
config.$bind($scope, 'dateFormat:dow', 'dateFormat_dow');
$scope.$watch('dateFormat_dow', function (day) {
const dow = moment.weekdays().indexOf(day);
moment.locale(moment.locale(), { week: { dow } });
});
listenForUpdates($rootScope); listenForUpdates($rootScope);
$rootScope.timefilter = timefilter; $rootScope.timefilter = timefilter;

View file

@ -15,7 +15,6 @@ let notify = new Notifier({
location: 'timepicker', location: 'timepicker',
}); });
module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals) { module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals) {
return { return {
restrict: 'E', restrict: 'E',
@ -28,10 +27,6 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter
}, },
template: html, template: html,
controller: function ($scope) { controller: function ($scope) {
let init = function () {
$scope.setMode($scope.mode);
};
$scope.format = 'MMMM Do YYYY, HH:mm:ss.SSS'; $scope.format = 'MMMM Do YYYY, HH:mm:ss.SSS';
$scope.modes = ['quick', 'relative', 'absolute']; $scope.modes = ['quick', 'relative', 'absolute'];
$scope.activeTab = $scope.activeTab || 'filter'; $scope.activeTab = $scope.activeTab || 'filter';
@ -115,7 +110,7 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter
$scope.mode = thisMode; $scope.mode = thisMode;
}; };
$scope.setQuick = function (from, to, description) { $scope.setQuick = function (from, to) {
$scope.from = from; $scope.from = from;
$scope.to = to; $scope.to = to;
}; };
@ -154,7 +149,7 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter
$scope.interval = interval; $scope.interval = interval;
}; };
init(); $scope.setMode($scope.mode);
} }
}; };
}); });