From 7740d6edd9080c5275a970d84c4f7372a690ed60 Mon Sep 17 00:00:00 2001 From: Nicolas Bevacqua Date: Mon, 4 Apr 2016 16:23:46 -0300 Subject: [PATCH 1/3] [ui] Added advanced setting to tweak starting day of week. Fixes #1855. --- docs/advanced-settings.asciidoc | 29 +++++++++++++------------- src/ui/public/config/defaults.js | 10 ++++++++- src/ui/public/timepicker/timepicker.js | 10 ++++++++- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/docs/advanced-settings.asciidoc b/docs/advanced-settings.asciidoc index eb599be309ad..8314cb458493 100644 --- a/docs/advanced-settings.asciidoc +++ b/docs/advanced-settings.asciidoc @@ -1,7 +1,7 @@ [[kibana-settings-reference]] -WARNING: Modifying the following settings can signficantly affect Kibana's performance and cause problems that are -difficult to diagnose. Setting a property's value to a blank field will revert to the default behavior, which may not be +WARNING: Modifying the following settings can signficantly affect Kibana's performance and cause problems that are +difficult to diagnose. Setting a property's value to a blank field will revert to the default behavior, which may not be compatible with other configuration settings. Deleting a custom setting removes it from Kibana permanently. .Kibana Settings Reference @@ -10,37 +10,38 @@ compatible with other configuration settings. Deleting a custom setting removes `sort:options`:: Options for the Elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html[sort] parameter. `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: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]. `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 document. `discover:sampleSize`:: The number of rows to show in the Discover table. -`doc_table:highlight`:: Highlight results in Discover and Saved Searches Dashboard. Highlighing makes request slow when +`doc_table:highlight`:: Highlight results in Discover and Saved Searches Dashboard. Highlighing makes request slow when working on big documents. Set this property to `false` to disable highlighting. -`courier:maxSegmentCount`:: Kibana splits requests in the Discover app into segments to limit the size of requests sent to -the Elasticsearch cluster. This setting constrains the length of the segment list. Long segment lists can significantly +`courier:maxSegmentCount`:: Kibana splits requests in the Discover app into segments to limit the size of requests sent to +the Elasticsearch cluster. This setting constrains the length of the segment list. Long segment lists can significantly increase request processing time. `fields:popularLimit`:: This setting governs how many of the top most popular fields are shown. `histogram:barTarget`:: When date histograms use the `auto` interval, Kibana attempts to generate this number of bars. -`histogram:maxBars`:: Date histograms are not generated with more bars than the value of this property, scaling values +`histogram:maxBars`:: Date histograms are not generated with more bars than the value of this property, scaling values when necessary. -`visualization:tileMap:maxPrecision`:: The maximum geoHash precision displayed on tile maps: 7 is high, 10 is very high, +`visualization:tileMap:maxPrecision`:: The maximum geoHash precision displayed on tile maps: 7 is high, 10 is very high, 12 is the maximum. http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html#_cell_dimensions_at_the_equator[Explanation of cell dimensions]. `visualization:tileMap:WMSdefaults`:: Default properties for the WMS map server support in the tile map. `visualization:colorMapping`:: Maps values to specified colors within visualizations. `visualization:loadingDelay`:: Time to wait before dimming visualizations during query. `csv:separator`:: A string that serves as the separator for exported values. `csv:quoteValues`:: Set this property to `true` to quote exported values. -`history:limit`:: In fields that have history, such as query inputs, the value of this property limits how many recent +`history:limit`:: In fields that have history, such as query inputs, the value of this property limits how many recent values are shown. -`shortDots:enable`:: Set this property to `true` to shorten long field names in visualizations. For example, instead of +`shortDots:enable`:: Set this property to `true` to shorten long field names in visualizations. For example, instead of `foo.bar.baz`, show `f.b.baz`. -`truncate:maxHeight`:: This property specifies the maximum height that a cell occupies in a table. A value of 0 disables +`truncate:maxHeight`:: This property specifies the maximum height that a cell occupies in a table. A value of 0 disables truncation. -`indexPattern:fieldMapping:lookBack`:: The value of this property sets the number of recent matching patterns to query the +`indexPattern:fieldMapping:lookBack`:: The value of this property sets the number of recent matching patterns to query the field mapping for index patterns with names that contain timestamps. -`format:defaultTypeMap`:: A map of the default format name for each field type. Field types that are not explicitly +`format:defaultTypeMap`:: A map of the default format name for each field type. Field types that are not explicitly mentioned use "_default_". `format:number:defaultPattern`:: Default numeral format for the "number" format. `format:bytes:defaultPattern`:: Default numeral format for the "bytes" format. diff --git a/src/ui/public/config/defaults.js b/src/ui/public/config/defaults.js index e5c3590653d4..adf14779fbfc 100644 --- a/src/ui/public/config/defaults.js +++ b/src/ui/public/config/defaults.js @@ -2,8 +2,10 @@ import moment from 'moment-timezone'; import _ from 'lodash'; 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 { 'buildNum': { readonly: true @@ -46,6 +48,12 @@ export default function configDefaultsProvider() { ' ' + 'ISO8601 intervals.' }, + 'dateFormat:dow': { + value: defaultWeekday, + description: 'What day should weeks start on?', + type: 'select', + options: weekdays + }, 'defaultIndex': { value: null, description: 'The index to access if no index is set', diff --git a/src/ui/public/timepicker/timepicker.js b/src/ui/public/timepicker/timepicker.js index ea5e9c174ffd..43f7b6160178 100644 --- a/src/ui/public/timepicker/timepicker.js +++ b/src/ui/public/timepicker/timepicker.js @@ -16,7 +16,7 @@ var notify = new Notifier({ }); -module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals) { +module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals, config) { return { restrict: 'E', scope: { @@ -155,6 +155,14 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter }; init(); + }, + link: function ($scope) { + 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 } }); + }); } }; }); From 6492320b82d03d8aa20226d0ebc84769a510963b Mon Sep 17 00:00:00 2001 From: Nicolas Bevacqua Date: Fri, 8 Apr 2016 14:15:37 -0300 Subject: [PATCH 2/3] [fix] Move start of week formatting to service so it's immediately applied. --- src/ui/public/timefilter/timefilter.js | 6 ++++++ src/ui/public/timepicker/timepicker.js | 18 +++--------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/ui/public/timefilter/timefilter.js b/src/ui/public/timefilter/timefilter.js index 55da9e55a992..b0403b7885c9 100644 --- a/src/ui/public/timefilter/timefilter.js +++ b/src/ui/public/timefilter/timefilter.js @@ -23,6 +23,12 @@ uiModules var Events = Private(EventsProvider); var diff = Private(UtilsDiffTimePickerValsProvider); + config.$bind($rootScope, 'dateFormat:dow', 'dateFormat_dow'); + + $rootScope.$watch('dateFormat_dow', function (day) { + const dow = moment.weekdays().indexOf(day); + moment.locale(moment.locale(), { week: { dow } }); + }); function convertISO8601(stringTime) { var obj = moment(stringTime, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true); diff --git a/src/ui/public/timepicker/timepicker.js b/src/ui/public/timepicker/timepicker.js index 43f7b6160178..0b61a75d176a 100644 --- a/src/ui/public/timepicker/timepicker.js +++ b/src/ui/public/timepicker/timepicker.js @@ -16,7 +16,7 @@ var notify = new Notifier({ }); -module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals, config) { +module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals) { return { restrict: 'E', scope: { @@ -28,10 +28,6 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter }, template: html, controller: function ($scope) { - var init = function () { - $scope.setMode($scope.mode); - }; - $scope.format = 'MMMM Do YYYY, HH:mm:ss.SSS'; $scope.modes = ['quick', 'relative', 'absolute']; $scope.activeTab = $scope.activeTab || 'filter'; @@ -115,7 +111,7 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter $scope.mode = thisMode; }; - $scope.setQuick = function (from, to, description) { + $scope.setQuick = function (from, to) { $scope.from = from; $scope.to = to; }; @@ -154,15 +150,7 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter $scope.interval = interval; }; - init(); - }, - link: function ($scope) { - 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 } }); - }); + $scope.setMode($scope.mode); } }; }); From 5e2911290b914402b36b8b07b18c24befbe21064 Mon Sep 17 00:00:00 2001 From: Nicolas Bevacqua Date: Mon, 18 Apr 2016 23:39:24 -0300 Subject: [PATCH 3/3] [refactor] Moved global moment locale update to kbnGlobalTimepicker directive. --- src/ui/public/timefilter/timefilter.js | 8 -------- src/ui/public/timepicker/kbn_global_timepicker.js | 9 ++++++++- src/ui/public/timepicker/timepicker.js | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ui/public/timefilter/timefilter.js b/src/ui/public/timefilter/timefilter.js index 34de9d26237c..f362ec3e2597 100644 --- a/src/ui/public/timefilter/timefilter.js +++ b/src/ui/public/timefilter/timefilter.js @@ -19,17 +19,9 @@ uiRoutes uiModules .get('kibana') .service('timefilter', function (Private, globalState, $rootScope, config) { - let Events = Private(EventsProvider); let diff = Private(UtilsDiffTimePickerValsProvider); - config.$bind($rootScope, 'dateFormat:dow', 'dateFormat_dow'); - - $rootScope.$watch('dateFormat_dow', function (day) { - const dow = moment.weekdays().indexOf(day); - moment.locale(moment.locale(), { week: { dow } }); - }); - function convertISO8601(stringTime) { let obj = moment(stringTime, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true); return obj.isValid() ? obj : stringTime; diff --git a/src/ui/public/timepicker/kbn_global_timepicker.js b/src/ui/public/timepicker/kbn_global_timepicker.js index 33ff002ea1d1..8e0912d88793 100644 --- a/src/ui/public/timepicker/kbn_global_timepicker.js +++ b/src/ui/public/timepicker/kbn_global_timepicker.js @@ -1,3 +1,4 @@ +import moment from 'moment'; import UiModules from 'ui/modules'; import chromeNavControlsRegistry from 'ui/registry/chrome_nav_controls'; import { once, clone } from 'lodash'; @@ -6,7 +7,7 @@ import toggleHtml from './kbn_global_timepicker.html'; UiModules .get('kibana') -.directive('kbnGlobalTimepicker', (timefilter, globalState, $rootScope) => { +.directive('kbnGlobalTimepicker', (timefilter, globalState, $rootScope, config) => { const listenForUpdates = once($scope => { $scope.$listen(timefilter, 'update', (newVal, oldVal) => { globalState.time = clone(timefilter.time); @@ -18,6 +19,12 @@ UiModules return { template: toggleHtml, 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); $rootScope.timefilter = timefilter; diff --git a/src/ui/public/timepicker/timepicker.js b/src/ui/public/timepicker/timepicker.js index 77823bdf7acc..3567455f41ac 100644 --- a/src/ui/public/timepicker/timepicker.js +++ b/src/ui/public/timepicker/timepicker.js @@ -15,7 +15,6 @@ let notify = new Notifier({ location: 'timepicker', }); - module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals) { return { restrict: 'E',