From 8699d49f93b49c2bf1b348c3bd04fab28f286b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 14 Jan 2016 15:15:45 +0100 Subject: [PATCH] feat(plugins): updated cloudwatch to new plugin style --- .../core/services/dynamic_directive_srv.ts | 11 +++++-- .../app/features/annotations/editor_ctrl.js | 9 +++--- public/app/features/panel/query_editor.ts | 10 +------ .../datasource/cloudwatch/datasource.js | 1 - .../plugins/datasource/cloudwatch/module.js | 29 +++++-------------- .../partials/annotations.editor.html | 2 +- .../cloudwatch/partials/query.editor.html | 2 +- .../cloudwatch/query_parameter_ctrl.js | 22 ++++++++++---- .../partials/annotations.editor.html | 14 ++++----- 9 files changed, 47 insertions(+), 53 deletions(-) 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 @@ - + diff --git a/public/app/plugins/datasource/cloudwatch/partials/query.editor.html b/public/app/plugins/datasource/cloudwatch/partials/query.editor.html index d2dd9d84436..09ac6279c12 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/query.editor.html +++ b/public/app/plugins/datasource/cloudwatch/partials/query.editor.html @@ -35,4 +35,4 @@
- + diff --git a/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.js b/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.js index 0ed23aff205..3be1f0d5a01 100644 --- a/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.js +++ b/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.js @@ -7,6 +7,19 @@ function (angular, _) { var module = angular.module('grafana.controllers'); + module.directive('cloudwatchQueryParameter', function() { + return { + templateUrl: 'app/plugins/datasource/cloudwatch/partials/query.parameter.html', + controller: 'CloudWatchQueryParameterCtrl', + restrict: 'E', + scope: { + target: "=", + datasource: "=", + onChange: "&", + } + }; + }); + module.controller('CloudWatchQueryParameterCtrl', function($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) { $scope.init = function() { @@ -38,12 +51,9 @@ function (angular, _) { $scope.removeDimSegment = uiSegmentSrv.newSegment({fake: true, value: '-- remove dimension --'}); $scope.removeStatSegment = uiSegmentSrv.newSegment({fake: true, value: '-- remove stat --'}); - datasourceSrv.get($scope.datasourceName).then(function(datasource) { - $scope.datasource = datasource; - if (_.isEmpty($scope.target.region)) { - $scope.target.region = $scope.datasource.getDefaultRegion(); - } - }); + if (_.isEmpty($scope.target.region)) { + $scope.target.region = $scope.datasource.getDefaultRegion(); + } if (!$scope.onChange) { $scope.onChange = function() {}; diff --git a/public/app/plugins/datasource/elasticsearch/partials/annotations.editor.html b/public/app/plugins/datasource/elasticsearch/partials/annotations.editor.html index 4ef9a916866..0b7070904de 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/annotations.editor.html +++ b/public/app/plugins/datasource/elasticsearch/partials/annotations.editor.html @@ -1,14 +1,14 @@
-
+
Index name
- +
Search query (lucene) Use [[filterName]] in query to replace part of the query with a filter value
- +
@@ -18,22 +18,22 @@
Field mappings
- +
- +
- +
- +