grafana/public/app/controllers/inspectCtrl.js

87 lines
2.3 KiB
JavaScript
Raw Normal View History

2014-04-05 06:26:48 -05:00
define([
'angular',
'lodash'
2014-04-05 06:26:48 -05:00
],
function (angular, _) {
2014-04-05 06:26:48 -05:00
'use strict';
2014-07-28 11:11:52 -05:00
var module = angular.module('grafana.controllers');
2014-04-05 06:26:48 -05:00
module.controller('InspectCtrl', function($scope) {
var model = $scope.inspector;
function getParametersFromQueryString(queryString) {
var result = [];
var parameters = queryString.split("&");
for (var i = 0; i < parameters.length; i++) {
var keyValue = parameters[i].split("=");
if (keyValue[1].length > 0) {
result.push({ key: keyValue[0], value: window.unescape(keyValue[1]) });
}
}
return result;
}
2014-04-05 06:26:48 -05:00
$scope.init = function () {
$scope.editor = { index: 0 };
2014-04-05 06:26:48 -05:00
if (!model.error) {
return;
2014-04-05 06:26:48 -05:00
}
if (_.isString(model.error.data)) {
$scope.response = model.error.data;
}
if (model.error.config && model.error.config.params) {
$scope.request_parameters = _.map(model.error.config.params, function(value, key) {
return { key: key, value: value};
});
}
if (model.error.stack) {
$scope.editor.index = 2;
$scope.stack_trace = model.error.stack;
$scope.message = model.error.message;
}
else if (model.error.config && model.error.config.data) {
$scope.editor.index = 1;
2014-04-05 06:26:48 -05:00
$scope.request_parameters = getParametersFromQueryString(model.error.config.data);
2014-04-05 06:26:48 -05:00
if (model.error.data.indexOf('DOCTYPE') !== -1) {
$scope.response_html = model.error.data;
2014-04-05 06:26:48 -05:00
}
}
};
});
angular
2014-07-28 11:11:52 -05:00
.module('grafana.directives')
2014-04-05 06:26:48 -05:00
.directive('iframeContent', function($parse) {
return {
restrict: 'A',
link: function($scope, elem, attrs) {
var getter = $parse(attrs.iframeContent), value = getter($scope);
$scope.$on("$destroy",function() {
elem.remove();
});
var iframe = document.createElement('iframe');
iframe.width = '100%';
iframe.height = '400px';
iframe.style.border = 'none';
iframe.src = 'about:blank';
elem.append(iframe);
iframe.contentWindow.document.open('text/html', 'replace');
iframe.contentWindow.document.write(value);
iframe.contentWindow.document.close();
}
};
});
});