| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- define(['angular', 'jquery', 'lodash', 'moment'], function (angular, $, _, moment) {
- 'use strict';
- var module = angular.module('grafana.filters');
- module.filter('stringSort', function() {
- return function(input) {
- return input.sort();
- };
- });
- module.filter('slice', function() {
- return function(arr, start, end) {
- if(!_.isUndefined(arr)) {
- return arr.slice(start, end);
- }
- };
- });
- module.filter('stringify', function() {
- return function(arr) {
- if(_.isObject(arr) && !_.isArray(arr)) {
- return angular.toJson(arr);
- } else {
- return _.isNull(arr) ? null : arr.toString();
- }
- };
- });
- module.filter('moment', function() {
- return function(date,mode) {
- switch(mode) {
- case 'ago':
- return moment(date).fromNow();
- }
- return moment(date).fromNow();
- };
- });
- module.filter('noXml', function() {
- var noXml = function(text) {
- return _.isString(text)
- ? text
- .replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/'/g, ''')
- .replace(/"/g, '"')
- : text;
- };
- return function(text) {
- return _.isArray(text)
- ? _.map(text, noXml)
- : noXml(text);
- };
- });
- module.filter('interpolateTemplateVars', function(templateSrv) {
- function interpolateTemplateVars(text, scope) {
- if (scope.panel) {
- return templateSrv.replaceWithText(text, scope.panel.scopedVars);
- } else {
- return templateSrv.replaceWithText(text, scope.row.scopedVars);
- }
- }
- interpolateTemplateVars.$stateful = true;
- return interpolateTemplateVars;
- });
- });
|