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

Field formatting #2731

Merged
merged 129 commits into from
May 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
73e28d4
[docTable/tableRow] rely on indexPattern.formatHit
Jan 22, 2015
051dfdd
[docViewer] rely on indexPattern.formatHit()
Jan 22, 2015
fcd2d6e
[indexPattern] export partially applied formatHit()
Jan 22, 2015
171ea25
[registry/fieldFormats] replace indexPattern/fieldFormats with a regi…
Jan 22, 2015
5c38476
[lodash/mixins] provide default string format as util
Jan 22, 2015
792059d
[stringify] replace field formats with stringify component
Jan 23, 2015
3e685a5
support configurable format defaults by type
Jan 26, 2015
ec96ab0
rename limit to ary, like lodash 3.0
Jan 27, 2015
743391e
make field formats saveable
Jan 27, 2015
e7dd0f0
fix de tests
Jan 28, 2015
a137ea8
move the field setup logic into a util, preserve keys when serialized
Jan 28, 2015
4d3c7f1
[stringify] added tests
Jan 28, 2015
4fdf7c8
[indexPatterns/formatHit] I like... format'ed the thing
Jan 28, 2015
e7c2689
[stringify/number] return nothing for values that aren't numbers
Jan 28, 2015
ed02f00
updated relative jshint path
Apr 3, 2015
60d05b3
[aggConfig/tests] use new fieldFormats registry
Apr 3, 2015
32a0dbb
[fieldFormats] shorten #defaultFor() to #for()
Apr 9, 2015
8838b97
[stringfy] reorganized types into their own dir
Apr 9, 2015
c88d2bc
[stringify] added anchor type
Apr 9, 2015
607b2a6
[config] added default format for murmur3
Apr 9, 2015
fecf290
[docTable] updated to use only #formatHit()
Apr 9, 2015
be7506b
rely on field formatting for html escaping
Apr 9, 2015
6456984
[objWrap] allow changing savable fiels that are at their default value
Apr 9, 2015
fb2cf51
[fieldFormats] moved default formats into a single config value
Apr 9, 2015
4395a46
[indexPattern] isolate field format names to persist across refresh
Apr 9, 2015
8ca4b10
Merge branch 'master' of github.com:elastic/kibana into fieldFormatting
Apr 10, 2015
4e9c4ed
[mixins] rename _.asString to _.asPrettyString
Apr 10, 2015
4f0df4e
[indexPattern/fields] make Field creation a bit more externally consu…
Apr 10, 2015
937b817
[fieldTypes] introducing "unknown" field type
Apr 10, 2015
356b1b1
[indexPattern/field] keep a copy of the original field spec
Apr 10, 2015
d40f56a
[util/objDefine] disable a test in Phantom because of a bug it has
Apr 13, 2015
2808370
[util/objDefine] rename #flag to #comp
Apr 13, 2015
7836012
[fieldEditor] stub the route
Apr 13, 2015
b4c1412
[indexPattern/field] add url for field editting
Apr 13, 2015
ffac554
[settings/indices] simplify field tables, add edit buttons
Apr 13, 2015
f17dc1c
[fieldEditor] expose field format param editors
Apr 14, 2015
ca5a533
[indexPattern] keep id and editUrl in sync
Apr 15, 2015
77e75d5
[fieldEditor] [indexPattern] [stringify] implement FieldFormat Class
Apr 17, 2015
70aca13
[fieldEditor] added params for numeral formatter
Apr 17, 2015
9fa1bee
[indexPatterns] pull in the FieldFormat class
Apr 17, 2015
4c2d6a0
[indexPatterns/fiels] allow overriding the format per-field
Apr 17, 2015
9d6bda4
[fieldEditor] simplied $scope, and made field mutable by the editor
Apr 17, 2015
68a8343
[indexPattern] enhance serialization of #fieldFormatMap
Apr 17, 2015
6fe8fa1
[fieldEditor] implement save
Apr 17, 2015
2d2fdee
Merge branch 'master' of github.com:elastic/kibana into fieldFormatting
Apr 20, 2015
ea1f87d
Merge branch 'bindconfigvars' into fieldFormatting
Apr 20, 2015
062595a
[indexPattern] don't compute routes if we don't have enough data
Apr 21, 2015
0883e8e
[settings/indices] move the index header into a directive
Apr 21, 2015
631eb95
[settings/indices] merged the scripted field editor and the normal fi…
Apr 21, 2015
24d4f5c
[stringify] fixing file casing
Apr 21, 2015
656d68b
[config] added config vars for the different number formats
Apr 22, 2015
882fae4
[fieldEditor] move the scripting info into the scripting form-group
Apr 22, 2015
ca5dda0
[fieldEditor] only show params if the field has a custom field format
Apr 22, 2015
cca76e2
[stringify] added editors for numbers, drop moment and numeral.js types
Apr 22, 2015
f546780
Merge branch 'bindconfigvars' into fieldFormatting
Apr 22, 2015
752d8da
[_.asPrettyString] basic optimization of very hot path
Apr 22, 2015
cabc334
[hintbox] improve styles when used outside visualize sidebar
Apr 23, 2015
69f31d3
[field/format] support formatters for multiple content types
Apr 23, 2015
2ad34bd
[settings/fields] fix compile order so params can require the editor
Apr 23, 2015
12ac4ae
[stringify] convert Anchor to Url format
Apr 23, 2015
55742cd
[stringify/numeral] show default format as a placeholder
Apr 23, 2015
988d56b
[stringify/url] use ng-options rather than html-based options
Apr 23, 2015
3f0d2f3
[settings/indices] added doctitles to controllers
Apr 23, 2015
3dfe595
[fieldEditor] simplify param saving, just strip defaults on save
Apr 23, 2015
646b704
[fieldEditor] style tweaks
Apr 23, 2015
4289444
[settings/field] fix spacing for scripted fields
Apr 23, 2015
04d6210
[mixins] port _.remove so that it support IndexedArrays
Apr 23, 2015
6fd4f1c
[settings/editor] allow deleting a scripted field
Apr 23, 2015
b2f71f7
[registry/fieldFormats] clean up api to make Type/instance line clearer
Apr 23, 2015
b549710
[aggTypes/metrics] implemented per-agg formatting
Apr 23, 2015
f93cfa7
[stringify/percent] standardize on 'percent' naming
Apr 23, 2015
e191666
[stringify] when escaping don't cast numbers to strings
Apr 23, 2015
29561d1
[stringify/date] simplify date formatting
Apr 23, 2015
c55c959
[stringify] added unit tests for default field types
Apr 23, 2015
d20ef9f
[aggTypes/count] added custom value formatter
Apr 23, 2015
4e08060
[routes] fix test that used #addResolves
Apr 24, 2015
433629c
[$scope.$bind] mimic isolate binding better, mas tests
Apr 24, 2015
92ed019
[fieldEditor] convert to an isolate scope
Apr 24, 2015
0e29fad
[fieldEditor] handle missing FieldFormats better
Apr 24, 2015
f545978
[fieldFormatEditor] moved into own directive, for testability and reuse
Apr 24, 2015
0977e26
Merge branch 'fix/multiWatchRaceCondition' into fieldFormatting
Apr 25, 2015
a3bf70a
[fieldEditor] added some tests
Apr 25, 2015
3159d51
[fieldFormat] remove old param doc
Apr 27, 2015
39d291f
[stringify/Date/editor] use the isolate fieldEditorPattern directive
Apr 27, 2015
9a1dc07
Merge branch 'fix/multiWatchRaceCondition' into fieldFormatting
Apr 27, 2015
3e2fb5b
[settings/indices] stripe the field list
Apr 28, 2015
bff2618
[fieldEditor] absorb the pattern and numeral directives, show pattern…
Apr 28, 2015
f14ffd7
[fieldEditor] after saving redirect to the indexPattern, or go back
Apr 28, 2015
6257333
[aggReponse] make sure to specify the 'text' content type
Apr 28, 2015
8d3d6d5
Merge branch 'add/yAxisFormatter' into fieldFormatting
Apr 28, 2015
f74f7db
[fieldEditor] simplified out self.format and self.fieldProps
Apr 28, 2015
72e4e57
[aggTypes/count] remove custom format
Apr 28, 2015
680c328
Merge branch 'master' of github.com:elastic/kibana into fieldFormatting
Apr 29, 2015
b600e13
[registry/fieldFormats] allow setting default params for configs
Apr 29, 2015
5dc8536
[fieldFormatEditor] absorb the numeral and pattern directives
Apr 29, 2015
f1ff251
[stringify/String] added a transform param to the string format
Apr 29, 2015
9e8eb3a
[indexPattern] added support for per-field formatting to help discove…
Apr 29, 2015
874c32e
[fieldFormat] refactor contentTypes, text is now the default
Apr 29, 2015
e4b07e8
[aggTypes/count] always format the value as a number
Apr 30, 2015
9caa814
[object.routes] move away from precomputed routes
Apr 30, 2015
81a6162
[mixins/shortenDottedString] only shorten strings
Apr 30, 2015
f9ae669
[flattenHit] [formatHit] [stubbedIndexPattern] update tests
Apr 30, 2015
a1af9d4
Merge branch 'master' into fieldFormatting
May 1, 2015
e2f8f8e
[stringify/url] urls for geo_points and attachments don't make much s…
Apr 30, 2015
b7e35e6
[ObjDefine] support phantomjs dispite https://github.com/ariya/phanto…
Apr 30, 2015
c90996e
[fixture/hits] wrap in private
Apr 30, 2015
ed667d8
[stringify/source] added basic _source format
Apr 30, 2015
159f1bd
[indexPattern/field] _source field is always of type _source
Apr 30, 2015
9566291
[kbnUrl] added getRouteHref() method
Apr 30, 2015
e19024e
[docTable/row] cache the formatted source
Apr 30, 2015
fa41afc
[fieldFormat] implement highlighting
Apr 30, 2015
eed15bb
[settings/indices] added field format name
Apr 30, 2015
12b72a6
fixin some tests
Apr 30, 2015
4d8ff2f
[settings/indices] missed an old usage of indexPattern.routes
May 1, 2015
8d586fc
[objDefine] fix typo and add docs
May 1, 2015
c0b87d9
[docTable/tests] move init logic inside of a test suite
May 1, 2015
f25d885
[stringify] remove old format module
May 1, 2015
797ff39
Merge branch 'add/yAxisFormatter' into fieldFormatting
May 1, 2015
3d65cda
Merge branch 'master' of github.com:elastic/kibana into fieldFormatting
May 1, 2015
bd99a48
[fieldFormatting/contentType/text] remove html escaping
May 1, 2015
b942257
[fieldEditor] added a warning about field formatting
May 1, 2015
2a15e9f
[stringify/editors] fix half renamed sample inputs
May 4, 2015
4a717b7
[fieldEditor] properly teardown the shadowCopy when saving
May 4, 2015
77409af
[indexPattern] clean up getFields() api
May 4, 2015
482638e
Merge branch 'master' of github.com:elastic/kibana into fieldFormatting
May 4, 2015
f99beea
[indexPattern/getScriptedFields] update tests
May 4, 2015
1b303fb
[stringify/url] only own properties can be locals
May 4, 2015
8dbd8f9
[vislib/yAxis] properly pass the yAxisFormatter from handler to compo…
May 4, 2015
e05c7bd
[stringify/url] prevent an infinite loop of infinity looping
May 4, 2015
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
define(function (require) {
var _ = require('lodash');
define(function () {
return function (leaf) {
// walk up the branch for each parent
function walk(item, memo) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(function (require) {
define(function () {
return function PointSeriesInitX() {
return function initXAxis(chart) {
var x = chart.aspects.x;
Expand All @@ -14,4 +14,4 @@ define(function (require) {
}
};
};
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ define(function (require) {
chart.yScale = xAggOutput.metricScale || null;
};
};
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
define(function (require) {
return function PointSeriesTooltipFormatter($compile, $rootScope) {
var _ = require('lodash');
var $ = require('jquery');

var $tooltipScope = $rootScope.$new();
Expand Down
22 changes: 5 additions & 17 deletions src/kibana/components/agg_table/agg_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ define(function (require) {
.directive('kbnAggTable', function ($filter, config, Private, compileRecursiveDirective) {
var _ = require('lodash');

var orderBy = $filter('orderBy');

return {
restrict: 'E',
template: require('text!components/agg_table/agg_table.html'),
Expand Down Expand Up @@ -54,7 +52,7 @@ define(function (require) {
}

// escape each cell in each row
var csvRows = rows.map(function (row, i) {
var csvRows = rows.map(function (row) {
return row.map(escape);
});

Expand All @@ -72,16 +70,13 @@ define(function (require) {
var table = $scope.table;

if (!table) {
$scope.formattedRows = null;
$scope.rows = null;
$scope.formattedColumns = null;
return;
}

setFormattedRows(table);
setFormattedColumns(table);
});

function setFormattedColumns(table) {
self.csv.filename = (table.title() || 'table') + '.csv';
$scope.rows = table.rows;
$scope.formattedColumns = table.columns.map(function (col, i) {
var agg = $scope.table.aggConfig(col);
var field = agg.field();
Expand All @@ -98,14 +93,7 @@ define(function (require) {

return formattedColumn;
});
}

function setFormattedRows(table) {
$scope.rows = table.rows;

// update the csv file's title
self.csv.filename = (table.title() || 'table') + '.csv';
}
});
}
};
});
Expand Down
28 changes: 18 additions & 10 deletions src/kibana/components/agg_types/metrics/_metric_agg_type.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
define(function (require) {
return function MetricAggTypeProvider(Private, indexPatterns) {
return function MetricAggTypeProvider(Private) {
var _ = require('lodash');
var AggType = Private(require('components/agg_types/_agg_type'));
var fieldFormats = Private(require('registry/field_formats'));

_(MetricAggType).inherits(AggType);
function MetricAggType(config) {
MetricAggType.Super.call(this, config);

if (_.isFunction(config.getValue)) {
this.getValue = config.getValue;
}
// allow overriding any value on the prototype
_.forOwn(config, function (val, key) {
if (_.has(MetricAggType.prototype, key)) {
this[key] = val;
}
}, this);
}

/**
Expand All @@ -21,15 +25,19 @@ define(function (require) {
return bucket[agg.id].value;
};

/**
* Pick a format for the values produced by this agg type,
* overriden by several metrics that always output a simple
* number
*
* @param {agg} agg - the agg to pick a format for
* @return {FieldFromat}
*/
MetricAggType.prototype.getFormat = function (agg) {
var field = agg.field();
if (field && field.type === 'date' && field.format) {
return field.format;
} else {
return indexPatterns.fieldFormats.byName.number;
}
return field ? field.format : fieldFormats.getDefaultInstance('number');
};

return MetricAggType;
};
});
});
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/metrics/avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ define(function (require) {
]
});
};
});
});
6 changes: 5 additions & 1 deletion src/kibana/components/agg_types/metrics/cardinality.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
define(function (require) {
return function AggTypeMetricCardinalityProvider(Private) {
var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type'));
var fieldFormats = Private(require('registry/field_formats'));

return new MetricAggType({
name: 'cardinality',
title: 'Unique Count',
makeLabel: function (aggConfig) {
return 'Unique count of ' + aggConfig.params.field.displayName;
},
getFormat: function () {
return fieldFormats.getDefaultInstance('number');
},
params: [
{
name: 'field'
}
]
});
};
});
});
8 changes: 6 additions & 2 deletions src/kibana/components/agg_types/metrics/count.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
define(function (require) {
return function AggTypeMetricCountProvider(Private) {
var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type'));
var fieldFormats = Private(require('registry/field_formats'));

return new MetricAggType({
name: 'count',
title: 'Count',
hasNoDsl: true,
makeLabel: function (aggConfig) {
makeLabel: function () {
return 'Count';
},
getFormat: function () {
return fieldFormats.getDefaultInstance('number');
},
getValue: function (agg, bucket) {
return bucket.doc_count;
}
});
};
});
});
4 changes: 4 additions & 0 deletions src/kibana/components/agg_types/metrics/percentile_ranks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define(function (require) {

var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type'));
var getResponseAggConfig = Private(require('components/agg_types/metrics/_get_response_agg_config'));
var fieldFormats = Private(require('registry/field_formats'));

var valuesEditor = require('text!components/agg_types/controls/percentile_ranks.html');
// required by the values editor
Expand Down Expand Up @@ -39,6 +40,9 @@ define(function (require) {
return new ValueAggConfig(value);
});
},
getFormat: function () {
return fieldFormats.getInstance('percent') || fieldFormats.getDefaultInstance('number');
},
getValue: function (agg, bucket) {
// values for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we
// parse the keys and respond with the value that matches
Expand Down
4 changes: 4 additions & 0 deletions src/kibana/components/agg_types/metrics/percentiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define(function (require) {
var MetricAggType = Private(require('components/agg_types/metrics/_metric_agg_type'));
var getResponseAggConfig = Private(require('components/agg_types/metrics/_get_response_agg_config'));
var ordinalSuffix = require('utils/ordinal_suffix');
var fieldFormats = Private(require('registry/field_formats'));

var percentsEditor = require('text!components/agg_types/controls/percentiles.html');
// required by the percentiles editor
Expand Down Expand Up @@ -40,6 +41,9 @@ define(function (require) {
return new ValueAggConfig(percent);
});
},
getFormat: function () {
return fieldFormats.getInstance('percent') || fieldFormats.getDefaultInstance('number');
},
getValue: function (agg, bucket) {
// percentiles for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we
// parse the keys and respond with the value that matches
Expand Down
66 changes: 56 additions & 10 deletions src/kibana/components/bind.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
define(function (require) {
var _ = require('lodash');
var angular = require('angular');

require('modules').get('kibana')
.config(function ($provide) {

function strictEquality(a, b) {
// are the values equal? or, are they both NaN?
return a === b || (a !== a && b !== b);
}

function errorNotAssignable(source, target) {
throw Error('Unable to accept change to bound $scope property "' + source + '"' +
' because source expression "' + target + '" is not assignable!');
}

$provide.decorator('$rootScope', function ($delegate, $parse) {
/**
* Two-way bind a value from scope to another property on scope. This
Expand All @@ -12,23 +23,58 @@ define(function (require) {
*
* @param {expression} to - the location on scope to bind to
* @param {expression} from - the location on scope to bind from
* @param {Scope} $sourceScope - the scope to read "from" expression from
* @return {undefined}
*/
$delegate.constructor.prototype.$bind = function (to, from) {
var $source = this.$parent;
$delegate.constructor.prototype.$bind = function (to, from, $sourceScope) {
var $source = $sourceScope || this.$parent;
var $target = this;

var getter = $parse(from);
var setter = $parse(to).assign;
// parse expressions
var $to = $parse(to);
if (!$to.assign) errorNotAssignable(to, from);
var $from = $parse(from);
$from.assignOrFail = $from.assign || function () {
// revert the change and throw an error, child writes aren't supported
$to($target, lastSourceVal = $from($source));
errorNotAssignable(from, to);
};

// bind scopes to expressions
var getTarget = function () { return $to($target); };
var setTarget = function (v) { return $to.assign($target, v); };
var getSource = function () { return $from($source); };
var setSource = function (v) { return $from.assignOrFail($source, v); };

// if we are syncing down a literal, then we use loose equality check
var strict = !$from.literal;
var compare = strict ? strictEquality : angular.equals;

// to support writing from the child to the parent we need to know
// which source has changed. Track the source value and anytime it
// changes (even if the target value changed too) push from source
// to target. If the source hasn't changed then the change is from
// the target and push accordingly
var lastSourceVal = getSource();

// push the initial value down, start off in sync
setTarget(lastSourceVal);

$target.$watch(function () {
var sourceVal = getSource();
var targetVal = getTarget();

var outOfSync = !compare(sourceVal, targetVal);
var sourceChanged = outOfSync && !compare(sourceVal, lastSourceVal);

if (sourceChanged) setTarget(sourceVal);
else if (outOfSync) setSource(targetVal);

setter($target, getter($source));
this.$watch(
function () { return getter($source); },
function (val) { setter($target, val); }
);
return lastSourceVal = sourceVal;
}, null, !strict);
};

return $delegate;
});
});
});
});
43 changes: 43 additions & 0 deletions src/kibana/components/bound_to_config_obj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
define(function (require) {
return function BoundToConfigObjProvider($rootScope, config) {
var _ = require('lodash');

/**
* Create an object with properties that may be bound to config values.
* The input object is basically cloned unless one of it's own properties
* resolved to a string value that starts with an equal sign. When that is
* found, that property is forever bound to the corresponding config key.
*
* example:
*
* // name is cloned, height is bound to the defaultHeight config key
* { name: 'john', height: '=defaultHeight' };
*
* @param {Object} input
* @return {Object}
*/
function BoundToConfigObj(input) {
var self = this;

_.forOwn(input, function (val, prop) {
if (!_.isString(val) || val.charAt(0) !== '=') {
self[prop] = val;
return;
}

var configKey = val.substr(1);

update();
$rootScope.$on('init:config', update);
$rootScope.$on('change:config.' + configKey, update);
function update() {
self[prop] = config.get(configKey);
}

});
}

return BoundToConfigObj;

};
});
Loading