From 91b48258f0f58ca181b6d06d012727d819a76626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 30 Jun 2014 09:10:32 +0200 Subject: [PATCH] Refactoring PR #511, Allow filter notation [[..]] in text panels --- CHANGELOG.md | 3 + src/app/panels/text/module.html | 7 +- src/app/panels/text/module.js | 116 +++++++++++++------------------- 3 files changed, 49 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c354cf3c37..61e9d0c1f43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ vNext +**New features or improvements** +- Allow [[..]] filter notation in all text panels (markdown/html/text) (Issue #511) + **Changes** - Use unix epoch for Graphite from/to for absolute time ranges (Closes #536) diff --git a/src/app/panels/text/module.html b/src/app/panels/text/module.html index 5b6c55c9954..3db0a30d031 100644 --- a/src/app/panels/text/module.html +++ b/src/app/panels/text/module.html @@ -1,9 +1,4 @@
- - - -

-

-

+

diff --git a/src/app/panels/text/module.js b/src/app/panels/text/module.js index 460a6c09919..65b50f3ee67 100644 --- a/src/app/panels/text/module.js +++ b/src/app/panels/text/module.js @@ -23,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" @@ -40,84 +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.renderText = function(content) { + content = content + .replace(/&/g, '&') + .replace(/>/g, '>') + .replace(/'); + + $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, '>') - .replace(/'); - }; - }); - - module.filter('striphtml', function () { - return function(text) { - return text - .replace(/&/g, '&') - .replace(/>/g, '>') - .replace(//g, '>') - .replace(/