| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- 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-other/angular-strap';
- import $ from 'jquery';
- import angular from 'angular';
- import config from 'app/core/config';
- // @ts-ignore ignoring this for now, otherwise we would have to extend _ interface with move
- import _ from 'lodash';
- import { addClassIfNoOverlayScrollbar } from 'app/core/utils/scrollbar';
- import { importPluginModule } from 'app/features/plugins/plugin_loader';
- // add move to lodash for backward compatabiltiy
- // @ts-ignore
- _.move = (array: [], fromIndex: number, toIndex: number) => {
- array.splice(toIndex, 0, array.splice(fromIndex, 1)[0]);
- return array;
- };
- import { coreModule, angularModules } from 'app/core/core_module';
- import { registerAngularDirectives } from 'app/core/core';
- import { setupAngularRoutes } from 'app/routes/routes';
- import 'app/routes/GrafanaCtrl';
- import 'app/features/all';
- import { setLocale } from '@grafana/data';
- import { setMarkdownOptions } from '@grafana/data';
- // import symlinked extensions
- const extensionsIndex = (require as any).context('.', true, /extensions\/index.ts/);
- extensionsIndex.keys().forEach((key: any) => {
- extensionsIndex(key);
- });
- export class GrafanaApp {
- registerFunctions: any;
- ngModuleDependencies: any[];
- preBootModules: any[] | null;
- constructor() {
- addClassIfNoOverlayScrollbar('no-overlay-scrollbar');
- this.preBootModules = [];
- this.registerFunctions = {};
- this.ngModuleDependencies = [];
- }
- useModule(module: angular.IModule) {
- if (this.preBootModules) {
- this.preBootModules.push(module);
- } else {
- _.extend(module, this.registerFunctions);
- }
- this.ngModuleDependencies.push(module.name);
- return module;
- }
- init() {
- const app = angular.module('grafana', []);
- setLocale(config.bootData.user.locale);
- setMarkdownOptions({ sanitize: !config.disableSanitizeHtml });
- app.config(
- (
- $locationProvider: angular.ILocationProvider,
- $controllerProvider: angular.IControllerProvider,
- $compileProvider: angular.ICompileProvider,
- $filterProvider: angular.IFilterProvider,
- $httpProvider: angular.IHttpProvider,
- $provide: angular.auto.IProvideService
- ) => {
- // 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',
- ($delegate: any, $templateCache: any) => {
- const get = $delegate.get;
- $delegate.get = (url: string, config: any) => {
- 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;
- },
- ]);
- }
- );
- this.ngModuleDependencies = [
- 'grafana.core',
- 'ngRoute',
- 'ngSanitize',
- '$strap.directives',
- 'ang-drag-drop',
- 'grafana',
- 'pasvaz.bindonce',
- 'react',
- ];
- // makes it possible to add dynamic stuff
- _.each(angularModules, (m: angular.IModule) => {
- this.useModule(m);
- });
- // register react angular wrappers
- coreModule.config(setupAngularRoutes);
- registerAngularDirectives();
- // disable tool tip animation
- $.fn.tooltip.defaults.animation = false;
- // bootstrap the app
- angular.bootstrap(document, this.ngModuleDependencies).invoke(() => {
- _.each(this.preBootModules, (module: angular.IModule) => {
- _.extend(module, this.registerFunctions);
- });
- this.preBootModules = null;
- });
- // Preload selected app plugins
- for (const modulePath of config.pluginsToPreload) {
- importPluginModule(modulePath);
- }
- }
- }
- export default new GrafanaApp();
|