2015-12-17 21:27:34 +08:00
|
|
|
///<reference path="headers/common.d.ts" />
|
|
|
|
|
|
|
|
|
|
import 'bootstrap';
|
2016-01-20 18:20:15 +08:00
|
|
|
import 'vendor/filesaver';
|
2015-12-17 21:27:34 +08:00
|
|
|
import 'lodash-src';
|
|
|
|
|
import 'angular-strap';
|
|
|
|
|
import 'angular-route';
|
|
|
|
|
import 'angular-sanitize';
|
|
|
|
|
import 'angular-dragdrop';
|
|
|
|
|
import 'angular-bindonce';
|
|
|
|
|
import 'angular-ui';
|
2017-09-22 03:12:49 +08:00
|
|
|
import 'react';
|
|
|
|
|
import 'react-dom';
|
2017-09-20 23:44:23 +08:00
|
|
|
import 'ngreact';
|
2015-12-17 21:27:34 +08:00
|
|
|
|
2015-12-17 23:30:53 +08:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
import angular from 'angular';
|
2015-12-22 20:59:11 +08:00
|
|
|
import config from 'app/core/config';
|
|
|
|
|
import _ from 'lodash';
|
2016-07-05 22:08:44 +08:00
|
|
|
import moment from 'moment';
|
2016-01-14 05:31:29 +08:00
|
|
|
import {coreModule} from './core/core';
|
2015-12-17 21:27:34 +08:00
|
|
|
|
|
|
|
|
export class GrafanaApp {
|
|
|
|
|
registerFunctions: any;
|
|
|
|
|
ngModuleDependencies: any[];
|
|
|
|
|
preBootModules: any[];
|
|
|
|
|
|
2015-12-21 23:00:58 +08:00
|
|
|
constructor() {
|
|
|
|
|
this.preBootModules = [];
|
|
|
|
|
this.registerFunctions = {};
|
|
|
|
|
this.ngModuleDependencies = [];
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 21:27:34 +08:00
|
|
|
useModule(module) {
|
|
|
|
|
if (this.preBootModules) {
|
|
|
|
|
this.preBootModules.push(module);
|
|
|
|
|
} else {
|
|
|
|
|
_.extend(module, this.registerFunctions);
|
|
|
|
|
}
|
|
|
|
|
this.ngModuleDependencies.push(module.name);
|
|
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
var app = angular.module('grafana', []);
|
|
|
|
|
|
2016-07-05 23:59:43 +08:00
|
|
|
moment.locale(config.bootData.user.locale);
|
|
|
|
|
|
2016-06-06 23:18:10 +08:00
|
|
|
app.config(($locationProvider, $controllerProvider, $compileProvider, $filterProvider, $httpProvider, $provide) => {
|
2017-01-17 04:31:55 +08:00
|
|
|
// pre assing bindings before constructor calls
|
|
|
|
|
$compileProvider.preAssignBindingsEnabled(true);
|
2016-07-05 23:59:43 +08:00
|
|
|
|
2016-05-17 21:00:48 +08:00
|
|
|
if (config.buildInfo.env !== 'development') {
|
|
|
|
|
$compileProvider.debugInfoEnabled(false);
|
|
|
|
|
}
|
2016-05-04 17:46:06 +08:00
|
|
|
|
2016-07-05 23:59:43 +08:00
|
|
|
$httpProvider.useApplyAsync(true);
|
2016-07-05 22:08:44 +08:00
|
|
|
|
2015-12-17 21:27:34 +08:00
|
|
|
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;
|
2016-02-21 16:02:32 +08:00
|
|
|
|
2016-02-21 19:47:57 +08:00
|
|
|
$provide.decorator("$http", ["$delegate", "$templateCache", function($delegate, $templateCache) {
|
2016-02-21 16:02:32 +08:00
|
|
|
var get = $delegate.get;
|
|
|
|
|
$delegate.get = function(url, config) {
|
|
|
|
|
if (url.match(/\.html$/)) {
|
2016-02-21 19:47:57 +08:00
|
|
|
// some template's already exist in the cache
|
|
|
|
|
if (!$templateCache.get(url)) {
|
|
|
|
|
url += "?v=" + new Date().getTime();
|
|
|
|
|
}
|
2016-02-21 16:02:32 +08:00
|
|
|
}
|
|
|
|
|
return get(url, config);
|
|
|
|
|
};
|
|
|
|
|
return $delegate;
|
|
|
|
|
}]);
|
2015-12-17 21:27:34 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.ngModuleDependencies = [
|
|
|
|
|
'grafana.core',
|
|
|
|
|
'ngRoute',
|
|
|
|
|
'ngSanitize',
|
|
|
|
|
'$strap.directives',
|
|
|
|
|
'ang-drag-drop',
|
|
|
|
|
'grafana',
|
|
|
|
|
'pasvaz.bindonce',
|
2016-01-08 03:50:45 +08:00
|
|
|
'ui.bootstrap',
|
2015-12-18 17:28:00 +08:00
|
|
|
'ui.bootstrap.tpls',
|
2017-09-20 23:44:23 +08:00
|
|
|
'react'
|
2015-12-17 21:27:34 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
|
|
|
|
|
|
|
|
|
|
_.each(module_types, type => {
|
|
|
|
|
var moduleName = 'grafana.' + type;
|
|
|
|
|
this.useModule(angular.module(moduleName, []));
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-14 05:31:29 +08:00
|
|
|
// makes it possible to add dynamic stuff
|
|
|
|
|
this.useModule(coreModule);
|
|
|
|
|
|
2015-12-17 23:30:53 +08:00
|
|
|
var preBootRequires = [System.import('app/features/all')];
|
2015-12-17 21:27:34 +08:00
|
|
|
|
|
|
|
|
Promise.all(preBootRequires).then(() => {
|
|
|
|
|
// disable tool tip animation
|
|
|
|
|
$.fn.tooltip.defaults.animation = false;
|
|
|
|
|
// bootstrap the app
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-12-21 17:02:39 +08:00
|
|
|
}
|
2015-12-17 21:27:34 +08:00
|
|
|
|
2015-12-21 17:02:39 +08:00
|
|
|
export default new GrafanaApp();
|