From 74d7a946a76a3cc554130eb8583f0fc6abd94e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 15 Dec 2015 19:10:08 +0100 Subject: [PATCH] tech(systemjs): work on moving to systemjs --- public/app/_old_app.js | 112 ----------------------------------------- public/app/app.ts | 43 ++++++++++------ 2 files changed, 28 insertions(+), 127 deletions(-) delete mode 100644 public/app/_old_app.js diff --git a/public/app/_old_app.js b/public/app/_old_app.js deleted file mode 100644 index b8d6579dea1..00000000000 --- a/public/app/_old_app.js +++ /dev/null @@ -1,112 +0,0 @@ -define([ - 'angular', - 'jquery', - 'lodash', - 'app/core/config', - 'require', - 'bootstrap', - 'angular-route', - 'angular-sanitize', - 'angular-strap', - 'angular-dragdrop', - 'angular-ui', - 'bindonce', - 'app/core/core', -], -function (angular, $, _, config, appLevelRequire) { - "use strict"; - - var app = angular.module('grafana', []); - var register_fns = {}; - var preBootModules = []; - - // This stores the grafana version number - app.constant('grafanaVersion',"@grafanaVersion@"); - - /** - * Tells the application to watch the module, once bootstraping has completed - * the modules controller, service, etc. functions will be overwritten to register directly - * with this application. - * @param {[type]} module [description] - * @return {[type]} [description] - */ - app.useModule = function (module) { - if (preBootModules) { - preBootModules.push(module); - } else { - _.extend(module, register_fns); - } - // push it into the apps dependencies - apps_deps.push(module.name); - return module; - }; - - app.config(function($locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) { - register_fns.controller = $controllerProvider.register; - register_fns.directive = $compileProvider.directive; - register_fns.factory = $provide.factory; - register_fns.service = $provide.service; - register_fns.filter = $filterProvider.register; - }); - - var apps_deps = [ - 'grafana.core', - 'ngRoute', - 'ngSanitize', - '$strap.directives', - 'ang-drag-drop', - 'grafana', - 'pasvaz.bindonce', - 'ui.bootstrap', - 'ui.bootstrap.tpls', - ]; - - var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes']; - - _.each(module_types, function (type) { - var module_name = 'grafana.'+type; - // create the module - app.useModule(angular.module(module_name, [])); - }); - - var preBootRequires = ['app/features/all']; - var pluginModules = config.bootData.pluginModules || []; - - // add plugin modules - for (var i = 0; i < pluginModules.length; i++) { - preBootRequires.push(pluginModules[i]); - } - - app.boot = function() { - require(preBootRequires, function () { - - // disable tool tip animation - $.fn.tooltip.defaults.animation = false; - - // bootstrap the app - angular - .element(document) - .ready(function() { - angular.bootstrap(document, apps_deps) - .invoke(['$rootScope', function ($rootScope) { - _.each(preBootModules, function (module) { - _.extend(module, register_fns); - }); - - preBootModules = null; - - $rootScope.requireContext = appLevelRequire; - $rootScope.require = function (deps, fn) { - var $scope = this; - $scope.requireContext(deps, function () { - var deps = _.toArray(arguments); - fn.apply($scope, deps); - }); - }; - }]); - }); - }); - }; - - return app; -}); diff --git a/public/app/app.ts b/public/app/app.ts index c1438392116..81a9e32e134 100644 --- a/public/app/app.ts +++ b/public/app/app.ts @@ -20,27 +20,37 @@ import angular = require('angular'); import config = require('app/core/config'); class GrafanaApp { - register_fns: any = {}; + registerFunctions: any; + ngModuleDependencies: any[]; + preBootModules: any[]; useModule(module) { - _.extend(module, this.register_fns); + if (this.preBootModules) { + this.preBootModules.push(module); + } else { + _.extend(module, this.registerFunctions); + } + this.ngModuleDependencies.push(module.name); return module; } init() { + this.registerFunctions = {}; + this.preBootModules = []; + var app = angular.module('grafana', []); app.constant('grafanaVersion', "@grafanaVersion@"); app.config(($locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) => { console.log('app config'); - this.register_fns.controller = $controllerProvider.register; - this.register_fns.directive = $compileProvider.directive; - this.register_fns.factory = $provide.factory; - this.register_fns.service = $provide.service; - this.register_fns.filter = $filterProvider.register; + this.registerFunctions.controller = $controllerProvider.register; + this.registerFunctions.directive = $compileProvider.directive; + this.registerFunctions.factory = $provide.factory; + this.registerFunctions.service = $provide.service; + this.registerFunctions.filter = $filterProvider.register; }); - var apps_deps = [ + this.ngModuleDependencies = [ 'grafana.core', 'ngRoute', 'ngSanitize', @@ -54,9 +64,8 @@ class GrafanaApp { var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes']; _.each(module_types, type => { - var module_name = 'grafana.' + type; - this.useModule(angular.module(module_name, [])); - apps_deps.push(module_name); + var moduleName = 'grafana.' + type; + this.useModule(angular.module(moduleName, [])); }); var preBootRequires = [System.import('app/features/all')]; @@ -67,13 +76,17 @@ class GrafanaApp { preBootRequires.push(System.import(pluginModules[i])); } - Promise.all(preBootRequires).then(function() { + Promise.all(preBootRequires).then(() => { // disable tool tip animation $.fn.tooltip.defaults.animation = false; // bootstrap the app - var asd = angular.bootstrap(document, apps_deps).invoke(['$rootScope', function ($rootScope) { - console.log('bootstrap'); - }]); + angular.bootstrap(document, this.ngModuleDependencies).invoke(() => { + _.each(this.preBootModules, module => { + _.extend(module, this.registerFunctions); + }); + + this.preBootModules = null; + }); }).catch(function(err) { console.log('Application boot failed: ' + err); });