app.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. define([
  2. 'angular',
  3. 'jquery',
  4. 'lodash',
  5. 'app/core/config',
  6. 'require',
  7. 'bootstrap',
  8. 'angular-route',
  9. 'angular-sanitize',
  10. 'angular-strap',
  11. 'angular-dragdrop',
  12. 'angular-ui',
  13. 'bindonce',
  14. 'app/core/core',
  15. ],
  16. function (angular, $, _, config, appLevelRequire) {
  17. "use strict";
  18. var app = angular.module('grafana', []);
  19. var register_fns = {};
  20. var preBootModules = [];
  21. // This stores the grafana version number
  22. app.constant('grafanaVersion',"@grafanaVersion@");
  23. /**
  24. * Tells the application to watch the module, once bootstraping has completed
  25. * the modules controller, service, etc. functions will be overwritten to register directly
  26. * with this application.
  27. * @param {[type]} module [description]
  28. * @return {[type]} [description]
  29. */
  30. app.useModule = function (module) {
  31. if (preBootModules) {
  32. preBootModules.push(module);
  33. } else {
  34. _.extend(module, register_fns);
  35. }
  36. // push it into the apps dependencies
  37. apps_deps.push(module.name);
  38. return module;
  39. };
  40. app.config(function($locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) {
  41. register_fns.controller = $controllerProvider.register;
  42. register_fns.directive = $compileProvider.directive;
  43. register_fns.factory = $provide.factory;
  44. register_fns.service = $provide.service;
  45. register_fns.filter = $filterProvider.register;
  46. });
  47. var apps_deps = [
  48. 'grafana.core',
  49. 'ngRoute',
  50. 'ngSanitize',
  51. '$strap.directives',
  52. 'ang-drag-drop',
  53. 'grafana',
  54. 'pasvaz.bindonce',
  55. 'ui.bootstrap',
  56. 'ui.bootstrap.tpls',
  57. ];
  58. var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
  59. _.each(module_types, function (type) {
  60. var module_name = 'grafana.'+type;
  61. // create the module
  62. app.useModule(angular.module(module_name, []));
  63. });
  64. var preBootRequires = ['app/features/all'];
  65. var pluginModules = config.bootData.pluginModules || [];
  66. // add plugin modules
  67. for (var i = 0; i < pluginModules.length; i++) {
  68. preBootRequires.push(pluginModules[i]);
  69. }
  70. app.boot = function() {
  71. require(preBootRequires, function () {
  72. // disable tool tip animation
  73. $.fn.tooltip.defaults.animation = false;
  74. // bootstrap the app
  75. angular
  76. .element(document)
  77. .ready(function() {
  78. angular.bootstrap(document, apps_deps)
  79. .invoke(['$rootScope', function ($rootScope) {
  80. _.each(preBootModules, function (module) {
  81. _.extend(module, register_fns);
  82. });
  83. preBootModules = null;
  84. $rootScope.requireContext = appLevelRequire;
  85. $rootScope.require = function (deps, fn) {
  86. var $scope = this;
  87. $scope.requireContext(deps, function () {
  88. var deps = _.toArray(arguments);
  89. fn.apply($scope, deps);
  90. });
  91. };
  92. }]);
  93. });
  94. });
  95. };
  96. return app;
  97. });