2020-07-14 02:25:17 -05:00
|
|
|
import 'symbol-observable';
|
2020-01-30 03:54:11 -06:00
|
|
|
import 'core-js/stable';
|
|
|
|
import 'regenerator-runtime/runtime';
|
|
|
|
|
2020-01-22 01:15:31 -06:00
|
|
|
import 'whatwg-fetch'; // fetch polyfill needed for PhantomJs rendering
|
|
|
|
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'; // fetch polyfill needed for PhantomJs rendering
|
2020-01-30 03:54:11 -06:00
|
|
|
// @ts-ignore
|
|
|
|
import ttiPolyfill from 'tti-polyfill';
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
import 'file-saver';
|
|
|
|
import 'jquery';
|
2021-02-11 06:45:25 -06:00
|
|
|
import _ from 'lodash';
|
|
|
|
import angular from 'angular';
|
2017-12-20 05:33:33 -06:00
|
|
|
import 'angular-route';
|
|
|
|
import 'angular-sanitize';
|
|
|
|
import 'angular-bindonce';
|
|
|
|
import 'react';
|
|
|
|
import 'react-dom';
|
|
|
|
|
|
|
|
import 'vendor/bootstrap/bootstrap';
|
|
|
|
import 'vendor/angular-other/angular-strap';
|
|
|
|
import config from 'app/core/config';
|
2019-03-15 01:19:34 -05:00
|
|
|
// @ts-ignore ignoring this for now, otherwise we would have to extend _ interface with move
|
2020-03-26 15:48:46 -05:00
|
|
|
import {
|
|
|
|
AppEvents,
|
|
|
|
setLocale,
|
2020-11-18 08:10:32 -06:00
|
|
|
setTimeZoneResolver,
|
2020-03-26 15:48:46 -05:00
|
|
|
standardEditorsRegistry,
|
|
|
|
standardFieldConfigEditorRegistry,
|
2020-04-10 12:21:49 -05:00
|
|
|
standardTransformersRegistry,
|
2020-03-26 15:48:46 -05:00
|
|
|
} from '@grafana/data';
|
2019-10-23 03:30:31 -05:00
|
|
|
import appEvents from 'app/core/app_events';
|
|
|
|
import { checkBrowserCompatibility } from 'app/core/utils/browser';
|
2021-02-25 04:50:10 -06:00
|
|
|
import { arrayMove } from 'app/core/utils/arrayMove';
|
2019-04-11 01:02:22 -05:00
|
|
|
import { importPluginModule } from 'app/features/plugins/plugin_loader';
|
2020-01-22 01:15:31 -06:00
|
|
|
import { angularModules, coreModule } from 'app/core/core_module';
|
2018-10-14 09:31:20 -05:00
|
|
|
import { registerAngularDirectives } from 'app/core/core';
|
|
|
|
import { setupAngularRoutes } from 'app/routes/routes';
|
2020-01-22 01:15:31 -06:00
|
|
|
import { registerEchoBackend, setEchoSrv } from '@grafana/runtime';
|
2019-12-05 01:30:39 -06:00
|
|
|
import { Echo } from './core/services/echo/Echo';
|
|
|
|
import { reportPerformance } from './core/services/echo/EchoSrv';
|
|
|
|
import { PerformanceBackend } from './core/services/echo/backends/PerformanceBackend';
|
2018-10-14 09:31:20 -05:00
|
|
|
import 'app/routes/GrafanaCtrl';
|
|
|
|
import 'app/features/all';
|
2020-11-18 08:10:32 -06:00
|
|
|
import { getScrollbarWidth, getStandardFieldConfigs, getStandardOptionEditors } from '@grafana/ui';
|
2020-03-23 09:33:17 -05:00
|
|
|
import { getDefaultVariableAdapters, variableAdapters } from './features/variables/adapters';
|
2020-04-09 12:44:05 -05:00
|
|
|
import { initDevFeatures } from './dev';
|
2020-05-07 12:53:58 -05:00
|
|
|
import { getStandardTransformers } from 'app/core/utils/standardTransformers';
|
2020-11-12 05:29:43 -06:00
|
|
|
import { SentryEchoBackend } from './core/services/echo/backends/sentry/SentryBackend';
|
2020-11-03 06:18:10 -06:00
|
|
|
import { monkeyPatchInjectorWithPreAssignedBindings } from './core/injectorMonkeyPatch';
|
2020-11-18 08:10:32 -06:00
|
|
|
import { setVariableQueryRunner, VariableQueryRunner } from './features/variables/query/VariableQueryRunner';
|
2015-12-17 07:27:34 -06:00
|
|
|
|
2021-02-25 04:50:10 -06:00
|
|
|
// add move to lodash for backward compatabilty with plugins
|
2020-01-22 01:15:31 -06:00
|
|
|
// @ts-ignore
|
2021-02-25 04:50:10 -06:00
|
|
|
_.move = arrayMove;
|
2020-01-22 01:15:31 -06:00
|
|
|
|
2018-10-12 00:19:05 -05:00
|
|
|
// import symlinked extensions
|
|
|
|
const extensionsIndex = (require as any).context('.', true, /extensions\/index.ts/);
|
2019-03-15 01:19:34 -05:00
|
|
|
extensionsIndex.keys().forEach((key: any) => {
|
2018-10-12 00:19:05 -05:00
|
|
|
extensionsIndex(key);
|
2018-10-11 05:36:04 -05:00
|
|
|
});
|
|
|
|
|
2020-04-09 12:44:05 -05:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
initDevFeatures();
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:27:34 -06:00
|
|
|
export class GrafanaApp {
|
|
|
|
registerFunctions: any;
|
|
|
|
ngModuleDependencies: any[];
|
2019-08-05 05:07:35 -05:00
|
|
|
preBootModules: any[] | null;
|
2015-12-17 07:27:34 -06:00
|
|
|
|
2015-12-21 09:00:58 -06:00
|
|
|
constructor() {
|
|
|
|
this.preBootModules = [];
|
|
|
|
this.registerFunctions = {};
|
|
|
|
this.ngModuleDependencies = [];
|
|
|
|
}
|
|
|
|
|
2019-03-15 01:19:34 -05:00
|
|
|
useModule(module: angular.IModule) {
|
2015-12-17 07:27:34 -06:00
|
|
|
if (this.preBootModules) {
|
|
|
|
this.preBootModules.push(module);
|
|
|
|
} else {
|
|
|
|
_.extend(module, this.registerFunctions);
|
|
|
|
}
|
|
|
|
this.ngModuleDependencies.push(module.name);
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2018-08-26 14:52:57 -05:00
|
|
|
const app = angular.module('grafana', []);
|
2015-12-17 07:27:34 -06:00
|
|
|
|
2020-05-25 07:26:44 -05:00
|
|
|
addClassIfNoOverlayScrollbar();
|
2019-05-08 06:51:44 -05:00
|
|
|
setLocale(config.bootData.user.locale);
|
2020-06-26 02:08:15 -05:00
|
|
|
setTimeZoneResolver(() => config.bootData.user.timezone);
|
2016-07-05 10:59:43 -05:00
|
|
|
|
2020-03-26 15:48:46 -05:00
|
|
|
standardEditorsRegistry.setInit(getStandardOptionEditors);
|
2020-02-13 14:37:24 -06:00
|
|
|
standardFieldConfigEditorRegistry.setInit(getStandardFieldConfigs);
|
2020-04-10 12:21:49 -05:00
|
|
|
standardTransformersRegistry.setInit(getStandardTransformers);
|
2020-03-23 09:33:17 -05:00
|
|
|
variableAdapters.setInit(getDefaultVariableAdapters);
|
2021-01-06 14:40:32 -06:00
|
|
|
|
2020-11-18 08:10:32 -06:00
|
|
|
setVariableQueryRunner(new VariableQueryRunner());
|
2019-06-26 06:15:45 -05:00
|
|
|
|
2019-03-15 01:19:34 -05:00
|
|
|
app.config(
|
|
|
|
(
|
|
|
|
$controllerProvider: angular.IControllerProvider,
|
|
|
|
$compileProvider: angular.ICompileProvider,
|
|
|
|
$filterProvider: angular.IFilterProvider,
|
|
|
|
$httpProvider: angular.IHttpProvider,
|
|
|
|
$provide: angular.auto.IProvideService
|
|
|
|
) => {
|
|
|
|
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();
|
|
|
|
}
|
2017-12-21 01:39:31 -06:00
|
|
|
}
|
2019-03-15 01:19:34 -05:00
|
|
|
return get(url, config);
|
|
|
|
};
|
|
|
|
return $delegate;
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
);
|
2015-12-17 07:27:34 -06:00
|
|
|
|
|
|
|
this.ngModuleDependencies = [
|
2017-12-20 05:33:33 -06:00
|
|
|
'grafana.core',
|
|
|
|
'ngRoute',
|
|
|
|
'ngSanitize',
|
|
|
|
'$strap.directives',
|
|
|
|
'grafana',
|
|
|
|
'pasvaz.bindonce',
|
|
|
|
'react',
|
2015-12-17 07:27:34 -06:00
|
|
|
];
|
|
|
|
|
2016-01-13 15:31:29 -06:00
|
|
|
// makes it possible to add dynamic stuff
|
2019-03-15 01:19:34 -05:00
|
|
|
_.each(angularModules, (m: angular.IModule) => {
|
2018-10-14 09:31:20 -05:00
|
|
|
this.useModule(m);
|
|
|
|
});
|
2016-01-13 15:31:29 -06:00
|
|
|
|
2017-10-22 05:48:20 -05:00
|
|
|
// register react angular wrappers
|
2017-12-21 04:56:45 -06:00
|
|
|
coreModule.config(setupAngularRoutes);
|
2017-10-22 05:48:20 -05:00
|
|
|
registerAngularDirectives();
|
|
|
|
|
2018-10-14 09:31:20 -05:00
|
|
|
// disable tool tip animation
|
|
|
|
$.fn.tooltip.defaults.animation = false;
|
2015-12-17 07:27:34 -06:00
|
|
|
|
2018-10-14 09:31:20 -05:00
|
|
|
// bootstrap the app
|
2020-11-03 06:18:10 -06:00
|
|
|
const injector: any = angular.bootstrap(document, this.ngModuleDependencies);
|
|
|
|
|
|
|
|
injector.invoke(() => {
|
2019-03-15 01:19:34 -05:00
|
|
|
_.each(this.preBootModules, (module: angular.IModule) => {
|
2018-10-14 09:31:20 -05:00
|
|
|
_.extend(module, this.registerFunctions);
|
2015-12-17 07:27:34 -06:00
|
|
|
});
|
2018-10-14 09:31:20 -05:00
|
|
|
|
|
|
|
this.preBootModules = null;
|
2019-10-23 03:30:31 -05:00
|
|
|
|
|
|
|
if (!checkBrowserCompatibility()) {
|
|
|
|
setTimeout(() => {
|
|
|
|
appEvents.emit(AppEvents.alertWarning, [
|
|
|
|
'Your browser is not fully supported',
|
|
|
|
'A newer browser version is recommended',
|
|
|
|
]);
|
|
|
|
}, 1000);
|
|
|
|
}
|
2018-10-14 09:31:20 -05:00
|
|
|
});
|
2019-04-11 01:02:22 -05:00
|
|
|
|
2020-11-03 06:18:10 -06:00
|
|
|
monkeyPatchInjectorWithPreAssignedBindings(injector);
|
|
|
|
|
2019-04-11 01:02:22 -05:00
|
|
|
// Preload selected app plugins
|
|
|
|
for (const modulePath of config.pluginsToPreload) {
|
|
|
|
importPluginModule(modulePath);
|
|
|
|
}
|
2015-12-17 07:27:34 -06:00
|
|
|
}
|
2019-12-05 01:30:39 -06:00
|
|
|
|
|
|
|
initEchoSrv() {
|
|
|
|
setEchoSrv(new Echo({ debug: process.env.NODE_ENV === 'development' }));
|
|
|
|
|
|
|
|
ttiPolyfill.getFirstConsistentlyInteractive().then((tti: any) => {
|
|
|
|
// Collecting paint metrics first
|
2019-12-16 02:40:12 -06:00
|
|
|
const paintMetrics = performance && performance.getEntriesByType ? performance.getEntriesByType('paint') : [];
|
2019-12-05 01:30:39 -06:00
|
|
|
|
|
|
|
for (const metric of paintMetrics) {
|
|
|
|
reportPerformance(metric.name, Math.round(metric.startTime + metric.duration));
|
|
|
|
}
|
|
|
|
reportPerformance('tti', tti);
|
|
|
|
});
|
|
|
|
|
|
|
|
registerEchoBackend(new PerformanceBackend({}));
|
2020-11-17 01:49:39 -06:00
|
|
|
if (config.sentry.enabled) {
|
|
|
|
registerEchoBackend(
|
|
|
|
new SentryEchoBackend({
|
|
|
|
...config.sentry,
|
|
|
|
user: config.bootData.user,
|
|
|
|
buildInfo: config.buildInfo,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-12-05 01:30:39 -06:00
|
|
|
|
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
|
|
reportPerformance('dcl', Math.round(performance.now()));
|
|
|
|
});
|
|
|
|
}
|
2015-12-21 03:02:39 -06:00
|
|
|
}
|
2015-12-17 07:27:34 -06:00
|
|
|
|
2020-05-25 07:26:44 -05:00
|
|
|
function addClassIfNoOverlayScrollbar() {
|
|
|
|
if (getScrollbarWidth() > 0) {
|
|
|
|
document.body.classList.add('no-overlay-scrollbar');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 03:02:39 -06:00
|
|
|
export default new GrafanaApp();
|