2017-12-19 23:06:54 +08:00
|
|
|
import "babel-polyfill";
|
|
|
|
|
import "file-saver";
|
|
|
|
|
import "lodash";
|
|
|
|
|
import "jquery";
|
|
|
|
|
import "angular";
|
|
|
|
|
import "angular-route";
|
|
|
|
|
import "angular-sanitize";
|
|
|
|
|
import "angular-native-dragdrop";
|
|
|
|
|
import "angular-bindonce";
|
|
|
|
|
import "react";
|
|
|
|
|
import "react-dom";
|
|
|
|
|
|
|
|
|
|
import "vendor/bootstrap/bootstrap";
|
|
|
|
|
import "vendor/angular-ui/ui-bootstrap-tpls";
|
|
|
|
|
import "vendor/angular-other/angular-strap";
|
|
|
|
|
|
|
|
|
|
import $ from "jquery";
|
|
|
|
|
import angular from "angular";
|
|
|
|
|
import config from "app/core/config";
|
|
|
|
|
import _ from "lodash";
|
|
|
|
|
import moment from "moment";
|
2017-12-21 00:24:04 +08:00
|
|
|
import { createStore } from "app/stores/store";
|
2017-10-02 02:02:25 +08:00
|
|
|
|
|
|
|
|
// add move to lodash for backward compatabiltiy
|
2017-12-19 23:06:54 +08:00
|
|
|
_.move = function(array, fromIndex, toIndex) {
|
2017-10-02 02:02:25 +08:00
|
|
|
array.splice(toIndex, 0, array.splice(fromIndex, 1)[0]);
|
|
|
|
|
return array;
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
import { coreModule, registerAngularDirectives } 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() {
|
2017-12-19 23:06:54 +08:00
|
|
|
var app = angular.module("grafana", []);
|
2015-12-17 21:27:34 +08:00
|
|
|
|
2016-07-05 23:59:43 +08:00
|
|
|
moment.locale(config.bootData.user.locale);
|
|
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
app.config(
|
|
|
|
|
(
|
|
|
|
|
$locationProvider,
|
|
|
|
|
$controllerProvider,
|
|
|
|
|
$compileProvider,
|
|
|
|
|
$filterProvider,
|
|
|
|
|
$httpProvider,
|
|
|
|
|
$provide
|
|
|
|
|
) => {
|
|
|
|
|
// pre assing bindings before constructor calls
|
|
|
|
|
$compileProvider.preAssignBindingsEnabled(true);
|
|
|
|
|
|
|
|
|
|
if (config.buildInfo.env !== "development") {
|
|
|
|
|
$compileProvider.debugInfoEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$httpProvider.useApplyAsync(true);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
$provide.decorator("$http", [
|
|
|
|
|
"$delegate",
|
|
|
|
|
"$templateCache",
|
|
|
|
|
function($delegate, $templateCache) {
|
|
|
|
|
var get = $delegate.get;
|
|
|
|
|
$delegate.get = function(url, config) {
|
|
|
|
|
if (url.match(/\.html$/)) {
|
|
|
|
|
// some template's already exist in the cache
|
|
|
|
|
if (!$templateCache.get(url)) {
|
|
|
|
|
url += "?v=" + new Date().getTime();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return get(url, config);
|
|
|
|
|
};
|
|
|
|
|
return $delegate;
|
2016-02-21 16:02:32 +08:00
|
|
|
}
|
2017-12-19 23:06:54 +08:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
);
|
2015-12-17 21:27:34 +08:00
|
|
|
|
|
|
|
|
this.ngModuleDependencies = [
|
2017-12-19 23:06:54 +08:00
|
|
|
"grafana.core",
|
|
|
|
|
"ngRoute",
|
|
|
|
|
"ngSanitize",
|
|
|
|
|
"$strap.directives",
|
|
|
|
|
"ang-drag-drop",
|
|
|
|
|
"grafana",
|
|
|
|
|
"pasvaz.bindonce",
|
|
|
|
|
"ui.bootstrap",
|
|
|
|
|
"ui.bootstrap.tpls",
|
|
|
|
|
"react"
|
2015-12-17 21:27:34 +08:00
|
|
|
];
|
|
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
var module_types = [
|
|
|
|
|
"controllers",
|
|
|
|
|
"directives",
|
|
|
|
|
"factories",
|
|
|
|
|
"services",
|
|
|
|
|
"filters",
|
|
|
|
|
"routes"
|
|
|
|
|
];
|
2015-12-17 21:27:34 +08:00
|
|
|
|
|
|
|
|
_.each(module_types, type => {
|
2017-12-19 23:06:54 +08:00
|
|
|
var moduleName = "grafana." + type;
|
2015-12-17 21:27:34 +08:00
|
|
|
this.useModule(angular.module(moduleName, []));
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-14 05:31:29 +08:00
|
|
|
// makes it possible to add dynamic stuff
|
|
|
|
|
this.useModule(coreModule);
|
|
|
|
|
|
2017-10-22 18:48:20 +08:00
|
|
|
// register react angular wrappers
|
|
|
|
|
registerAngularDirectives();
|
|
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
var preBootRequires = [System.import("app/features/all")];
|
2015-12-17 21:27:34 +08:00
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
Promise.all(preBootRequires)
|
|
|
|
|
.then(() => {
|
2017-12-21 00:24:04 +08:00
|
|
|
createStore();
|
|
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
// 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);
|
|
|
|
|
});
|
2015-12-17 21:27:34 +08:00
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
this.preBootModules = null;
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(function(err) {
|
|
|
|
|
console.log("Application boot failed:", err);
|
2015-12-17 21:27:34 +08:00
|
|
|
});
|
|
|
|
|
}
|
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();
|