2019-05-08 06:51:44 -05:00
|
|
|
/* tslint:disable:import-blacklist */
|
2017-12-20 05:33:33 -06:00
|
|
|
import System from 'systemjs/dist/system.js';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import * as sdk from 'app/plugins/sdk';
|
|
|
|
import kbn from 'app/core/utils/kbn';
|
|
|
|
import moment from 'moment';
|
|
|
|
import angular from 'angular';
|
|
|
|
import jquery from 'jquery';
|
2018-06-14 06:32:57 -05:00
|
|
|
|
|
|
|
// Experimental module exports
|
|
|
|
import prismjs from 'prismjs';
|
|
|
|
import slate from 'slate';
|
|
|
|
import slateReact from 'slate-react';
|
|
|
|
import slatePlain from 'slate-plain-serializer';
|
|
|
|
import react from 'react';
|
|
|
|
import reactDom from 'react-dom';
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
import config from 'app/core/config';
|
|
|
|
import TimeSeries from 'app/core/time_series2';
|
|
|
|
import TableModel from 'app/core/table_model';
|
|
|
|
import { coreModule, appEvents, contextSrv } from 'app/core/core';
|
2019-05-01 00:36:46 -05:00
|
|
|
import { DataSourcePlugin, AppPlugin, PanelPlugin, PluginMeta, DataSourcePluginMeta } from '@grafana/ui/src/types';
|
2019-05-06 05:36:42 -05:00
|
|
|
import * as datemath from '@grafana/ui/src/utils/datemath';
|
2017-12-20 05:33:33 -06:00
|
|
|
import * as fileExport from 'app/core/utils/file_export';
|
|
|
|
import * as flatten from 'app/core/utils/flatten';
|
|
|
|
import * as ticks from 'app/core/utils/ticks';
|
2019-04-12 11:45:22 -05:00
|
|
|
import { BackendSrv, getBackendSrv } from 'app/core/services/backend_srv';
|
2017-12-20 05:33:33 -06:00
|
|
|
import impressionSrv from 'app/core/services/impression_srv';
|
|
|
|
import builtInPlugins from './built_in_plugins';
|
|
|
|
import * as d3 from 'd3';
|
2019-06-18 10:17:27 -05:00
|
|
|
import * as grafanaData from '@grafana/data';
|
2018-12-20 09:56:46 -06:00
|
|
|
import * as grafanaUI from '@grafana/ui';
|
2019-06-18 10:17:27 -05:00
|
|
|
import * as grafanaRuntime from '@grafana/runtime';
|
2019-06-19 13:31:47 -05:00
|
|
|
export { loadPluginCss } from '@grafana/runtime';
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2017-10-17 05:14:34 -05:00
|
|
|
// rxjs
|
2018-12-14 08:47:23 -06:00
|
|
|
import { Observable, Subject } from 'rxjs';
|
2017-10-17 05:14:34 -05:00
|
|
|
|
2018-05-29 05:01:10 -05:00
|
|
|
// add cache busting
|
|
|
|
const bust = `?_cache=${Date.now()}`;
|
|
|
|
function locate(load) {
|
|
|
|
return load.address + bust;
|
|
|
|
}
|
|
|
|
System.registry.set('plugin-loader', System.newModule({ locate: locate }));
|
|
|
|
|
2017-10-01 13:02:25 -05:00
|
|
|
System.config({
|
2017-12-20 05:33:33 -06:00
|
|
|
baseURL: 'public',
|
|
|
|
defaultExtension: 'js',
|
2017-10-01 13:02:25 -05:00
|
|
|
packages: {
|
2017-12-19 09:06:54 -06:00
|
|
|
plugins: {
|
2017-12-20 05:33:33 -06:00
|
|
|
defaultExtension: 'js',
|
|
|
|
},
|
2017-10-01 13:02:25 -05:00
|
|
|
},
|
|
|
|
map: {
|
2017-12-20 05:33:33 -06:00
|
|
|
text: 'vendor/plugin-text/text.js',
|
|
|
|
css: 'vendor/plugin-css/css.js',
|
2017-10-01 13:02:25 -05:00
|
|
|
},
|
2017-10-18 04:15:46 -05:00
|
|
|
meta: {
|
2018-07-12 06:16:41 -05:00
|
|
|
'/*': {
|
2017-11-01 04:45:20 -05:00
|
|
|
esModule: true,
|
2017-12-20 05:33:33 -06:00
|
|
|
authorization: true,
|
2018-05-29 05:01:10 -05:00
|
|
|
loader: 'plugin-loader',
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
|
|
|
},
|
2017-10-01 13:02:25 -05:00
|
|
|
});
|
|
|
|
|
2017-10-02 08:30:14 -05:00
|
|
|
function exposeToPlugin(name: string, component: any) {
|
2018-09-04 07:27:03 -05:00
|
|
|
System.registerDynamic(name, [], true, (require, exports, module) => {
|
2017-10-02 08:30:14 -05:00
|
|
|
module.exports = component;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-18 10:17:27 -05:00
|
|
|
exposeToPlugin('@grafana/data', grafanaData);
|
2018-12-21 05:27:43 -06:00
|
|
|
exposeToPlugin('@grafana/ui', grafanaUI);
|
2019-06-18 10:17:27 -05:00
|
|
|
exposeToPlugin('@grafana/runtime', grafanaRuntime);
|
2017-12-20 05:33:33 -06:00
|
|
|
exposeToPlugin('lodash', _);
|
|
|
|
exposeToPlugin('moment', moment);
|
|
|
|
exposeToPlugin('jquery', jquery);
|
|
|
|
exposeToPlugin('angular', angular);
|
|
|
|
exposeToPlugin('d3', d3);
|
|
|
|
exposeToPlugin('rxjs/Subject', Subject);
|
|
|
|
exposeToPlugin('rxjs/Observable', Observable);
|
2019-05-18 10:31:25 -05:00
|
|
|
exposeToPlugin('rxjs', {
|
|
|
|
Subject: Subject,
|
|
|
|
Observable: Observable,
|
|
|
|
});
|
2017-10-26 05:07:23 -05:00
|
|
|
|
2018-06-14 06:32:57 -05:00
|
|
|
// Experimental modules
|
|
|
|
exposeToPlugin('prismjs', prismjs);
|
|
|
|
exposeToPlugin('slate', slate);
|
|
|
|
exposeToPlugin('slate-react', slateReact);
|
|
|
|
exposeToPlugin('slate-plain-serializer', slatePlain);
|
|
|
|
exposeToPlugin('react', react);
|
|
|
|
exposeToPlugin('react-dom', reactDom);
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
exposeToPlugin('app/features/dashboard/impression_store', {
|
2017-11-24 09:18:56 -06:00
|
|
|
impressions: impressionSrv,
|
2017-12-20 05:33:33 -06:00
|
|
|
__esModule: true,
|
2017-10-20 03:38:52 -05:00
|
|
|
});
|
|
|
|
|
2019-04-12 11:45:22 -05: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 05:33:33 -06:00
|
|
|
exposeToPlugin('app/plugins/sdk', sdk);
|
2019-05-09 08:27:52 -05:00
|
|
|
exposeToPlugin('app/core/utils/datemath', datemath);
|
2017-12-20 05:33:33 -06:00
|
|
|
exposeToPlugin('app/core/utils/file_export', fileExport);
|
|
|
|
exposeToPlugin('app/core/utils/flatten', flatten);
|
|
|
|
exposeToPlugin('app/core/utils/kbn', kbn);
|
|
|
|
exposeToPlugin('app/core/utils/ticks', ticks);
|
2017-10-12 08:33:37 -05:00
|
|
|
|
2017-12-20 05:33:33 -06: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 08:06:54 -05:00
|
|
|
coreModule: coreModule,
|
|
|
|
appEvents: appEvents,
|
|
|
|
contextSrv: contextSrv,
|
2017-12-20 05:33:33 -06:00
|
|
|
__esModule: true,
|
2017-10-10 08:06:54 -05:00
|
|
|
});
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2017-12-20 05:33:33 -06: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.pie';
|
|
|
|
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 05:05:45 -05:00
|
|
|
import 'vendor/flot/jquery.flot.gauge';
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2017-10-12 08:33:37 -05:00
|
|
|
const flotDeps = [
|
2017-12-20 05:33:33 -06: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 05:05:45 -05:00
|
|
|
'jquery.flot.gauge',
|
2017-10-12 08:33:37 -05:00
|
|
|
];
|
2018-07-05 15:10:39 -05:00
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
for (const flotDep of flotDeps) {
|
2017-12-19 09:06:54 -06:00
|
|
|
exposeToPlugin(flotDep, { fakeDep: 1 });
|
2017-10-01 13:02:25 -05:00
|
|
|
}
|
|
|
|
|
2019-04-11 01:02:22 -05:00
|
|
|
export function importPluginModule(path: string): Promise<any> {
|
2018-08-26 10:14:40 -05:00
|
|
|
const builtIn = builtInPlugins[path];
|
2017-10-01 13:02:25 -05:00
|
|
|
if (builtIn) {
|
|
|
|
return Promise.resolve(builtIn);
|
|
|
|
}
|
|
|
|
return System.import(path);
|
|
|
|
}
|
|
|
|
|
2019-05-01 00:36:46 -05:00
|
|
|
export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise<DataSourcePlugin<any>> {
|
|
|
|
return importPluginModule(meta.module).then(pluginExports => {
|
2019-04-04 11:30:15 -05:00
|
|
|
if (pluginExports.plugin) {
|
2019-05-01 00:36:46 -05:00
|
|
|
const dsPlugin = pluginExports.plugin as DataSourcePlugin<any>;
|
|
|
|
dsPlugin.meta = meta;
|
|
|
|
return dsPlugin;
|
2019-04-04 11:30:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pluginExports.Datasource) {
|
|
|
|
const dsPlugin = new DataSourcePlugin(pluginExports.Datasource);
|
|
|
|
dsPlugin.setComponentsFromLegacyExports(pluginExports);
|
2019-05-01 00:36:46 -05:00
|
|
|
dsPlugin.meta = meta;
|
2019-04-04 11:30:15 -05:00
|
|
|
return dsPlugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('Plugin module is missing DataSourcePlugin or Datasource constructor export');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-15 09:54:00 -05:00
|
|
|
export function importAppPlugin(meta: PluginMeta): Promise<AppPlugin> {
|
|
|
|
return importPluginModule(meta.module).then(pluginExports => {
|
2019-05-01 00:36:46 -05:00
|
|
|
const plugin = pluginExports.plugin ? (pluginExports.plugin as AppPlugin) : new AppPlugin();
|
2019-05-20 15:05:23 -05:00
|
|
|
plugin.init(meta);
|
|
|
|
plugin.meta = meta;
|
2019-06-15 01:26:31 -05:00
|
|
|
plugin.setComponentsFromLegacyExports(pluginExports);
|
2019-05-01 00:36:46 -05:00
|
|
|
return plugin;
|
2019-04-04 11:30:15 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-01 00:36:46 -05:00
|
|
|
import { getPanelPluginNotFound } from '../dashboard/dashgrid/PanelPluginNotFound';
|
|
|
|
|
|
|
|
interface PanelCache {
|
|
|
|
[key: string]: PanelPlugin;
|
|
|
|
}
|
|
|
|
const panelCache: PanelCache = {};
|
|
|
|
|
|
|
|
export function importPanelPlugin(id: string): Promise<PanelPlugin> {
|
|
|
|
const loaded = panelCache[id];
|
|
|
|
if (loaded) {
|
|
|
|
return Promise.resolve(loaded);
|
|
|
|
}
|
|
|
|
const meta = config.panels[id];
|
|
|
|
if (!meta) {
|
|
|
|
return Promise.resolve(getPanelPluginNotFound(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
return importPluginModule(meta.module)
|
|
|
|
.then(pluginExports => {
|
|
|
|
if (pluginExports.plugin) {
|
|
|
|
return pluginExports.plugin as PanelPlugin;
|
|
|
|
} else if (pluginExports.PanelCtrl) {
|
|
|
|
const plugin = new PanelPlugin(null);
|
|
|
|
plugin.angularPanelCtrl = pluginExports.PanelCtrl;
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
throw new Error('missing export: plugin or PanelCtrl');
|
|
|
|
})
|
|
|
|
.then(plugin => {
|
|
|
|
plugin.meta = meta;
|
|
|
|
return (panelCache[meta.id] = plugin);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
// TODO, maybe a different error plugin
|
|
|
|
console.log('Error loading panel plugin', err);
|
|
|
|
return getPanelPluginNotFound(id);
|
|
|
|
});
|
2019-04-04 11:30:15 -05:00
|
|
|
}
|