|
@@ -1,4 +1,4 @@
|
|
|
-import angular from 'angular';
|
|
|
|
|
|
|
+import angular, { IQService } from 'angular';
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
import config from 'app/core/config';
|
|
import config from 'app/core/config';
|
|
@@ -6,10 +6,19 @@ import coreModule from 'app/core/core_module';
|
|
|
|
|
|
|
|
import { DataSourceApi } from '@grafana/ui';
|
|
import { DataSourceApi } from '@grafana/ui';
|
|
|
import { importPanelPlugin, importDataSourcePlugin, importAppPlugin } from './plugin_loader';
|
|
import { importPanelPlugin, importDataSourcePlugin, importAppPlugin } from './plugin_loader';
|
|
|
|
|
+import DatasourceSrv from './datasource_srv';
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
/** @ngInject */
|
|
|
-function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $templateCache, $timeout) {
|
|
|
|
|
- function getTemplate(component) {
|
|
|
|
|
|
|
+function pluginDirectiveLoader(
|
|
|
|
|
+ $compile: any,
|
|
|
|
|
+ datasourceSrv: DatasourceSrv,
|
|
|
|
|
+ $rootScope: any,
|
|
|
|
|
+ $q: IQService,
|
|
|
|
|
+ $http: any,
|
|
|
|
|
+ $templateCache: any,
|
|
|
|
|
+ $timeout: any
|
|
|
|
|
+) {
|
|
|
|
|
+ function getTemplate(component: { template: any; templateUrl: any }) {
|
|
|
if (component.template) {
|
|
if (component.template) {
|
|
|
return $q.when(component.template);
|
|
return $q.when(component.template);
|
|
|
}
|
|
}
|
|
@@ -17,7 +26,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
if (cached) {
|
|
if (cached) {
|
|
|
return $q.when(cached);
|
|
return $q.when(cached);
|
|
|
}
|
|
}
|
|
|
- return $http.get(component.templateUrl).then(res => {
|
|
|
|
|
|
|
+ return $http.get(component.templateUrl).then((res: any) => {
|
|
|
return res.data;
|
|
return res.data;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -32,7 +41,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
return baseUrl + '/' + templateUrl;
|
|
return baseUrl + '/' + templateUrl;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getPluginComponentDirective(options) {
|
|
|
|
|
|
|
+ function getPluginComponentDirective(options: any) {
|
|
|
// handle relative template urls for plugin templates
|
|
// handle relative template urls for plugin templates
|
|
|
options.Component.templateUrl = relativeTemplateUrlToAbs(options.Component.templateUrl, options.baseUrl);
|
|
options.Component.templateUrl = relativeTemplateUrlToAbs(options.Component.templateUrl, options.baseUrl);
|
|
|
|
|
|
|
@@ -45,7 +54,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
controllerAs: 'ctrl',
|
|
controllerAs: 'ctrl',
|
|
|
bindToController: true,
|
|
bindToController: true,
|
|
|
scope: options.bindings,
|
|
scope: options.bindings,
|
|
|
- link: (scope, elem, attrs, ctrl) => {
|
|
|
|
|
|
|
+ link: (scope: any, elem: any, attrs: any, ctrl: any) => {
|
|
|
if (ctrl.link) {
|
|
if (ctrl.link) {
|
|
|
ctrl.link(scope, elem, attrs, ctrl);
|
|
ctrl.link(scope, elem, attrs, ctrl);
|
|
|
}
|
|
}
|
|
@@ -57,7 +66,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function loadPanelComponentInfo(scope, attrs) {
|
|
|
|
|
|
|
+ function loadPanelComponentInfo(scope: any, attrs: any) {
|
|
|
const componentInfo: any = {
|
|
const componentInfo: any = {
|
|
|
name: 'panel-plugin-' + scope.panel.type,
|
|
name: 'panel-plugin-' + scope.panel.type,
|
|
|
bindings: { dashboard: '=', panel: '=', row: '=' },
|
|
bindings: { dashboard: '=', panel: '=', row: '=' },
|
|
@@ -78,7 +87,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (PanelCtrl.templatePromise) {
|
|
if (PanelCtrl.templatePromise) {
|
|
|
- return PanelCtrl.templatePromise.then(res => {
|
|
|
|
|
|
|
+ return PanelCtrl.templatePromise.then((res: any) => {
|
|
|
return componentInfo;
|
|
return componentInfo;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -87,7 +96,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
PanelCtrl.templateUrl = relativeTemplateUrlToAbs(PanelCtrl.templateUrl, panelInfo.baseUrl);
|
|
PanelCtrl.templateUrl = relativeTemplateUrlToAbs(PanelCtrl.templateUrl, panelInfo.baseUrl);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- PanelCtrl.templatePromise = getTemplate(PanelCtrl).then(template => {
|
|
|
|
|
|
|
+ PanelCtrl.templatePromise = getTemplate(PanelCtrl).then((template: any) => {
|
|
|
PanelCtrl.templateUrl = null;
|
|
PanelCtrl.templateUrl = null;
|
|
|
PanelCtrl.template = `<grafana-panel ctrl="ctrl" class="panel-height-helper">${template}</grafana-panel>`;
|
|
PanelCtrl.template = `<grafana-panel ctrl="ctrl" class="panel-height-helper">${template}</grafana-panel>`;
|
|
|
return componentInfo;
|
|
return componentInfo;
|
|
@@ -97,7 +106,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getModule(scope: any, attrs: any) {
|
|
|
|
|
|
|
+ function getModule(scope: any, attrs: any): any {
|
|
|
switch (attrs.type) {
|
|
switch (attrs.type) {
|
|
|
// QueryCtrl
|
|
// QueryCtrl
|
|
|
case 'query-ctrl': {
|
|
case 'query-ctrl': {
|
|
@@ -189,7 +198,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function appendAndCompile(scope, elem, componentInfo) {
|
|
|
|
|
|
|
+ function appendAndCompile(scope: any, elem: JQuery, componentInfo: any) {
|
|
|
const child = angular.element(document.createElement(componentInfo.name));
|
|
const child = angular.element(document.createElement(componentInfo.name));
|
|
|
_.each(componentInfo.attrs, (value, key) => {
|
|
_.each(componentInfo.attrs, (value, key) => {
|
|
|
child.attr(key, value);
|
|
child.attr(key, value);
|
|
@@ -211,7 +220,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function registerPluginComponent(scope, elem, attrs, componentInfo) {
|
|
|
|
|
|
|
+ function registerPluginComponent(scope: any, elem: JQuery, attrs: any, componentInfo: any) {
|
|
|
if (componentInfo.notFound) {
|
|
if (componentInfo.notFound) {
|
|
|
elem.empty();
|
|
elem.empty();
|
|
|
return;
|
|
return;
|
|
@@ -235,12 +244,12 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
restrict: 'E',
|
|
restrict: 'E',
|
|
|
- link: (scope, elem, attrs) => {
|
|
|
|
|
|
|
+ link: (scope: any, elem: JQuery, attrs: any) => {
|
|
|
getModule(scope, attrs)
|
|
getModule(scope, attrs)
|
|
|
- .then(componentInfo => {
|
|
|
|
|
|
|
+ .then((componentInfo: any) => {
|
|
|
registerPluginComponent(scope, elem, attrs, componentInfo);
|
|
registerPluginComponent(scope, elem, attrs, componentInfo);
|
|
|
})
|
|
})
|
|
|
- .catch(err => {
|
|
|
|
|
|
|
+ .catch((err: any) => {
|
|
|
console.log('Plugin component error', err);
|
|
console.log('Plugin component error', err);
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|