grafana/public/app/app.ts

219 lines
6.9 KiB
TypeScript
Raw Normal View History

import 'core-js/stable';
import 'regenerator-runtime/runtime';
import 'whatwg-fetch'; // fetch polyfill needed for PhantomJs rendering
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'; // fetch polyfill needed for PhantomJs rendering
// @ts-ignore
import ttiPolyfill from 'tti-polyfill';
2017-12-20 05:33:33 -06:00
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
2017-12-20 05:33:33 -06:00
import _ from 'lodash';
import {
AppEvents,
setLocale,
setMarkdownOptions,
standardEditorsRegistry,
standardFieldConfigEditorRegistry,
standardTransformersRegistry,
DateTime: adding support to select preferred timezone for presentation of date and time values. (#23586) * added moment timezone package. * added a qnd way of selecting timezone. * added a first draft to display how it can be used. * fixed failing tests. * made moment.local to be in utc when running tests. * added tests to verify that the timeZone support works as expected. * Fixed so we use the formatter in the graph context menu. * changed so we will format d3 according to timeZone. * changed from class base to function based for easier consumption. * fixed so tests got green. * renamed to make it shorter. * fixed formatting in logRow. * removed unused value. * added time formatter to flot. * fixed failing tests. * changed so history will use the formatting with support for timezone. * added todo. * added so we append the correct abbrivation behind time. * added time zone abbrevation in timepicker. * adding timezone in rangeutil tool. * will use timezone when formatting range. * changed so we use new functions to format date so timezone is respected. * wip - dashboard settings. * changed so the time picker settings is in react. * added force update. * wip to get the react graph to work. * fixed formatting and parsing on the timepicker. * updated snap to be correct. * fixed so we format values properly in time picker. * make sure we pass timezone on all the proper places. * fixed so we use correct timeZone in explore. * fixed failing tests. * fixed so we always parse from local to selected timezone. * removed unused variable. * reverted back. * trying to fix issue with directive. * fixed issue. * fixed strict null errors. * fixed so we still can select default. * make sure we reads the time zone from getTimezone
2020-04-27 08:28:06 -05:00
setTimeZoneResolver,
} from '@grafana/data';
import appEvents from 'app/core/app_events';
import { addClassIfNoOverlayScrollbar } from 'app/core/utils/scrollbar';
import { checkBrowserCompatibility } from 'app/core/utils/browser';
import { importPluginModule } from 'app/features/plugins/plugin_loader';
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';
import { registerEchoBackend, setEchoSrv } from '@grafana/runtime';
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';
import { getStandardFieldConfigs, getStandardOptionEditors, getStandardTransformers } from '@grafana/ui';
import { getDefaultVariableAdapters, variableAdapters } from './features/variables/adapters';
import { initDevFeatures } from './dev';
2015-12-17 07:27:34 -06:00
// 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 symlinked extensions
const extensionsIndex = (require as any).context('.', true, /extensions\/index.ts/);
extensionsIndex.keys().forEach((key: any) => {
extensionsIndex(key);
});
if (process.env.NODE_ENV === 'development') {
initDevFeatures();
}
2015-12-17 07:27:34 -06:00
export class GrafanaApp {
registerFunctions: any;
ngModuleDependencies: any[];
preBootModules: any[] | null;
2015-12-17 07:27:34 -06:00
constructor() {
addClassIfNoOverlayScrollbar('no-overlay-scrollbar');
this.preBootModules = [];
this.registerFunctions = {};
this.ngModuleDependencies = [];
}
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() {
const app = angular.module('grafana', []);
2015-12-17 07:27:34 -06:00
setLocale(config.bootData.user.locale);
DateTime: adding support to select preferred timezone for presentation of date and time values. (#23586) * added moment timezone package. * added a qnd way of selecting timezone. * added a first draft to display how it can be used. * fixed failing tests. * made moment.local to be in utc when running tests. * added tests to verify that the timeZone support works as expected. * Fixed so we use the formatter in the graph context menu. * changed so we will format d3 according to timeZone. * changed from class base to function based for easier consumption. * fixed so tests got green. * renamed to make it shorter. * fixed formatting in logRow. * removed unused value. * added time formatter to flot. * fixed failing tests. * changed so history will use the formatting with support for timezone. * added todo. * added so we append the correct abbrivation behind time. * added time zone abbrevation in timepicker. * adding timezone in rangeutil tool. * will use timezone when formatting range. * changed so we use new functions to format date so timezone is respected. * wip - dashboard settings. * changed so the time picker settings is in react. * added force update. * wip to get the react graph to work. * fixed formatting and parsing on the timepicker. * updated snap to be correct. * fixed so we format values properly in time picker. * make sure we pass timezone on all the proper places. * fixed so we use correct timeZone in explore. * fixed failing tests. * fixed so we always parse from local to selected timezone. * removed unused variable. * reverted back. * trying to fix issue with directive. * fixed issue. * fixed strict null errors. * fixed so we still can select default. * make sure we reads the time zone from getTimezone
2020-04-27 08:28:06 -05:00
setTimeZoneResolver(() => config.bootData.user.timeZone);
setMarkdownOptions({ sanitize: !config.disableSanitizeHtml });
standardEditorsRegistry.setInit(getStandardOptionEditors);
standardFieldConfigEditorRegistry.setInit(getStandardFieldConfigs);
standardTransformersRegistry.setInit(getStandardTransformers);
variableAdapters.setInit(getDefaultVariableAdapters);
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;
},
]);
}
);
2015-12-17 07:27:34 -06:00
this.ngModuleDependencies = [
2017-12-20 05:33:33 -06:00
'grafana.core',
'ngRoute',
'ngSanitize',
'$strap.directives',
'ang-drag-drop',
'grafana',
'pasvaz.bindonce',
'react',
2015-12-17 07:27:34 -06:00
];
// makes it possible to add dynamic stuff
_.each(angularModules, (m: angular.IModule) => {
2018-10-14 09:31:20 -05:00
this.useModule(m);
});
2017-10-22 05:48:20 -05:00
// register react angular wrappers
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
angular.bootstrap(document, this.ngModuleDependencies).invoke(() => {
_.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;
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
});
// Preload selected app plugins
for (const modulePath of config.pluginsToPreload) {
importPluginModule(modulePath);
}
2015-12-17 07:27:34 -06:00
}
initEchoSrv() {
setEchoSrv(new Echo({ debug: process.env.NODE_ENV === 'development' }));
ttiPolyfill.getFirstConsistentlyInteractive().then((tti: any) => {
// Collecting paint metrics first
const paintMetrics = performance && performance.getEntriesByType ? performance.getEntriesByType('paint') : [];
for (const metric of paintMetrics) {
reportPerformance(metric.name, Math.round(metric.startTime + metric.duration));
}
reportPerformance('tti', tti);
});
registerEchoBackend(new PerformanceBackend({}));
window.addEventListener('DOMContentLoaded', () => {
reportPerformance('dcl', Math.round(performance.now()));
});
}
}
2015-12-17 07:27:34 -06:00
export default new GrafanaApp();