-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3640 from spalger/bindconfigvars
[config] added simple $bind helper
- Loading branch information
Showing
7 changed files
with
196 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,93 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
return function () { | ||
var _ = require('lodash'); | ||
|
||
return { | ||
'query:queryString:options': { | ||
value: '{ "analyze_wildcard": true }', | ||
description: 'Options for the lucene query string parser', | ||
type: 'json' | ||
}, | ||
'dateFormat': { | ||
value: 'MMMM Do YYYY, HH:mm:ss.SSS', | ||
description: 'When displaying a pretty formatted date, use this format', | ||
}, | ||
'dateFormat:scaled': { | ||
type: 'json', | ||
value: | ||
'[\n' + | ||
' ["", "hh:mm:ss.SSS"],\n' + | ||
' ["PT1S", "HH:mm:ss"],\n' + | ||
' ["PT1M", "HH:mm"],\n' + | ||
' ["PT1H",\n' + | ||
' "YYYY-MM-DD HH:mm"],\n' + | ||
' ["P1DT", "YYYY-MM-DD"],\n' + | ||
' ["P1YT", "YYYY"]\n' + | ||
']', | ||
description: 'Values that define the format used in situations where timebased' + | ||
' data is rendered in order, and formatted timestamps should adapt to the' + | ||
' interval between measurements. Keys are ISO 8601 intervals:' + | ||
' http://en.wikipedia.org/wiki/ISO_8601#Time_intervals' | ||
}, | ||
'defaultIndex': { | ||
value: null, | ||
description: 'The index to access if no index is set', | ||
}, | ||
'metaFields': { | ||
value: ['_source', '_id', '_type', '_index'], | ||
description: 'Fields that exist outside of _source to merge into our document when displaying it', | ||
}, | ||
'discover:sampleSize': { | ||
value: 500, | ||
description: 'The number of rows to show in the table', | ||
}, | ||
'fields:popularLimit': { | ||
value: 10, | ||
description: 'The top N most popular fields to show', | ||
}, | ||
'format:numberPrecision': { | ||
value: 3, | ||
description: 'Round numbers to this many decimal places', | ||
}, | ||
'histogram:barTarget': { | ||
value: 50, | ||
description: 'Attempt to generate around this many bar when using "auto" interval in date histograms', | ||
}, | ||
'histogram:maxBars': { | ||
value: 100, | ||
description: 'Never show more than this many bar in date histograms, scale values if needed', | ||
}, | ||
'visualization:tileMap:maxPrecision': { | ||
value: 7, | ||
description: 'The maximum geoHash precision displayed on tile maps: 7 is high, 10 is very high, ' + | ||
'12 is the max. Explanation of cell dimensions: http://www.elastic.co/guide/en/elasticsearch/reference/current/' + | ||
'search-aggregations-bucket-geohashgrid-aggregation.html#_cell_dimensions_at_the_equator', | ||
}, | ||
'csv:separator': { | ||
value: ',', | ||
description: 'Separate exported values with this string', | ||
}, | ||
'csv:quoteValues': { | ||
value: true, | ||
description: 'Should values be quoted in csv exports?', | ||
}, | ||
'history:limit': { | ||
value: 10, | ||
description: 'In fields that have history (e.g. query inputs), show this many recent values', | ||
}, | ||
'shortDots:enable': { | ||
value: false, | ||
description: 'Shorten long fields, for example, instead of foo.bar.baz, show f.b.baz', | ||
}, | ||
'truncate:maxHeight': { | ||
value: 115, | ||
description: 'The maximum height that a cell in a table should occupy. Set to 0 to disable truncation.' | ||
}, | ||
'indexPattern:fieldMapping:lookBack': { | ||
value: 5, | ||
description: 'For index patterns containing timestamps in their names, look for this many recent matching ' + | ||
'patterns from which to query the field mapping.' | ||
} | ||
return { | ||
'query:queryString:options': { | ||
value: '{ "analyze_wildcard": true }', | ||
description: 'Options for the lucene query string parser', | ||
type: 'json' | ||
}, | ||
'dateFormat': { | ||
value: 'MMMM Do YYYY, HH:mm:ss.SSS', | ||
description: 'When displaying a pretty formatted date, use this format', | ||
}, | ||
'dateFormat:scaled': { | ||
type: 'json', | ||
value: | ||
'[\n' + | ||
' ["", "hh:mm:ss.SSS"],\n' + | ||
' ["PT1S", "HH:mm:ss"],\n' + | ||
' ["PT1M", "HH:mm"],\n' + | ||
' ["PT1H",\n' + | ||
' "YYYY-MM-DD HH:mm"],\n' + | ||
' ["P1DT", "YYYY-MM-DD"],\n' + | ||
' ["P1YT", "YYYY"]\n' + | ||
']', | ||
description: 'Values that define the format used in situations where timebased' + | ||
' data is rendered in order, and formatted timestamps should adapt to the' + | ||
' interval between measurements. Keys are ISO 8601 intervals:' + | ||
' http://en.wikipedia.org/wiki/ISO_8601#Time_intervals' | ||
}, | ||
'defaultIndex': { | ||
value: null, | ||
description: 'The index to access if no index is set', | ||
}, | ||
'metaFields': { | ||
value: ['_source', '_id', '_type', '_index'], | ||
description: 'Fields that exist outside of _source to merge into our document when displaying it', | ||
}, | ||
'discover:sampleSize': { | ||
value: 500, | ||
description: 'The number of rows to show in the table', | ||
}, | ||
'fields:popularLimit': { | ||
value: 10, | ||
description: 'The top N most popular fields to show', | ||
}, | ||
'format:numberPrecision': { | ||
value: 3, | ||
description: 'Round numbers to this many decimal places', | ||
}, | ||
'histogram:barTarget': { | ||
value: 50, | ||
description: 'Attempt to generate around this many bar when using "auto" interval in date histograms', | ||
}, | ||
'histogram:maxBars': { | ||
value: 100, | ||
description: 'Never show more than this many bar in date histograms, scale values if needed', | ||
}, | ||
'visualization:tileMap:maxPrecision': { | ||
value: 7, | ||
description: 'The maximum geoHash precision displayed on tile maps: 7 is high, 10 is very high, ' + | ||
'12 is the max. Explanation of cell dimensions: http://www.elastic.co/guide/en/elasticsearch/reference/current/' + | ||
'search-aggregations-bucket-geohashgrid-aggregation.html#_cell_dimensions_at_the_equator', | ||
}, | ||
'csv:separator': { | ||
value: ',', | ||
description: 'Separate exported values with this string', | ||
}, | ||
'csv:quoteValues': { | ||
value: true, | ||
description: 'Should values be quoted in csv exports?', | ||
}, | ||
'history:limit': { | ||
value: 10, | ||
description: 'In fields that have history (e.g. query inputs), show this many recent values', | ||
}, | ||
'shortDots:enable': { | ||
value: false, | ||
description: 'Shorten long fields, for example, instead of foo.bar.baz, show f.b.baz', | ||
}, | ||
'truncate:maxHeight': { | ||
value: 115, | ||
description: 'The maximum height that a cell in a table should occupy. Set to 0 to disable truncation.' | ||
}, | ||
'indexPattern:fieldMapping:lookBack': { | ||
value: 5, | ||
description: 'For index patterns containing timestamps in their names, look for this many recent matching ' + | ||
'patterns from which to query the field mapping.' | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
define(function (require) { | ||
describe('config component', function () { | ||
var $scope; | ||
var config; | ||
var defaults; | ||
var configFile; | ||
|
||
beforeEach(module('kibana')); | ||
beforeEach(inject(function ($injector, Private) { | ||
config = $injector.get('config'); | ||
$scope = $injector.get('$rootScope'); | ||
configFile = $injector.get('configFile'); | ||
defaults = Private(require('components/config/defaults')); | ||
})); | ||
|
||
it('exposes the configFile', function () { | ||
expect(config.file).to.be(configFile); | ||
}); | ||
|
||
describe('#get', function () { | ||
|
||
it('gives access to config values', function () { | ||
expect(config.get('dateFormat')).to.be.a('string'); | ||
}); | ||
|
||
it('reads from the defaults', function () { | ||
var initial = config.get('dateFormat'); | ||
var newDefault = initial + '- new'; | ||
defaults.dateFormat.value = newDefault; | ||
expect(config.get('dateFormat')).to.be(newDefault); | ||
}); | ||
|
||
}); | ||
|
||
describe('#set', function () { | ||
|
||
it('stores a value in the config val set', function () { | ||
var initial = config.get('dateFormat'); | ||
config.set('dateFormat', 'notaformat'); | ||
expect(config.get('dateFormat')).to.be('notaformat'); | ||
}); | ||
|
||
}); | ||
|
||
describe('#$bind', function () { | ||
|
||
it('binds a config key to a $scope property', function () { | ||
var dateFormat = config.get('dateFormat'); | ||
config.$bind($scope, 'dateFormat'); | ||
expect($scope).to.have.property('dateFormat', dateFormat); | ||
}); | ||
|
||
it('alows overriding the property name', function () { | ||
var dateFormat = config.get('dateFormat'); | ||
config.$bind($scope, 'dateFormat', 'defaultDateFormat'); | ||
expect($scope).to.not.have.property('dateFormat'); | ||
expect($scope).to.have.property('defaultDateFormat', dateFormat); | ||
}); | ||
|
||
it('keeps the property up to date', function () { | ||
var dateFormat = config.get('dateFormat'); | ||
var newDateFormat = dateFormat + ' NEW NEW NEW!'; | ||
config.$bind($scope, 'dateFormat'); | ||
|
||
expect($scope).to.have.property('dateFormat', dateFormat); | ||
config.set('dateFormat', newDateFormat); | ||
expect($scope).to.have.property('dateFormat', newDateFormat); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
}); |