app.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. 'bindonce',
  13. 'app/core/core',
  14. ],
  15. function (angular, $, _, appLevelRequire) {
  16. "use strict";
  17. var app = angular.module('grafana', []);
  18. var register_fns = {};
  19. var preBootModules = [];
  20. // This stores the grafana version number
  21. app.constant('grafanaVersion',"@grafanaVersion@");
  22. /**
  23. * Tells the application to watch the module, once bootstraping has completed
  24. * the modules controller, service, etc. functions will be overwritten to register directly
  25. * with this application.
  26. * @param {[type]} module [description]
  27. * @return {[type]} [description]
  28. */
  29. app.useModule = function (module) {
  30. if (preBootModules) {
  31. preBootModules.push(module);
  32. } else {
  33. _.extend(module, register_fns);
  34. }
  35. return module;
  36. };
  37. app.config(function($locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) {
  38. register_fns.controller = $controllerProvider.register;
  39. register_fns.directive = $compileProvider.directive;
  40. register_fns.factory = $provide.factory;
  41. register_fns.service = $provide.service;
  42. register_fns.filter = $filterProvider.register;
  43. });
  44. var apps_deps = [
  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, function (type) {
  57. var module_name = 'grafana.'+type;
  58. // create the module
  59. app.useModule(angular.module(module_name, []));
  60. // push it into the apps dependencies
  61. apps_deps.push(module_name);
  62. });
  63. var preBootRequires = [
  64. 'app/features/all',
  65. ];
  66. app.boot = function() {
  67. require(preBootRequires, function () {
  68. // disable tool tip animation
  69. $.fn.tooltip.defaults.animation = false;
  70. // bootstrap the app
  71. angular
  72. .element(document)
  73. .ready(function() {
  74. angular.bootstrap(document, apps_deps)
  75. .invoke(['$rootScope', function ($rootScope) {
  76. _.each(preBootModules, function (module) {
  77. _.extend(module, register_fns);
  78. });
  79. preBootModules = null;
  80. $rootScope.requireContext = appLevelRequire;
  81. $rootScope.require = function (deps, fn) {
  82. var $scope = this;
  83. $scope.requireContext(deps, function () {
  84. var deps = _.toArray(arguments);
  85. fn.apply($scope, deps);
  86. });
  87. };
  88. }]);
  89. });
  90. });
  91. };
  92. return app;
  93. });