Allow custom fields in advanced settings

If the kibana index includes any custom key/value pairs in the config,
they will be editable on the advanced settings panel. All custom
settings appear at the bottom of the list and are visually labeled as a
"custom setting". When the trash can icon is clicked, custom settings
are removed entirely from the index.
This commit is contained in:
Court Ewing 2015-09-11 11:47:14 -04:00
parent fdc351b2e6
commit 2378e6282d
3 changed files with 47 additions and 23 deletions

View file

@ -1,9 +1,12 @@
<tr ng-class="conf.value === undefined ? 'default' : 'custom'">
<td class="name">
<b>{{conf.name}}</b>
<span class="smaller" ng-show="conf.value !== undefined">
<span class="smaller" ng-show="!conf.isCustom && conf.value !== undefined">
(Default: <i>{{conf.defVal == undefined ? 'null' : conf.defVal}}</i>)
</span>
<span class="smaller" ng-show="conf.isCustom">
(Custom setting)
</span>
<br>
<span class="smaller" ng-bind-html="conf.description | trustAsHtml"></span>
</td>

View file

@ -3,8 +3,7 @@
<div class="bs-callout bs-callout-warning">
<h4>Caution: You can break stuff here</h4>
Be careful in here, these settings are for very advanced users only. Tweaks you make here can break large portions of Kibana.
Some of these settings may be undocumented, unsupported or experimental. Blanking a field will cause Kibana to use its internal
defaults which may be unacceptable given other configuration directives.
Some of these settings may be undocumented, unsupported or experimental. If a field has a default value, blanking the field will reset it to its default which may be unacceptable given other configuration directives. Deleting a custom setting will permanently remove it from Kibana's config.
</div>
<form role="form">
<input aria-label="Filter" ng-model="advancedFilter" class="form-control span12" type="text" placeholder="Filter"/>

View file

@ -20,6 +20,7 @@ define(function (require) {
ESC: 27
};
var IMMUTABLE_CONFIG_VALS = ['buildNum'];
var NAMED_EDITORS = ['json', 'array', 'boolean', 'select'];
var NORMAL_EDITOR = ['number', 'string', 'null', 'undefined'];
@ -32,30 +33,51 @@ define(function (require) {
return !(conf.json || conf.array || conf.bool || conf.normal);
}
function notDefaultConfig(configName) {
return !(configName in configDefaults);
}
function notImmutableConfig(configName) {
return !_.contains(IMMUTABLE_CONFIG_VALS, configName);
}
function toEditableConfig(def, name, value) {
var isCustom = !def;
if (isCustom) def = {};
var conf = {
name,
value,
isCustom,
defVal: def.value,
type: getValType(def, value),
description: def.description,
options: def.options
};
var editor = getEditorType(conf);
conf.json = editor === 'json';
conf.select = editor === 'select';
conf.bool = editor === 'boolean';
conf.array = editor === 'array';
conf.normal = editor === 'normal';
conf.tooComplex = !editor;
return conf;
}
function readConfigVals() {
var configVals = config._vals();
$scope.configs = _.map(configDefaults, function (def, name) {
var val = configVals[name];
var conf = {
name: name,
defVal: def.value,
type: getValType(def, val),
description: def.description,
options: def.options,
value: val,
};
var customConfig = Object.keys(configVals)
.filter(notDefaultConfig)
.filter(notImmutableConfig)
.map(name => toEditableConfig(false, name, configVals[name]));
var editor = getEditorType(conf);
conf.json = editor === 'json';
conf.select = editor === 'select';
conf.bool = editor === 'boolean';
conf.array = editor === 'array';
conf.normal = editor === 'normal';
conf.tooComplex = !editor;
return conf;
});
$scope.configs = _(configDefaults)
.map((def, name) => toEditableConfig(def, name, configVals[name]))
.concat(customConfig)
.value();
}
readConfigVals();