app.js 2.9 KB

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