kibana-123
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
46 lines (39 loc) • 1.21 kB
JavaScript
import _ from 'lodash';
import uiModules from 'ui/modules';
import samplesTemplate from 'ui/field_format_editor/samples/samples.html';
uiModules
.get('kibana')
.directive('fieldFormatEditorSamples', function ($sce, Promise) {
return {
restrict: 'E',
template: samplesTemplate,
require: ['?^ngModel', '^fieldEditor'],
scope: true,
link: function ($scope, $el, attrs, cntrls) {
let ngModelCntrl = cntrls[0];
$scope.samples = null;
$scope.$bind('inputs', attrs.inputs);
$scope.$watchMulti([
'editor.field.format',
'[]inputs'
], function () {
$scope.samples = null;
let field = $scope.editor.field;
if (!field || !field.format) {
return;
}
Promise.try(function () {
let converter = field.format.getConverterFor('html');
$scope.samples = _.map($scope.inputs, function (input) {
return [input, $sce.trustAsHtml(converter(input))];
});
})
.then(validity, validity);
});
function validity(err) {
$scope.error = err;
ngModelCntrl && ngModelCntrl.$setValidity('patternExecutes', !err);
}
}
};
});