app.ts 3.0 KB

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