app.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ///<reference path="headers/common.d.ts" />
  2. import 'bootstrap';
  3. import 'vendor/filesaver';
  4. import 'lodash-src';
  5. import 'angular-strap';
  6. import 'angular-route';
  7. import 'angular-sanitize';
  8. import 'angular-dragdrop';
  9. import 'angular-bindonce';
  10. import 'angular-ui';
  11. import $ from 'jquery';
  12. import angular from 'angular';
  13. import config from 'app/core/config';
  14. import _ from 'lodash';
  15. import moment from 'moment';
  16. import {coreModule} from './core/core';
  17. export class GrafanaApp {
  18. registerFunctions: any;
  19. ngModuleDependencies: any[];
  20. preBootModules: any[];
  21. constructor() {
  22. this.preBootModules = [];
  23. this.registerFunctions = {};
  24. this.ngModuleDependencies = [];
  25. }
  26. useModule(module) {
  27. if (this.preBootModules) {
  28. this.preBootModules.push(module);
  29. } else {
  30. _.extend(module, this.registerFunctions);
  31. }
  32. this.ngModuleDependencies.push(module.name);
  33. return module;
  34. }
  35. init() {
  36. var app = angular.module('grafana', []);
  37. moment.locale(config.bootData.user.locale);
  38. app.config(($locationProvider, $controllerProvider, $compileProvider, $filterProvider, $httpProvider, $provide) => {
  39. // pre assing bindings before constructor calls
  40. $compileProvider.preAssignBindingsEnabled(true);
  41. if (config.buildInfo.env !== 'development') {
  42. $compileProvider.debugInfoEnabled(false);
  43. }
  44. $httpProvider.useApplyAsync(true);
  45. this.registerFunctions.controller = $controllerProvider.register;
  46. this.registerFunctions.directive = $compileProvider.directive;
  47. this.registerFunctions.factory = $provide.factory;
  48. this.registerFunctions.service = $provide.service;
  49. this.registerFunctions.filter = $filterProvider.register;
  50. $provide.decorator("$http", ["$delegate", "$templateCache", function($delegate, $templateCache) {
  51. var get = $delegate.get;
  52. $delegate.get = function(url, config) {
  53. if (url.match(/\.html$/)) {
  54. // some template's already exist in the cache
  55. if (!$templateCache.get(url)) {
  56. url += "?v=" + new Date().getTime();
  57. }
  58. }
  59. return get(url, config);
  60. };
  61. return $delegate;
  62. }]);
  63. });
  64. this.ngModuleDependencies = [
  65. 'grafana.core',
  66. 'ngRoute',
  67. 'ngSanitize',
  68. '$strap.directives',
  69. 'ang-drag-drop',
  70. 'grafana',
  71. 'pasvaz.bindonce',
  72. 'ui.bootstrap',
  73. 'ui.bootstrap.tpls',
  74. ];
  75. var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
  76. _.each(module_types, type => {
  77. var moduleName = 'grafana.' + type;
  78. this.useModule(angular.module(moduleName, []));
  79. });
  80. // makes it possible to add dynamic stuff
  81. this.useModule(coreModule);
  82. var preBootRequires = [System.import('app/features/all')];
  83. Promise.all(preBootRequires).then(() => {
  84. // disable tool tip animation
  85. $.fn.tooltip.defaults.animation = false;
  86. // bootstrap the app
  87. angular.bootstrap(document, this.ngModuleDependencies).invoke(() => {
  88. _.each(this.preBootModules, module => {
  89. _.extend(module, this.registerFunctions);
  90. });
  91. this.preBootModules = null;
  92. });
  93. }).catch(function(err) {
  94. console.log('Application boot failed:', err);
  95. });
  96. }
  97. }
  98. export default new GrafanaApp();