mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 09:33:34 -06:00
Refactoring PR #511, Allow filter notation [[..]] in text panels
This commit is contained in:
parent
2ac7b9dabf
commit
91b48258f0
@ -1,5 +1,8 @@
|
|||||||
vNext
|
vNext
|
||||||
|
|
||||||
|
**New features or improvements**
|
||||||
|
- Allow [[..]] filter notation in all text panels (markdown/html/text) (Issue #511)
|
||||||
|
|
||||||
**Changes**
|
**Changes**
|
||||||
- Use unix epoch for Graphite from/to for absolute time ranges (Closes #536)
|
- Use unix epoch for Graphite from/to for absolute time ranges (Closes #536)
|
||||||
|
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
<div ng-controller='text' ng-init="init()" style="min-height:{{panel.height || row.height}}" ng-dblclick="openEditor()">
|
<div ng-controller='text' ng-init="init()" style="min-height:{{panel.height || row.height}}" ng-dblclick="openEditor()">
|
||||||
<!--<p ng-style="panel.style" ng-bind-html-unsafe="panel.content | striphtml | newlines"></p>-->
|
<p ng-bind-html-unsafe="content">
|
||||||
<markdown ng-show="ready && panel.mode == 'markdown'" ng-bind-html-unsafe="panel.content | applymarkdown | applytemplate">
|
|
||||||
</markdown>
|
|
||||||
<p ng-show="panel.mode == 'text'" ng-style='panel.style' ng-bind-html-unsafe="panel.content | striphtml | newlines | applytemplate">
|
|
||||||
</p>
|
|
||||||
<p ng-show="panel.mode == 'html'" ng-bind-html-unsafe="panel.content | applytemplate">
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,7 +23,7 @@ function (angular, app, _, require) {
|
|||||||
var module = angular.module('kibana.panels.text', []);
|
var module = angular.module('kibana.panels.text', []);
|
||||||
app.useModule(module);
|
app.useModule(module);
|
||||||
|
|
||||||
module.controller('text', function($scope) {
|
module.controller('text', function($scope, filterSrv) {
|
||||||
|
|
||||||
$scope.panelMeta = {
|
$scope.panelMeta = {
|
||||||
description : "A static text panel that can use plain text, markdown, or (sanitized) HTML"
|
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.init = function() {
|
||||||
$scope.initBaseController(this, $scope);
|
$scope.initBaseController(this, $scope);
|
||||||
|
|
||||||
$scope.ready = false;
|
$scope.ready = false;
|
||||||
|
$scope.$on('refresh', $scope.render);
|
||||||
|
$scope.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.render = function() {
|
$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(/</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, '<');
|
||||||
|
|
||||||
|
$scope.updateContent(converter.makeHtml(text));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.updateContent = function(html) {
|
||||||
|
try {
|
||||||
|
$scope.content = filterSrv.applyTemplateToTarget(html);
|
||||||
|
|
||||||
|
if(!$scope.$$phase) {
|
||||||
|
$scope.$apply();
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openEditor = function() {
|
$scope.openEditor = function() {
|
||||||
//$scope.$emit('open-modal','paneleditor');
|
|
||||||
console.log('scope id', $scope.$id);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render_panel();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
module.filter('newlines', function() {
|
|
||||||
return function (input) {
|
|
||||||
return input.replace(/\n/g, '<br/>');
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
module.filter('striphtml', function () {
|
|
||||||
return function(text) {
|
|
||||||
return text
|
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/</g, '<');
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
module.filter('applytemplate', function(filterSrv) {
|
|
||||||
return function (input) {
|
|
||||||
return filterSrv.applyTemplateToTarget(input);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
module.filter('applymarkdown', function() {
|
|
||||||
return function (input) {
|
|
||||||
if(require.defined('./lib/showdown')) {
|
|
||||||
var Showdown = require('./lib/showdown');
|
|
||||||
var converter = new Showdown.converter();
|
|
||||||
var text = input.replace(/&/g, '&')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/</g, '<');
|
|
||||||
return converter.makeHtml(text);
|
|
||||||
} else {
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user