mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech(typescript): more testing and migration
This commit is contained in:
parent
20407bca89
commit
84371f03b5
@ -80,11 +80,11 @@ function (angular, $, _, appLevelRequire) {
|
||||
});
|
||||
|
||||
var preBootRequires = [
|
||||
'core/core',
|
||||
'services/all',
|
||||
'features/all',
|
||||
'controllers/all',
|
||||
'directives/all',
|
||||
'filters/all',
|
||||
'components/partials',
|
||||
'routes/all',
|
||||
];
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
export * from './directives/cool_dir'
|
||||
export * from './routes/module_loader'
|
||||
export * from './filters/filters'
|
||||
|
||||
|
||||
|
81
public/app/core/filters/filters.ts
Normal file
81
public/app/core/filters/filters.ts
Normal file
@ -0,0 +1,81 @@
|
||||
///<reference path="../../headers/require/require.d.ts" />
|
||||
///<reference path="../../headers/angularjs/angularjs.d.ts" />
|
||||
///<amd-dependency path="angular"/>
|
||||
///<amd-dependency path="config"/>
|
||||
///<amd-dependency path="moment"/>
|
||||
///<amd-dependency path="lodash"/>
|
||||
|
||||
var angular = require('angular');
|
||||
var jquery = require('jquery');
|
||||
var moment = require('moment');
|
||||
var _ = require('lodash');
|
||||
|
||||
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) {
|
||||
var interpolateTemplateVars : any = function (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;
|
||||
});
|
||||
|
||||
export function filters() {}
|
@ -1,72 +0,0 @@
|
||||
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;
|
||||
});
|
||||
|
||||
});
|
@ -15,14 +15,14 @@ module.exports = function(grunt) {
|
||||
'ngtemplates',
|
||||
'cssmin:build',
|
||||
'ngAnnotate:build',
|
||||
// 'requirejs:build',
|
||||
// 'concat:js',
|
||||
// 'clean:temp',
|
||||
// 'filerev',
|
||||
// 'remapFilerev',
|
||||
// 'usemin',
|
||||
// 'clean:temp',
|
||||
// 'uglify:genDir'
|
||||
'requirejs:build',
|
||||
'concat:js',
|
||||
'clean:temp',
|
||||
'filerev',
|
||||
'remapFilerev',
|
||||
'usemin',
|
||||
'clean:temp',
|
||||
'uglify:genDir'
|
||||
]);
|
||||
|
||||
// task to add [[.AppSubUrl]] to reved path
|
||||
|
@ -54,10 +54,10 @@ module.exports = function(config,grunt) {
|
||||
'jquery.flot',
|
||||
'angular-strap',
|
||||
'angular-dragdrop',
|
||||
'core/core',
|
||||
'services/all',
|
||||
'features/all',
|
||||
'directives/all',
|
||||
'filters/all',
|
||||
'controllers/all',
|
||||
'routes/all',
|
||||
'components/partials',
|
||||
|
Loading…
Reference in New Issue
Block a user