app.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. define([
  2. 'angular',
  3. 'jquery',
  4. 'lodash',
  5. 'require',
  6. 'bootstrap',
  7. 'angular-route',
  8. 'angular-sanitize',
  9. 'angular-strap',
  10. 'angular-dragdrop',
  11. 'angular-ui',
  12. 'extend-jquery',
  13. 'bindonce',
  14. 'app/core/core',
  15. ],
  16. function (angular, $, _, 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. return module;
  37. };
  38. app.config(function($locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) {
  39. register_fns.controller = $controllerProvider.register;
  40. register_fns.directive = $compileProvider.directive;
  41. register_fns.factory = $provide.factory;
  42. register_fns.service = $provide.service;
  43. register_fns.filter = $filterProvider.register;
  44. });
  45. var apps_deps = [
  46. 'grafana.core',
  47. 'ngRoute',
  48. 'ngSanitize',
  49. '$strap.directives',
  50. 'ang-drag-drop',
  51. 'grafana',
  52. 'pasvaz.bindonce',
  53. 'ui.bootstrap',
  54. 'ui.bootstrap.tpls',
  55. ];
  56. var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
  57. _.each(module_types, function (type) {
  58. var module_name = 'grafana.'+type;
  59. // create the module
  60. app.useModule(angular.module(module_name, []));
  61. // push it into the apps dependencies
  62. apps_deps.push(module_name);
  63. });
  64. var preBootRequires = [
  65. 'app/services/all',
  66. 'app/features/all',
  67. 'app/controllers/all',
  68. 'app/components/partials',
  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. });