app.ts 3.2 KB

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