app.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. });
  44. this.ngModuleDependencies = [
  45. 'grafana.core',
  46. 'ngRoute',
  47. 'ngSanitize',
  48. '$strap.directives',
  49. 'ang-drag-drop',
  50. 'grafana',
  51. 'pasvaz.bindonce',
  52. 'ui.bootstrap',
  53. 'ui.bootstrap.tpls',
  54. ];
  55. var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
  56. _.each(module_types, type => {
  57. var moduleName = 'grafana.' + type;
  58. this.useModule(angular.module(moduleName, []));
  59. });
  60. // makes it possible to add dynamic stuff
  61. this.useModule(coreModule);
  62. var preBootRequires = [System.import('app/features/all')];
  63. Promise.all(preBootRequires).then(() => {
  64. // disable tool tip animation
  65. $.fn.tooltip.defaults.animation = false;
  66. // bootstrap the app
  67. angular.bootstrap(document, this.ngModuleDependencies).invoke(() => {
  68. _.each(this.preBootModules, module => {
  69. _.extend(module, this.registerFunctions);
  70. });
  71. this.preBootModules = null;
  72. });
  73. }).catch(function(err) {
  74. console.log('Application boot failed:', err);
  75. });
  76. }
  77. }
  78. export default new GrafanaApp();