2017-12-20 05:33:33 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
2019-09-09 01:58:57 -05:00
|
|
|
import { JsonExplorer } from '@grafana/ui';
|
2016-07-21 06:57:19 -05:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('jsonTree', [
|
2017-12-19 09:06:54 -06:00
|
|
|
function jsonTreeDirective() {
|
|
|
|
return {
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'E',
|
2017-12-19 09:06:54 -06:00
|
|
|
scope: {
|
2017-12-20 05:33:33 -06:00
|
|
|
object: '=',
|
|
|
|
startExpanded: '@',
|
|
|
|
rootName: '@',
|
2017-12-19 09:06:54 -06:00
|
|
|
},
|
2019-03-11 14:44:14 -05:00
|
|
|
link: (scope: any, elem) => {
|
2019-06-17 17:10:56 -05:00
|
|
|
let expansionLevel = scope.startExpanded;
|
|
|
|
if (scope.startExpanded === 'true') {
|
|
|
|
expansionLevel = 2;
|
|
|
|
} else if (scope.startExpanded === 'false') {
|
|
|
|
expansionLevel = 1;
|
|
|
|
}
|
|
|
|
const jsonObject = { [scope.rootName]: scope.object };
|
|
|
|
const jsonExp = new JsonExplorer(jsonObject, expansionLevel, {
|
2017-12-20 05:33:33 -06:00
|
|
|
animateOpen: true,
|
2017-12-19 09:06:54 -06:00
|
|
|
});
|
|
|
|
const html = jsonExp.render(true);
|
2019-06-17 17:10:56 -05:00
|
|
|
elem.append(html);
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
};
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
]);
|