diff --git a/public/app/core/services/dynamic_directive_srv.ts b/public/app/core/services/dynamic_directive_srv.ts
index 80ddd774c22..d6cc8a19184 100644
--- a/public/app/core/services/dynamic_directive_srv.ts
+++ b/public/app/core/services/dynamic_directive_srv.ts
@@ -28,7 +28,7 @@ class DynamicDirectiveSrv {
directiveInfo.fn.registered = true;
}
- this.addDirective(elem, directiveInfo.name, directiveInfo.scope || scope);
+ this.addDirective(elem, directiveInfo.name, scope);
}).catch(err => {
console.log('Plugin load:', err);
this.$rootScope.appEvent('alert-error', ['Plugin error', err.toString()]);
@@ -41,7 +41,14 @@ class DynamicDirectiveSrv {
scope: options.scope,
link: (scope, elem, attrs) => {
if (options.watch) {
- scope.$watch(options.watch,() => this.link(scope, elem, attrs, options));
+ let childScope = null;
+ scope.$watch(options.watch, () => {
+ if (childScope) {
+ childScope.$destroy();
+ }
+ childScope = scope.$new();
+ this.link(childScope, elem, attrs, options);
+ });
} else {
this.link(scope, elem, attrs, options);
}
diff --git a/public/app/features/annotations/editor_ctrl.js b/public/app/features/annotations/editor_ctrl.js
index 5a509fe4ca9..69bc07ae26d 100644
--- a/public/app/features/annotations/editor_ctrl.js
+++ b/public/app/features/annotations/editor_ctrl.js
@@ -31,10 +31,10 @@ function (angular, _, $) {
};
$scope.datasourceChanged = function() {
- $scope.currentDatasource = _.findWhere($scope.datasources, { name: $scope.currentAnnotation.datasource });
- if (!$scope.currentDatasource) {
- $scope.currentDatasource = $scope.datasources[0];
- }
+ datasourceSrv.get($scope.currentAnnotation.datasource).then(function(ds) {
+ $scope.currentDatasource = ds;
+ $scope.currentAnnotation.datasource = ds.name;
+ });
};
$scope.edit = function(annotation) {
@@ -50,7 +50,6 @@ function (angular, _, $) {
$scope.currentAnnotation = angular.copy(annotationDefaults);
$scope.currentIsNew = true;
$scope.datasourceChanged();
- $scope.currentAnnotation.datasource = $scope.currentDatasource.name;
};
$scope.update = function() {
diff --git a/public/app/features/panel/query_editor.ts b/public/app/features/panel/query_editor.ts
index d86c2894bb5..100cb7510ae 100644
--- a/public/app/features/panel/query_editor.ts
+++ b/public/app/features/panel/query_editor.ts
@@ -8,21 +8,13 @@ function metricsQueryEditor(dynamicDirectiveSrv, datasourceSrv) {
watch: "panel.datasource",
directive: scope => {
let datasource = scope.target.datasource || scope.panel.datasource;
- let editorScope = null;
-
return datasourceSrv.get(datasource).then(ds => {
- if (editorScope) {
- editorScope.$destroy();
- }
-
- editorScope = scope.$new();
- editorScope.datasource = ds;
+ scope.datasource = ds;
return System.import(ds.meta.module).then(dsModule => {
return {
name: 'metrics-query-editor-' + ds.meta.id,
fn: dsModule.metricsQueryEditor,
- scope: editorScope,
};
});
});
diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js
index a2a74ca1883..6f9f24ff867 100644
--- a/public/app/plugins/datasource/cloudwatch/datasource.js
+++ b/public/app/plugins/datasource/cloudwatch/datasource.js
@@ -3,7 +3,6 @@ define([
'lodash',
'moment',
'app/core/utils/datemath',
- './query_ctrl',
],
function (angular, _, moment, dateMath) {
'use strict';
diff --git a/public/app/plugins/datasource/cloudwatch/module.js b/public/app/plugins/datasource/cloudwatch/module.js
index 2af084b1989..b4e6c2b6ccb 100644
--- a/public/app/plugins/datasource/cloudwatch/module.js
+++ b/public/app/plugins/datasource/cloudwatch/module.js
@@ -1,33 +1,18 @@
define([
- 'angular',
'./datasource',
'./query_parameter_ctrl',
+ './query_ctrl',
],
-function (angular, CloudWatchDatasource) {
+function (CloudWatchDatasource) {
'use strict';
- var module = angular.module('grafana.directives');
-
- module.directive('metricQueryEditorCloudwatch', function() {
+ function metricsQueryEditor() {
return {controller: 'CloudWatchQueryCtrl', templateUrl: 'app/plugins/datasource/cloudwatch/partials/query.editor.html'};
- });
+ }
- module.directive('annotationsQueryEditorCloudwatch', function() {
+ function annotationsQueryEditor() {
return {templateUrl: 'app/plugins/datasource/cloudwatch/partials/annotations.editor.html'};
- });
-
- module.directive('cloudwatchQueryParameter', function() {
- return {
- templateUrl: 'app/plugins/datasource/cloudwatch/partials/query.parameter.html',
- controller: 'CloudWatchQueryParameterCtrl',
- restrict: 'E',
- scope: {
- target: "=",
- datasourceName: "@",
- onChange: "&",
- }
- };
- });
+ }
function configView() {
return {templateUrl: 'app/plugins/datasource/cloudwatch/partials/edit_view.html'};
@@ -36,5 +21,7 @@ function (angular, CloudWatchDatasource) {
return {
Datasource: CloudWatchDatasource,
configView: configView,
+ annotationsQueryEditor: annotationsQueryEditor,
+ metricsQueryEditor: metricsQueryEditor,
};
});
diff --git a/public/app/plugins/datasource/cloudwatch/partials/annotations.editor.html b/public/app/plugins/datasource/cloudwatch/partials/annotations.editor.html
index dfecb80032d..583a578134d 100644
--- a/public/app/plugins/datasource/cloudwatch/partials/annotations.editor.html
+++ b/public/app/plugins/datasource/cloudwatch/partials/annotations.editor.html
@@ -1 +1 @@
-