tech(typescript): more testing and migration

This commit is contained in:
Torkel Ödegaard 2015-09-10 16:47:38 +02:00
parent 20407bca89
commit 84371f03b5
6 changed files with 92 additions and 82 deletions

View File

@ -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',
];

View File

@ -1,5 +1,6 @@
export * from './directives/cool_dir'
export * from './routes/module_loader'
export * from './filters/filters'

View 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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#39;')
.replace(/"/g, '&quot;')
: 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() {}

View File

@ -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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#39;')
.replace(/"/g, '&quot;')
: 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;
});
});

View File

@ -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

View File

@ -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',