|
|
@@ -14,7 +14,8 @@ define([
|
|
|
'angular',
|
|
|
'app',
|
|
|
'underscore',
|
|
|
- 'require'
|
|
|
+ 'require',
|
|
|
+ 'services/filterSrv'
|
|
|
],
|
|
|
function (angular, app, _, require) {
|
|
|
'use strict';
|
|
|
@@ -22,7 +23,7 @@ function (angular, app, _, require) {
|
|
|
var module = angular.module('kibana.panels.text', []);
|
|
|
app.useModule(module);
|
|
|
|
|
|
- module.controller('text', function($scope) {
|
|
|
+ module.controller('text', function($scope, filterSrv) {
|
|
|
|
|
|
$scope.panelMeta = {
|
|
|
description : "A static text panel that can use plain text, markdown, or (sanitized) HTML"
|
|
|
@@ -39,63 +40,58 @@ function (angular, app, _, require) {
|
|
|
|
|
|
$scope.init = function() {
|
|
|
$scope.initBaseController(this, $scope);
|
|
|
-
|
|
|
$scope.ready = false;
|
|
|
+ $scope.$on('refresh', $scope.render);
|
|
|
+ $scope.render();
|
|
|
};
|
|
|
|
|
|
$scope.render = function() {
|
|
|
- $scope.$emit('render');
|
|
|
+ if ($scope.panel.mode === 'markdown') {
|
|
|
+ $scope.renderMarkdown($scope.panel.content);
|
|
|
+ }
|
|
|
+ else if ($scope.panel.mode === 'html') {
|
|
|
+ $scope.updateContent($scope.panel.content);
|
|
|
+ }
|
|
|
+ else if ($scope.panel.mode === 'text') {
|
|
|
+ $scope.renderText($scope.panel.content);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
- $scope.openEditor = function() {
|
|
|
- //$scope.$emit('open-modal','paneleditor');
|
|
|
- console.log('scope id', $scope.$id);
|
|
|
+ $scope.renderText = function(content) {
|
|
|
+ content = content
|
|
|
+ .replace(/&/g, '&')
|
|
|
+ .replace(/>/g, '>')
|
|
|
+ .replace(/</g, '<')
|
|
|
+ .replace(/\n/g, '<br/>');
|
|
|
+
|
|
|
+ $scope.updateContent(content);
|
|
|
};
|
|
|
|
|
|
- });
|
|
|
+ $scope.renderMarkdown = function(content) {
|
|
|
+ require(['./lib/showdown'], function (Showdown) {
|
|
|
+ var converter = new Showdown.converter();
|
|
|
+ var text = content
|
|
|
+ .replace(/&/g, '&')
|
|
|
+ .replace(/>/g, '>')
|
|
|
+ .replace(/</g, '<');
|
|
|
|
|
|
- module.directive('markdown', function() {
|
|
|
- return {
|
|
|
- restrict: 'E',
|
|
|
- link: function(scope, element) {
|
|
|
- scope.$on('render', function() {
|
|
|
- render_panel();
|
|
|
- });
|
|
|
-
|
|
|
- function render_panel() {
|
|
|
- require(['./lib/showdown'], function (Showdown) {
|
|
|
- scope.ready = true;
|
|
|
- var converter = new Showdown.converter();
|
|
|
- var text = scope.panel.content.replace(/&/g, '&')
|
|
|
- .replace(/>/g, '>')
|
|
|
- .replace(/</g, '<');
|
|
|
- var htmlText = converter.makeHtml(text);
|
|
|
- element.html(htmlText);
|
|
|
- // For whatever reason, this fixes chrome. I don't like it, I think
|
|
|
- // it makes things slow?
|
|
|
- if(!scope.$$phase) {
|
|
|
- scope.$apply();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ $scope.updateContent(converter.makeHtml(text));
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.updateContent = function(html) {
|
|
|
+ try {
|
|
|
+ $scope.content = filterSrv.applyTemplateToTarget(html);
|
|
|
|
|
|
- render_panel();
|
|
|
+ if(!$scope.$$phase) {
|
|
|
+ $scope.$apply();
|
|
|
+ }
|
|
|
+ } catch(e) {
|
|
|
}
|
|
|
};
|
|
|
- });
|
|
|
|
|
|
- module.filter('newlines', function() {
|
|
|
- return function (input) {
|
|
|
- return input.replace(/\n/g, '<br/>');
|
|
|
+ $scope.openEditor = function() {
|
|
|
};
|
|
|
- });
|
|
|
|
|
|
- module.filter('striphtml', function () {
|
|
|
- return function(text) {
|
|
|
- return text
|
|
|
- .replace(/&/g, '&')
|
|
|
- .replace(/>/g, '>')
|
|
|
- .replace(/</g, '<');
|
|
|
- };
|
|
|
});
|
|
|
-});
|
|
|
+});
|