2021-04-21 08:38:00 +01:00
|
|
|
// eslint-disable-next-line lodash/import-scope
|
2017-12-20 12:33:33 +01:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
import * as sdk from 'app/plugins/sdk';
|
|
|
|
|
import kbn from 'app/core/utils/kbn';
|
2020-02-07 20:40:04 -05:00
|
|
|
import moment from 'moment'; // eslint-disable-line no-restricted-imports
|
2017-12-20 12:33:33 +01:00
|
|
|
import angular from 'angular';
|
|
|
|
|
import jquery from 'jquery';
|
2021-10-27 14:21:07 +01:00
|
|
|
import * as tslib from 'tslib';
|
2018-06-14 12:32:57 +01:00
|
|
|
|
|
|
|
|
// Experimental module exports
|
|
|
|
|
import prismjs from 'prismjs';
|
|
|
|
|
import slate from 'slate';
|
2019-07-18 08:03:04 +02:00
|
|
|
// @ts-ignore
|
2019-09-23 12:26:05 +01:00
|
|
|
import slateReact from '@grafana/slate-react';
|
2019-07-18 08:03:04 +02:00
|
|
|
// @ts-ignore
|
2018-06-14 12:32:57 +01:00
|
|
|
import slatePlain from 'slate-plain-serializer';
|
|
|
|
|
import react from 'react';
|
|
|
|
|
import reactDom from 'react-dom';
|
2019-11-01 09:05:18 -06:00
|
|
|
import * as reactRedux from 'react-redux';
|
|
|
|
|
import * as redux from 'redux';
|
2018-06-14 12:32:57 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
import config from 'app/core/config';
|
|
|
|
|
import TimeSeries from 'app/core/time_series2';
|
|
|
|
|
import TableModel from 'app/core/table_model';
|
2021-11-09 08:37:16 +01:00
|
|
|
import { coreModule } from 'app/angular/core_module';
|
|
|
|
|
import { appEvents, contextSrv } from 'app/core/core';
|
2017-12-20 12:33:33 +01:00
|
|
|
import * as flatten from 'app/core/utils/flatten';
|
|
|
|
|
import * as ticks from 'app/core/utils/ticks';
|
2019-04-12 09:45:22 -07:00
|
|
|
import { BackendSrv, getBackendSrv } from 'app/core/services/backend_srv';
|
2021-11-09 08:37:16 +01:00
|
|
|
import { promiseToDigest } from 'app/angular/promiseToDigest';
|
2017-12-20 12:33:33 +01:00
|
|
|
import impressionSrv from 'app/core/services/impression_srv';
|
|
|
|
|
import builtInPlugins from './built_in_plugins';
|
|
|
|
|
import * as d3 from 'd3';
|
2021-04-01 14:15:23 +02:00
|
|
|
import * as emotion from '@emotion/css';
|
2019-06-18 08:17:27 -07:00
|
|
|
import * as grafanaData from '@grafana/data';
|
2019-11-06 05:27:14 -08:00
|
|
|
import * as grafanaUIraw from '@grafana/ui';
|
2019-06-18 08:17:27 -07:00
|
|
|
import * as grafanaRuntime from '@grafana/runtime';
|
2021-10-13 08:53:36 +02:00
|
|
|
import { GenericDataSourcePlugin } from '../datasources/settings/PluginSettings';
|
2017-10-01 20:02:25 +02:00
|
|
|
|
2019-11-06 05:27:14 -08:00
|
|
|
// Help the 6.4 to 6.5 migration
|
|
|
|
|
// The base classes were moved from @grafana/ui to @grafana/data
|
|
|
|
|
// This exposes the same classes on both import paths
|
|
|
|
|
const grafanaUI = grafanaUIraw as any;
|
|
|
|
|
grafanaUI.PanelPlugin = grafanaData.PanelPlugin;
|
|
|
|
|
grafanaUI.DataSourcePlugin = grafanaData.DataSourcePlugin;
|
|
|
|
|
grafanaUI.AppPlugin = grafanaData.AppPlugin;
|
|
|
|
|
grafanaUI.DataSourceApi = grafanaData.DataSourceApi;
|
|
|
|
|
|
2017-10-17 12:14:34 +02:00
|
|
|
// rxjs
|
2019-09-19 16:27:31 +03:00
|
|
|
import * as rxjs from 'rxjs';
|
|
|
|
|
import * as rxjsOperators from 'rxjs/operators';
|
2021-05-19 19:10:21 +02:00
|
|
|
// routing
|
|
|
|
|
import * as reactRouter from 'react-router-dom';
|
2017-10-17 12:14:34 +02:00
|
|
|
|
2018-05-29 12:01:10 +02:00
|
|
|
// add cache busting
|
|
|
|
|
const bust = `?_cache=${Date.now()}`;
|
2019-07-18 08:03:04 +02:00
|
|
|
function locate(load: { address: string }) {
|
2018-05-29 12:01:10 +02:00
|
|
|
return load.address + bust;
|
|
|
|
|
}
|
2021-04-12 12:47:17 +02:00
|
|
|
|
2019-07-04 13:32:09 +02:00
|
|
|
grafanaRuntime.SystemJS.registry.set('plugin-loader', grafanaRuntime.SystemJS.newModule({ locate: locate }));
|
2018-05-29 12:01:10 +02:00
|
|
|
|
2019-07-04 13:32:09 +02:00
|
|
|
grafanaRuntime.SystemJS.config({
|
2017-12-20 12:33:33 +01:00
|
|
|
baseURL: 'public',
|
|
|
|
|
defaultExtension: 'js',
|
2017-10-01 20:02:25 +02:00
|
|
|
packages: {
|
2017-12-19 16:06:54 +01:00
|
|
|
plugins: {
|
2017-12-20 12:33:33 +01:00
|
|
|
defaultExtension: 'js',
|
|
|
|
|
},
|
2017-10-01 20:02:25 +02:00
|
|
|
},
|
|
|
|
|
map: {
|
2017-12-20 12:33:33 +01:00
|
|
|
text: 'vendor/plugin-text/text.js',
|
|
|
|
|
css: 'vendor/plugin-css/css.js',
|
2017-10-01 20:02:25 +02:00
|
|
|
},
|
2017-10-18 11:15:46 +02:00
|
|
|
meta: {
|
2018-07-12 13:16:41 +02:00
|
|
|
'/*': {
|
2017-11-01 10:45:20 +01:00
|
|
|
esModule: true,
|
2017-12-20 12:33:33 +01:00
|
|
|
authorization: true,
|
2018-05-29 12:01:10 +02:00
|
|
|
loader: 'plugin-loader',
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
|
|
|
|
},
|
2017-10-01 20:02:25 +02:00
|
|
|
});
|
|
|
|
|
|
2017-10-02 15:30:14 +02:00
|
|
|
function exposeToPlugin(name: string, component: any) {
|
2019-07-18 08:03:04 +02:00
|
|
|
grafanaRuntime.SystemJS.registerDynamic(name, [], true, (require: any, exports: any, module: { exports: any }) => {
|
2021-11-09 08:37:16 +01:00
|
|
|
console.log('registerDynamic callback', name);
|
2017-10-02 15:30:14 +02:00
|
|
|
module.exports = component;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 14:21:07 +01:00
|
|
|
exposeToPlugin('tslib', tslib);
|
2019-06-18 08:17:27 -07:00
|
|
|
exposeToPlugin('@grafana/data', grafanaData);
|
2018-12-21 12:27:43 +01:00
|
|
|
exposeToPlugin('@grafana/ui', grafanaUI);
|
2019-06-18 08:17:27 -07:00
|
|
|
exposeToPlugin('@grafana/runtime', grafanaRuntime);
|
2017-12-20 12:33:33 +01:00
|
|
|
exposeToPlugin('lodash', _);
|
|
|
|
|
exposeToPlugin('moment', moment);
|
|
|
|
|
exposeToPlugin('jquery', jquery);
|
|
|
|
|
exposeToPlugin('angular', angular);
|
|
|
|
|
exposeToPlugin('d3', d3);
|
2019-09-19 16:27:31 +03:00
|
|
|
exposeToPlugin('rxjs', rxjs);
|
|
|
|
|
exposeToPlugin('rxjs/operators', rxjsOperators);
|
2021-05-19 19:10:21 +02:00
|
|
|
exposeToPlugin('react-router-dom', reactRouter);
|
2017-10-26 12:07:23 +02:00
|
|
|
|
2018-06-14 12:32:57 +01:00
|
|
|
// Experimental modules
|
|
|
|
|
exposeToPlugin('prismjs', prismjs);
|
|
|
|
|
exposeToPlugin('slate', slate);
|
2019-09-23 12:26:05 +01:00
|
|
|
exposeToPlugin('@grafana/slate-react', slateReact);
|
2018-06-14 12:32:57 +01:00
|
|
|
exposeToPlugin('slate-plain-serializer', slatePlain);
|
|
|
|
|
exposeToPlugin('react', react);
|
|
|
|
|
exposeToPlugin('react-dom', reactDom);
|
2019-08-14 00:20:23 -07:00
|
|
|
exposeToPlugin('react-redux', reactRedux);
|
|
|
|
|
exposeToPlugin('redux', redux);
|
2019-07-05 13:33:42 +02:00
|
|
|
exposeToPlugin('emotion', emotion);
|
2021-04-01 14:15:23 +02:00
|
|
|
exposeToPlugin('@emotion/css', emotion);
|
2018-06-14 12:32:57 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
exposeToPlugin('app/features/dashboard/impression_store', {
|
2017-11-24 16:18:56 +01:00
|
|
|
impressions: impressionSrv,
|
2017-12-20 12:33:33 +01:00
|
|
|
__esModule: true,
|
2017-10-20 10:38:52 +02:00
|
|
|
});
|
|
|
|
|
|
2019-04-12 09:45:22 -07:00
|
|
|
/**
|
|
|
|
|
* NOTE: this is added temporarily while we explore a long term solution
|
|
|
|
|
* If you use this export, only use the:
|
|
|
|
|
* get/delete/post/patch/request methods
|
|
|
|
|
*/
|
|
|
|
|
exposeToPlugin('app/core/services/backend_srv', {
|
|
|
|
|
BackendSrv,
|
|
|
|
|
getBackendSrv,
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
exposeToPlugin('app/plugins/sdk', sdk);
|
2021-02-11 13:45:25 +01:00
|
|
|
exposeToPlugin('app/core/utils/datemath', grafanaData.dateMath);
|
2017-12-20 12:33:33 +01:00
|
|
|
exposeToPlugin('app/core/utils/flatten', flatten);
|
|
|
|
|
exposeToPlugin('app/core/utils/kbn', kbn);
|
|
|
|
|
exposeToPlugin('app/core/utils/ticks', ticks);
|
2020-04-01 13:32:12 +02:00
|
|
|
exposeToPlugin('app/core/utils/promiseToDigest', {
|
|
|
|
|
promiseToDigest: promiseToDigest,
|
|
|
|
|
__esModule: true,
|
|
|
|
|
});
|
2017-10-12 15:33:37 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
exposeToPlugin('app/core/config', config);
|
|
|
|
|
exposeToPlugin('app/core/time_series', TimeSeries);
|
|
|
|
|
exposeToPlugin('app/core/time_series2', TimeSeries);
|
|
|
|
|
exposeToPlugin('app/core/table_model', TableModel);
|
|
|
|
|
exposeToPlugin('app/core/app_events', appEvents);
|
|
|
|
|
exposeToPlugin('app/core/core_module', coreModule);
|
|
|
|
|
exposeToPlugin('app/core/core', {
|
2017-10-10 15:06:54 +02:00
|
|
|
coreModule: coreModule,
|
|
|
|
|
appEvents: appEvents,
|
|
|
|
|
contextSrv: contextSrv,
|
2017-12-20 12:33:33 +01:00
|
|
|
__esModule: true,
|
2017-10-10 15:06:54 +02:00
|
|
|
});
|
2017-10-01 20:02:25 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
import 'vendor/flot/jquery.flot';
|
|
|
|
|
import 'vendor/flot/jquery.flot.selection';
|
|
|
|
|
import 'vendor/flot/jquery.flot.time';
|
|
|
|
|
import 'vendor/flot/jquery.flot.stack';
|
|
|
|
|
import 'vendor/flot/jquery.flot.stackpercent';
|
|
|
|
|
import 'vendor/flot/jquery.flot.fillbelow';
|
|
|
|
|
import 'vendor/flot/jquery.flot.crosshair';
|
|
|
|
|
import 'vendor/flot/jquery.flot.dashes';
|
2018-07-18 12:05:45 +02:00
|
|
|
import 'vendor/flot/jquery.flot.gauge';
|
2017-10-01 20:02:25 +02:00
|
|
|
|
2017-10-12 15:33:37 +02:00
|
|
|
const flotDeps = [
|
2017-12-20 12:33:33 +01:00
|
|
|
'jquery.flot',
|
|
|
|
|
'jquery.flot.pie',
|
|
|
|
|
'jquery.flot.time',
|
|
|
|
|
'jquery.flot.fillbelow',
|
|
|
|
|
'jquery.flot.crosshair',
|
|
|
|
|
'jquery.flot.stack',
|
|
|
|
|
'jquery.flot.selection',
|
|
|
|
|
'jquery.flot.stackpercent',
|
|
|
|
|
'jquery.flot.events',
|
2018-07-18 12:05:45 +02:00
|
|
|
'jquery.flot.gauge',
|
2017-10-12 15:33:37 +02:00
|
|
|
];
|
2018-07-05 13:10:39 -07:00
|
|
|
|
2018-08-26 17:14:40 +02:00
|
|
|
for (const flotDep of flotDeps) {
|
2017-12-19 16:06:54 +01:00
|
|
|
exposeToPlugin(flotDep, { fakeDep: 1 });
|
2017-10-01 20:02:25 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-03 09:29:02 +01:00
|
|
|
export async function importPluginModule(path: string): Promise<any> {
|
2018-08-26 17:14:40 +02:00
|
|
|
const builtIn = builtInPlugins[path];
|
2017-10-01 20:02:25 +02:00
|
|
|
if (builtIn) {
|
2019-09-03 09:29:02 +01:00
|
|
|
// for handling dynamic imports
|
|
|
|
|
if (typeof builtIn === 'function') {
|
|
|
|
|
return await builtIn();
|
|
|
|
|
} else {
|
|
|
|
|
return Promise.resolve(builtIn);
|
|
|
|
|
}
|
2017-10-01 20:02:25 +02:00
|
|
|
}
|
2019-07-04 13:32:09 +02:00
|
|
|
return grafanaRuntime.SystemJS.import(path);
|
2017-10-01 20:02:25 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-11 13:45:25 +01:00
|
|
|
export function importDataSourcePlugin(meta: grafanaData.DataSourcePluginMeta): Promise<GenericDataSourcePlugin> {
|
2021-01-20 07:59:48 +01:00
|
|
|
return importPluginModule(meta.module).then((pluginExports) => {
|
2019-04-04 18:30:15 +02:00
|
|
|
if (pluginExports.plugin) {
|
2019-11-15 09:18:09 +00:00
|
|
|
const dsPlugin = pluginExports.plugin as GenericDataSourcePlugin;
|
2019-04-30 22:36:46 -07:00
|
|
|
dsPlugin.meta = meta;
|
|
|
|
|
return dsPlugin;
|
2019-04-04 18:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pluginExports.Datasource) {
|
2021-02-11 13:45:25 +01:00
|
|
|
const dsPlugin = new grafanaData.DataSourcePlugin<
|
|
|
|
|
grafanaData.DataSourceApi<grafanaData.DataQuery, grafanaData.DataSourceJsonData>,
|
|
|
|
|
grafanaData.DataQuery,
|
|
|
|
|
grafanaData.DataSourceJsonData
|
2019-11-15 09:18:09 +00:00
|
|
|
>(pluginExports.Datasource);
|
2019-04-04 18:30:15 +02:00
|
|
|
dsPlugin.setComponentsFromLegacyExports(pluginExports);
|
2019-04-30 22:36:46 -07:00
|
|
|
dsPlugin.meta = meta;
|
2019-04-04 18:30:15 +02:00
|
|
|
return dsPlugin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Error('Plugin module is missing DataSourcePlugin or Datasource constructor export');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 13:45:25 +01:00
|
|
|
export function importAppPlugin(meta: grafanaData.PluginMeta): Promise<grafanaData.AppPlugin> {
|
2021-01-20 07:59:48 +01:00
|
|
|
return importPluginModule(meta.module).then((pluginExports) => {
|
2021-02-11 13:45:25 +01:00
|
|
|
const plugin = pluginExports.plugin ? (pluginExports.plugin as grafanaData.AppPlugin) : new grafanaData.AppPlugin();
|
2019-05-20 13:05:23 -07:00
|
|
|
plugin.init(meta);
|
|
|
|
|
plugin.meta = meta;
|
2019-06-15 08:26:31 +02:00
|
|
|
plugin.setComponentsFromLegacyExports(pluginExports);
|
2019-04-30 22:36:46 -07:00
|
|
|
return plugin;
|
2019-04-04 18:30:15 +02:00
|
|
|
});
|
|
|
|
|
}
|