diff --git a/src/kibana/apps/examples/index.js b/src/kibana/apps/examples/index.js index 0158ac66045e..34bf62ba25e8 100644 --- a/src/kibana/apps/examples/index.js +++ b/src/kibana/apps/examples/index.js @@ -5,7 +5,6 @@ define(function (require) { require('css!./styles/index.css'); var app = angular.module('app/examples', []); - kibana.useModule(app); // main controller for the examples app.controller('examples', function ($scope, $location, courier) { diff --git a/src/kibana/index.js b/src/kibana/index.js new file mode 100644 index 000000000000..91de1ed65380 --- /dev/null +++ b/src/kibana/index.js @@ -0,0 +1,90 @@ +/** + * main app level module + */ +define(function (require) { + + var angular = require('angular'); + var $ = require('jquery'); + var _ = require('lodash'); + var scopedRequire = require('require'); + var setup = require('./setup'); + var configFile = require('../config'); + + require('elasticsearch'); + require('angular-route'); + + var kibana = angular.module('kibana', []); + + var requiredAgularModules = [ + 'elasticsearch', + 'ngRoute', + 'kibana', + 'kibana/controllers', + 'kibana/directives', + 'kibana/factories', + 'kibana/services', + 'kibana/filters', + 'kibana/constants' + ]; + + requiredAgularModules.forEach(function (name) { + if (name.indexOf('kibana/') === 0) angular.module(name, []); + }); + + kibana.requires = requiredAgularModules; + kibana.value('configFile', configFile); + + kibana.config(function ($routeProvider) { + $routeProvider + .otherwise({ + redirectTo: '/' + configFile.defaultAppId + }); + + configFile.apps.forEach(function (app) { + $routeProvider.when('/' + app.id, { + templateUrl: '/kibana/apps/' + app.id + '/index.html' + }); + }); + }); + + setup(kibana, function (err) { + if (err) throw err; + + // once all of the required modules are loaded, bootstrap angular + function bootstrap() { + $(function () { + angular.bootstrap(document, requiredAgularModules); + }); + } + + // do some requirejs loading in parallel, otherwise we + // would have to track everything in the r.js optimization + // config + var out = 0; + function loaded() { + out ++; + return function () { + out--; + if (!out) { + // all of the callbacks have been called + bootstrap(); + } + }; + } + + // require global modules + require([ + 'controllers/kibana', + 'constants/base' + ], loaded()); + + // require each applications root module + // since these are created via .map the same operation + // must be done in the r.js optimizer config + require(configFile.apps.map(function (app) { + return 'apps/' + app.id + '/index'; + }), loaded()); + }); + + return kibana; +}); \ No newline at end of file diff --git a/src/kibana/main.js b/src/kibana/main.js deleted file mode 100644 index ed4c752baa2e..000000000000 --- a/src/kibana/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * main app level module - */ -define(function (require) { - - var angular = require('angular'); - var $ = require('jquery'); - var _ = require('lodash'); - var scopedRequire = require('require'); - var enableAsyncModules = require('utils/async_modules'); - var setup = require('./setup'); - var configFile = require('../config'); - - require('elasticsearch'); - require('angular-route'); - - var kibana = angular.module('kibana', []); - enableAsyncModules(kibana); - - var dependencies = [ - 'elasticsearch', - 'ngRoute', - 'kibana', - 'kibana/controllers', - 'kibana/directives', - 'kibana/factories', - 'kibana/services', - 'kibana/filters', - 'kibana/constants' - ]; - - dependencies.forEach(function (name) { - if (name.indexOf('kibana/') === 0) { - kibana.useModule(angular.module(name, [])); - } - }); - - kibana.requires = dependencies; - kibana.value('configFile', configFile); - - kibana.config(function ($routeProvider) { - $routeProvider - .otherwise({ - redirectTo: '/discover' - }); - - configFile.apps.forEach(function (app) { - var deps = {}; - deps['app/' + app.id] = function () { - return kibana.loadChildApp(app); - }; - - $routeProvider.when('/' + app.id, { - templateUrl: '/kibana/apps/' + app.id + '/index.html', - resolve: deps - }); - }); - }); - - kibana.run(function ($q) { - kibana.loadChildApp = function (app) { - var defer = $q.defer(); - - require([ - 'apps/' + app.id + '/index' - ], function () { - defer.resolve(); - delete require.onError; - }); - - require.onError = function () { - defer.reject(); - }; - - return defer.promise; - }; - }); - - setup(kibana, function (err) { - if (err) throw err; - - // load the elasticsearch service - require([ - 'controllers/kibana', - 'constants/base' - ], function () { - // bootstrap the app - $(function () { - angular - .bootstrap(document, dependencies); - }); - }); - }); - - return kibana; -}); \ No newline at end of file diff --git a/src/kibana/require.config.js b/src/kibana/require.config.js index abcab000aaee..eaf685c0939d 100644 --- a/src/kibana/require.config.js +++ b/src/kibana/require.config.js @@ -1,7 +1,7 @@ require.config({ baseUrl: 'kibana', paths: { - kibana: './main', + kibana: './index', courier: '../courier', angular: '../bower_components/angular/angular', 'angular-route': '../bower_components/angular-route/angular-route', diff --git a/src/kibana/utils/async_modules.js b/src/kibana/utils/async_modules.js deleted file mode 100644 index b41a27ba3e8a..000000000000 --- a/src/kibana/utils/async_modules.js +++ /dev/null @@ -1,58 +0,0 @@ -define(function (require) { - var _ = require('lodash'); - - /* TODO: this will probably fail to work when we have multiple apps. - * Might need to propogate registrations to multiple providers - */ - function enable(app) { - // keep a reference to each module defined before boot, so that - // after boot it can define new features. Also serves as a flag. - var preBootModules = []; - - // the functions needed to register different - // features defined after boot - var registerFns = {}; - - app.config(function ($controllerProvider, $compileProvider, $filterProvider, $provide) { - // this is how the internet told me to dynamically add modules :/ - registerFns = { - controller: $controllerProvider.register, - directive: $compileProvider.directive, - factory: $provide.factory, - service: $provide.service, - constant: $provide.constant, - value: $provide.value, - filter: $filterProvider.register - }; - }); - - /** - * Modules that need to register components within the application after - * bootstrapping is complete need to pass themselves to this method. - * - * @param {object} module - The Angular module - * @return {object} module - */ - app.useModule = function (module) { - if (preBootModules) { - preBootModules.push(module); - } else { - _.extend(module, registerFns); - } - return module; - }; - - /** - * Called after app is bootrapped to enable asyncModules - * @return {[type]} [description] - */ - app.run(function () { - _.each(preBootModules, function (module) { - _.extend(module, registerFns); - }); - preBootModules = false; - }); - } - - return enable; -}); \ No newline at end of file