mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech(systemjs): work on moving to systemjs
This commit is contained in:
parent
7ee290cc57
commit
74d7a946a7
@ -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;
|
||||
});
|
@ -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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user