jsontree.ts 819 B

1234567891011121314151617181920212223242526272829
  1. import { JsonExplorer } from '@grafana/ui';
  2. import coreModule from 'app/angular/core_module';
  3. coreModule.directive('jsonTree', [
  4. function jsonTreeDirective() {
  5. return {
  6. restrict: 'E',
  7. scope: {
  8. object: '=',
  9. startExpanded: '@',
  10. rootName: '@',
  11. },
  12. link: (scope: any, elem) => {
  13. let expansionLevel = scope.startExpanded;
  14. if (scope.startExpanded === 'true') {
  15. expansionLevel = 2;
  16. } else if (scope.startExpanded === 'false') {
  17. expansionLevel = 1;
  18. }
  19. const jsonObject = { [scope.rootName]: scope.object };
  20. const jsonExp = new JsonExplorer(jsonObject, expansionLevel, {
  21. animateOpen: true,
  22. });
  23. const html = jsonExp.render(true);
  24. elem.append(html);
  25. },
  26. };
  27. },
  28. ]);