Просмотр исходного кода

tech(typescript): more testing and migration

Torkel Ödegaard 10 лет назад
Родитель
Сommit
84371f03b5

+ 1 - 1
public/app/app.js

@@ -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 - 0
public/app/core/core.ts

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

+ 81 - 0
public/app/core/filters/filters.ts

@@ -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() {}

+ 0 - 72
public/app/filters/all.js

@@ -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;
-  });
-
-});

+ 8 - 8
tasks/build_task.js

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

+ 1 - 1
tasks/options/requirejs.js

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