UNPKG

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

33 lines (28 loc) 796 B
import _ from 'lodash'; import angular from 'angular'; import uiModules from 'ui/modules'; uiModules .get('kibana') .directive('jsonInput', function () { return { restrict: 'A', require: 'ngModel', link: function (scope, $el, attrs, ngModelCntrl) { ngModelCntrl.$formatters.push(toJSON); ngModelCntrl.$parsers.push(fromJSON); function fromJSON(value) { try { value = JSON.parse(value); let validity = !scope.$eval(attrs.requireKeys) ? true : _.keys(value).length > 0; ngModelCntrl.$setValidity('json', validity); } catch (e) { ngModelCntrl.$setValidity('json', false); } return value; } function toJSON(value) { return angular.toJson(value, 2); } } }; });