inspectCtrl.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. define([
  2. 'angular'
  3. ],
  4. function (angular) {
  5. 'use strict';
  6. var module = angular.module('kibana.controllers');
  7. module.controller('InspectCtrl', function($scope) {
  8. var model = $scope.inspector;
  9. function getParametersFromQueryString(queryString) {
  10. var result = [];
  11. var parameters = queryString.split("&");
  12. for (var i = 0; i < parameters.length; i++) {
  13. var keyValue = parameters[i].split("=");
  14. if (keyValue[1].length > 0) {
  15. result.push({ key: keyValue[0], value: window.unescape(keyValue[1]) });
  16. }
  17. }
  18. return result;
  19. }
  20. $scope.init = function () {
  21. $scope.editor = { index: 0 };
  22. if (!model.error) {
  23. return;
  24. }
  25. if (model.error.stack) {
  26. $scope.editor.index = 2;
  27. $scope.stack_trace = model.error.stack;
  28. $scope.message = model.error.message;
  29. }
  30. else if (model.error.config && model.error.config.data) {
  31. $scope.editor.index = 1;
  32. $scope.request_parameters = getParametersFromQueryString(model.error.config.data);
  33. if (model.error.data.indexOf('DOCTYPE') !== -1) {
  34. $scope.response_html = model.error.data;
  35. }
  36. }
  37. };
  38. });
  39. angular
  40. .module('kibana.directives')
  41. .directive('iframeContent', function($parse) {
  42. return {
  43. restrict: 'A',
  44. link: function($scope, elem, attrs) {
  45. var getter = $parse(attrs.iframeContent), value = getter($scope);
  46. $scope.$on("$destroy",function() {
  47. elem.remove();
  48. });
  49. var iframe = document.createElement('iframe');
  50. iframe.width = '100%';
  51. iframe.height = '400px';
  52. iframe.style.border = 'none';
  53. iframe.src = 'about:blank';
  54. elem.append(iframe);
  55. iframe.contentWindow.document.open('text/html', 'replace');
  56. iframe.contentWindow.document.write(value);
  57. iframe.contentWindow.document.close();
  58. }
  59. };
  60. });
  61. });