app.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. if (config.buildInfo.env !== 'development') {
  40. $compileProvider.debugInfoEnabled(false);
  41. }
  42. $httpProvider.useApplyAsync(true);
  43. this.registerFunctions.controller = $controllerProvider.register;
  44. this.registerFunctions.directive = $compileProvider.directive;
  45. this.registerFunctions.factory = $provide.factory;
  46. this.registerFunctions.service = $provide.service;
  47. this.registerFunctions.filter = $filterProvider.register;
  48. $provide.decorator("$http", ["$delegate", "$templateCache", function($delegate, $templateCache) {
  49. var get = $delegate.get;
  50. $delegate.get = function(url, config) {
  51. if (url.match(/\.html$/)) {
  52. // some template's already exist in the cache
  53. if (!$templateCache.get(url)) {
  54. url += "?v=" + new Date().getTime();
  55. }
  56. }
  57. return get(url, config);
  58. };
  59. return $delegate;
  60. }]);
  61. });
  62. this.ngModuleDependencies = [
  63. 'grafana.core',
  64. 'ngRoute',
  65. 'ngSanitize',
  66. '$strap.directives',
  67. 'ang-drag-drop',
  68. 'grafana',
  69. 'pasvaz.bindonce',
  70. 'ui.bootstrap',
  71. 'ui.bootstrap.tpls',
  72. ];
  73. var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
  74. _.each(module_types, type => {
  75. var moduleName = 'grafana.' + type;
  76. this.useModule(angular.module(moduleName, []));
  77. });
  78. // makes it possible to add dynamic stuff
  79. this.useModule(coreModule);
  80. var preBootRequires = [System.import('app/features/all')];
  81. Promise.all(preBootRequires).then(() => {
  82. // disable tool tip animation
  83. $.fn.tooltip.defaults.animation = false;
  84. // bootstrap the app
  85. angular.bootstrap(document, this.ngModuleDependencies).invoke(() => {
  86. _.each(this.preBootModules, module => {
  87. _.extend(module, this.registerFunctions);
  88. });
  89. this.preBootModules = null;
  90. });
  91. }).catch(function(err) {
  92. console.log('Application boot failed:', err);
  93. });
  94. }
  95. }
  96. export default new GrafanaApp();