diff --git a/public/app/core/directives/plugin_component.ts b/public/app/core/directives/plugin_component.ts index 065a0be0392..9bfab78074e 100644 --- a/public/app/core/directives/plugin_component.ts +++ b/public/app/core/directives/plugin_component.ts @@ -5,7 +5,7 @@ import _ from 'lodash'; import coreModule from '../core_module'; -function pluginDirectiveLoader($compile, datasourceSrv, $rootScope) { +function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q) { function getPluginComponentDirective(options) { return function() { @@ -83,7 +83,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope) { }); } default: { - $rootScope.appEvent('alert-error', ['Plugin component error', 'could not find component '+ attrs.type]); + return $q.reject({message: "Could not find component type: " + attrs.type }); } } } @@ -106,6 +106,10 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope) { return; } + if (!componentInfo.Component) { + throw {message: 'Failed to find exported plugin component for ' + componentInfo.name}; + } + if (!componentInfo.Component.registered) { var directiveName = attrs.$normalize(componentInfo.name); var directiveFn = getPluginComponentDirective(componentInfo); @@ -121,6 +125,8 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope) { link: function(scope, elem, attrs) { getModule(scope, attrs).then(function (componentInfo) { registerPluginComponent(scope, elem, attrs, componentInfo); + }).catch(err => { + $rootScope.appEvent('alert-error', ['Plugin Error', err.message || err]); }); } }; diff --git a/public/app/plugins/datasource/elasticsearch/datasource.d.ts b/public/app/plugins/datasource/elasticsearch/datasource.d.ts index a50d7ca49cc..3682abfb614 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.d.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.d.ts @@ -1,3 +1,3 @@ -declare var Datasource: any; -export default Datasource; +declare var ElasticDatasource: any; +export {ElasticDatasource}; diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 0d2fd174c4d..294f666abc7 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -304,5 +304,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes }; } - return ElasticDatasource; + return { + ElasticDatasource: ElasticDatasource + }; }); diff --git a/public/app/plugins/datasource/elasticsearch/module.js b/public/app/plugins/datasource/elasticsearch/module.js deleted file mode 100644 index d38afe8e936..00000000000 --- a/public/app/plugins/datasource/elasticsearch/module.js +++ /dev/null @@ -1,30 +0,0 @@ -define([ - './datasource', - './edit_view', - './bucket_agg', - './metric_agg', -], -function (ElasticDatasource, editView) { - 'use strict'; - - function metricsQueryEditor() { - return {controller: 'ElasticQueryCtrl', templateUrl: 'public/app/plugins/datasource/elasticsearch/partials/query.editor.html'}; - } - - function metricsQueryOptions() { - return {templateUrl: 'public/app/plugins/datasource/elasticsearch/partials/query.options.html'}; - } - - function annotationsQueryEditor() { - return {templateUrl: 'public/app/plugins/datasource/elasticsearch/partials/annotations.editor.html'}; - } - - return { - Datasource: ElasticDatasource, - configView: editView.default, - annotationsQueryEditor: annotationsQueryEditor, - metricsQueryEditor: metricsQueryEditor, - metricsQueryOptions: metricsQueryOptions, - }; - -}); diff --git a/public/app/plugins/datasource/elasticsearch/module.ts b/public/app/plugins/datasource/elasticsearch/module.ts new file mode 100644 index 00000000000..f5463af0527 --- /dev/null +++ b/public/app/plugins/datasource/elasticsearch/module.ts @@ -0,0 +1,22 @@ +import {ElasticDatasource} from './datasource'; +import {ElasticQueryCtrl} from './query_ctrl'; + +class ElasticConfigCtrl { + static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/config.html'; +} + +class ElasticQueryOptionsCtrl { + static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/query.options.html'; +} + +class ElasticAnnotationsQueryCtrl { + static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/annotations.editor.html'; +} + +export { + ElasticDatasource as Datasource, + ElasticQueryCtrl as QueryCtrl, + ElasticConfigCtrl as ConfigCtrl, + ElasticQueryOptionsCtrl as QueryOptionsCtrl, + ElasticAnnotationsQueryCtrl as AnnotationsQueryCtrl, +}; diff --git a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html index bbf5964b220..017f5cf1a42 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html +++ b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html @@ -1,77 +1,32 @@ -
- - - - - -
+
+ +
-
-
- - -
- -
- - -
- +
+ +
+ diff --git a/public/app/plugins/datasource/elasticsearch/partials/query.options.html b/public/app/plugins/datasource/elasticsearch/partials/query.options.html index 628a0a0bf3d..bac22df7136 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/query.options.html +++ b/public/app/plugins/datasource/elasticsearch/partials/query.options.html @@ -8,7 +8,7 @@ Group by time interval
  • -
  • @@ -23,7 +23,7 @@
  • - + alias patterns
  • @@ -34,7 +34,7 @@
    -
    +
    Alias patterns
    • {{term fieldname}} = replaced with value of term group by
    • diff --git a/public/app/plugins/datasource/elasticsearch/query_ctrl.js b/public/app/plugins/datasource/elasticsearch/query_ctrl.js deleted file mode 100644 index 90214dff17c..00000000000 --- a/public/app/plugins/datasource/elasticsearch/query_ctrl.js +++ /dev/null @@ -1,46 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('ElasticQueryCtrl', function($scope, $rootScope, $timeout, uiSegmentSrv) { - $scope.esVersion = $scope.datasource.esVersion; - $scope.panelCtrl = $scope.ctrl; - - $scope.init = function() { - var target = $scope.target; - if (!target) { return; } - - $scope.queryUpdated(); - }; - - $scope.getFields = function(type) { - var jsonStr = angular.toJson({find: 'fields', type: type}); - return $scope.datasource.metricFindQuery(jsonStr) - .then(uiSegmentSrv.transformToSegments(false)) - .then(null, $scope.handleQueryError); - }; - - $scope.queryUpdated = function() { - var newJson = angular.toJson($scope.datasource.queryBuilder.build($scope.target), true); - if (newJson !== $scope.oldQueryRaw) { - $scope.rawQueryOld = newJson; - $scope.panelCtrl.refresh(); - } - - $rootScope.appEvent('elastic-query-updated'); - }; - - $scope.handleQueryError = function(err) { - $scope.parserError = err.message || 'Failed to issue metric query'; - return []; - }; - - $scope.init(); - - }); - -}); diff --git a/public/app/plugins/datasource/elasticsearch/query_ctrl.ts b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts new file mode 100644 index 00000000000..fb04f39b8ac --- /dev/null +++ b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts @@ -0,0 +1,45 @@ +/// + +import './bucket_agg'; +import './metric_agg'; + +import angular from 'angular'; +import _ from 'lodash'; +import {QueryCtrl} from 'app/features/panel/panel'; + +export class ElasticQueryCtrl extends QueryCtrl { + static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/query.editor.html'; + + esVersion: any; + rawQueryOld: string; + + /** @ngInject **/ + constructor($scope, $injector, private $rootScope, private $timeout, private uiSegmentSrv) { + super($scope, $injector); + + this.esVersion = this.datasource.esVersion; + this.queryUpdated(); + } + + getFields(type) { + var jsonStr = angular.toJson({find: 'fields', type: type}); + return this.datasource.metricFindQuery(jsonStr) + .then(this.uiSegmentSrv.transformToSegments(false)) + .catch(this.handleQueryError.bind(this)); + } + + queryUpdated() { + var newJson = angular.toJson(this.datasource.queryBuilder.build(this.target), true); + if (newJson !== this.rawQueryOld) { + this.rawQueryOld = newJson; + this.refresh(); + } + + this.$rootScope.appEvent('elastic-query-updated'); + } + + handleQueryError(err) { + this.error = err.message || 'Failed to issue metric query'; + return []; + } +} diff --git a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts index a7e6a642550..133d138be82 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts @@ -3,7 +3,7 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/co import moment from 'moment'; import angular from 'angular'; import helpers from 'test/specs/helpers'; -import Datasource from "../datasource"; +import {ElasticDatasource} from "../datasource"; describe('ElasticDatasource', function() { var ctx = new helpers.ServiceTestContext(); @@ -21,7 +21,7 @@ describe('ElasticDatasource', function() { function createDatasource(instanceSettings) { instanceSettings.jsonData = instanceSettings.jsonData || {}; - ctx.ds = ctx.$injector.instantiate(Datasource, {instanceSettings: instanceSettings}); + ctx.ds = ctx.$injector.instantiate(ElasticDatasource, {instanceSettings: instanceSettings}); } describe('When testing datasource with index pattern', function() { diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_ctrl_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_ctrl_specs.ts deleted file mode 100644 index aceef08a3d9..00000000000 --- a/public/app/plugins/datasource/elasticsearch/specs/query_ctrl_specs.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// -/// -/// - -import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common'; -import helpers from 'test/specs/helpers'; - -describe('ElasticQueryCtrl', function() { - var ctx = new helpers.ControllerTestContext(); - - beforeEach(angularMocks.module('grafana.controllers')); - beforeEach(angularMocks.module('grafana.services')); - beforeEach(ctx.providePhase()); - beforeEach(ctx.createControllerPhase('ElasticQueryCtrl')); - - beforeEach(function() { - ctx.scope.target = {}; - ctx.scope.$parent = { get_data: sinon.spy() }; - - ctx.scope.datasource = ctx.datasource; - ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); - }); - - describe('init', function() { - beforeEach(function() { - ctx.scope.init(); - }); - }); -}); diff --git a/public/app/plugins/datasource/grafana/module.ts b/public/app/plugins/datasource/grafana/module.ts index b9c4997af7d..19233c4f975 100644 --- a/public/app/plugins/datasource/grafana/module.ts +++ b/public/app/plugins/datasource/grafana/module.ts @@ -2,14 +2,15 @@ import angular from 'angular'; import {GrafanaDatasource} from './datasource'; +import {QueryCtrl} from 'app/features/panel/panel'; -class GrafanaMetricsQueryEditor { +class GrafanaQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/grafana/partials/query.editor.html'; } export { GrafanaDatasource, GrafanaDatasource as Datasource, - GrafanaMetricsQueryEditor as MetricsQueryEditor, + GrafanaQueryCtrl as QueryCtrl, }; diff --git a/public/app/plugins/datasource/grafana/partials/query.editor.html b/public/app/plugins/datasource/grafana/partials/query.editor.html index fd2953e4be4..3131b4cc346 100644 --- a/public/app/plugins/datasource/grafana/partials/query.editor.html +++ b/public/app/plugins/datasource/grafana/partials/query.editor.html @@ -1,56 +1,5 @@ -
      - - -
        -
      • - {{ctrl.target.refId}} -
      • -
      • - - - -
      • -
      • - Test metric (fake data source) -
      • -
      -
      -
      + +
    • + Test metric (fake data source) +
    • +
      diff --git a/public/app/plugins/datasource/influxdb/module.ts b/public/app/plugins/datasource/influxdb/module.ts index a8acffe6695..fc19413f18d 100644 --- a/public/app/plugins/datasource/influxdb/module.ts +++ b/public/app/plugins/datasource/influxdb/module.ts @@ -21,33 +21,4 @@ export { InfluxAnnotationsQueryCtrl as AnnotationsQueryCtrl, }; -// define([ -// './datasource', -// ], -// function (InfluxDatasource) { -// 'use strict'; -// -// function influxMetricsQueryEditor() { -// return {controller: 'InfluxQueryCtrl', templateUrl: 'public/app/plugins/datasource/influxdb/partials/query.editor.html'}; -// } -// -// function influxMetricsQueryOptions() { -// return {templateUrl: 'public/app/plugins/datasource/influxdb/partials/query.options.html'}; -// } -// -// function influxAnnotationsQueryEditor() { -// return {templateUrl: 'public/app/plugins/datasource/influxdb/partials/annotations.editor.html'}; -// } -// -// function influxConfigView() { -// return {templateUrl: 'public/app/plugins/datasource/influxdb/partials/config.html'}; -// } -// -// return { -// Datasource: InfluxDatasource, -// metricsQueryEditor: influxMetricsQueryEditor, -// metricsQueryOptions: influxMetricsQueryOptions, -// annotationsQueryEditor: influxAnnotationsQueryEditor, -// configView: influxConfigView, -// }; -// }); + diff --git a/public/app/plugins/datasource/influxdb/partials/query.options.html b/public/app/plugins/datasource/influxdb/partials/query.options.html index dd6c7accd28..f0b106b4765 100644 --- a/public/app/plugins/datasource/influxdb/partials/query.options.html +++ b/public/app/plugins/datasource/influxdb/partials/query.options.html @@ -8,7 +8,7 @@ Group by time interval
    • -
    • @@ -24,17 +24,17 @@
    • - + alias patterns
    • - + stacking & and fill
    • - + group by time
    • @@ -46,7 +46,7 @@
      -
      +
      Alias patterns
      • $m = replaced with measurement name
      • @@ -58,7 +58,7 @@
      -
      +
      Stacking and fill
      • When stacking is enabled it important that points align
      • @@ -69,7 +69,7 @@
      -
      +
      Group by time
      • Group by time is important, otherwise the query could return many thousands of datapoints that will slow down Grafana