@ -3,7 +3,9 @@ import _ from 'lodash';
import config from 'app/core/config' ;
import coreModule from 'app/core/core_module' ;
import { importPluginModule } from './plugin_loader' ;
import { AngularPanelPlugin , DataSourceApi } from '@grafana/ui/src/types' ;
import { importPanelPlugin , importDataSourcePlugin , importAppPlugin } from './plugin_loader' ;
/** @ngInject */
function pluginDirectiveLoader ( $compile , datasourceSrv , $rootScope , $q , $http , $templateCache , $timeout ) {
@ -67,14 +69,9 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
} ;
const panelInfo = config . panels [ scope . panel . type ] ;
let panelCtrlPromise = Promise . resolve ( null ) ;
if ( panelInfo ) {
panelCtrlPromise = importPluginModule ( panelInfo . module ) . then ( panelModule = > {
return panelModule . PanelCtrl ;
} ) ;
}
return panelCtrlPromise . then ( ( PanelCtrl : any ) = > {
return importPanelPlugin ( panelInfo . module ) . then ( panelPlugin = > {
const angularPanelPlugin = panelPlugin as AngularPanelPlugin ;
const PanelCtrl = angularPanelPlugin . components . PanelCtrl ;
componentInfo . Component = PanelCtrl ;
if ( ! PanelCtrl || PanelCtrl . registered ) {
@ -101,11 +98,12 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
} ) ;
}
function getModule ( scope , attrs ) {
function getModule ( scope : any , attrs : any ) {
switch ( attrs . type ) {
// QueryCtrl
case 'query-ctrl' : {
const ds = scope . ctrl . datasource ;
const ds : DataSourceApi = scope . ctrl . datasource as DataSourceApi ;
return $q . when ( {
baseUrl : ds.meta.baseUrl ,
name : 'query-ctrl-' + ds . meta . id ,
@ -115,12 +113,12 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
'panel-ctrl' : 'ctrl' ,
datasource : 'ctrl.datasource' ,
} ,
Component : ds.pluginExpor ts.QueryCtrl ,
Component : ds.componen ts.QueryCtrl ,
} ) ;
}
// Annotations
case 'annotations-query-ctrl' : {
return importPluginModule ( scope . ctrl . currentDatasource . meta . module ) . then ( dsModule = > {
return importDataSource Plugin ( scope . ctrl . currentDatasource . meta . module ) . then ( dsPlugin = > {
return {
baseUrl : scope.ctrl.currentDatasource.meta.baseUrl ,
name : 'annotations-query-ctrl-' + scope . ctrl . currentDatasource . meta . id ,
@ -129,60 +127,54 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
annotation : 'ctrl.currentAnnotation' ,
datasource : 'ctrl.currentDatasource' ,
} ,
Component : dsModule .AnnotationsQueryCtrl ,
Component : dsPlugin.components .AnnotationsQueryCtrl ,
} ;
} ) ;
}
// Datasource ConfigCtrl
case 'datasource-config-ctrl' : {
const dsMeta = scope . ctrl . datasourceMeta ;
return importPluginModule ( dsMeta . module ) . then (
( dsModule ) : any = > {
if ( ! dsModule . ConfigCtrl ) {
return { notFound : true } ;
}
scope . $watch (
'ctrl.current' ,
( ) = > {
scope . onModelChanged ( scope . ctrl . current ) ;
} ,
true
) ;
return importDataSourcePlugin ( dsMeta . module ) . then ( dsPlugin = > {
scope . $watch (
'ctrl.current' ,
( ) = > {
scope . onModelChanged ( scope . ctrl . current ) ;
} ,
true
) ;
return {
baseUrl : dsMeta.baseUrl ,
name : 'ds-config-' + dsMeta . id ,
bindings : { meta : '=' , current : '=' } ,
attrs : { meta : 'ctrl.datasourceMeta' , current : 'ctrl.current' } ,
Component : dsModule.ConfigCtrl ,
} ;
}
) ;
return {
baseUrl : dsMeta.baseUrl ,
name : 'ds-config-' + dsMeta . id ,
bindings : { meta : '=' , current : '=' } ,
attrs : { meta : 'ctrl.datasourceMeta' , current : 'ctrl.current' } ,
Component : dsPlugin.components.ConfigCtrl ,
} ;
} ) ;
}
// AppConfigCtrl
case 'app-config-ctrl' : {
const model = scope . ctrl . model ;
return importPluginModule ( model . module ) . then ( appModule = > {
return importApp Plugin ( model . module ) . then ( appPlugin = > {
return {
baseUrl : model.baseUrl ,
name : 'app-config-' + model . id ,
bindings : { appModel : '=' , appEditCtrl : '=' } ,
attrs : { 'app-model' : 'ctrl.model' , 'app-edit-ctrl' : 'ctrl' } ,
Component : appModule .ConfigCtrl ,
Component : appPlugin.components .ConfigCtrl ,
} ;
} ) ;
}
// App Page
case 'app-page' : {
const appModel = scope . ctrl . appModel ;
return importPluginModule ( appModel . module ) . then ( appModule = > {
return importApp Plugin ( appModel . module ) . then ( appPlugin = > {
return {
baseUrl : appModel.baseUrl ,
name : 'app-page-' + appModel . id + '-' + scope . ctrl . page . slug ,
bindings : { appModel : '=' } ,
attrs : { 'app-model' : 'ctrl.appModel' } ,
Component : appModule [ scope . ctrl . page . component ] ,
Component : appPlugin.pages [ scope . ctrl . page . component ] ,
} ;
} ) ;
}