app.ts 3.7 KB

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