Commit cf98a16d by Torkel Ödegaard

feat(plugins): made data source custom edit view into a directive instead of…

feat(plugins): made data source custom edit view into a directive instead of html path config in plugin.json
parent f813b4c5
...@@ -60,6 +60,7 @@ function (angular, _, coreModule, config) { ...@@ -60,6 +60,7 @@ function (angular, _, coreModule, config) {
var deferred = $q.defer(); var deferred = $q.defer();
var pluginDef = dsConfig.meta; var pluginDef = dsConfig.meta;
console.log(pluginDef);
System.import(pluginDef.module).then(function(plugin) { System.import(pluginDef.module).then(function(plugin) {
// check if its in cache now // check if its in cache now
if (self.datasources[name]) { if (self.datasources[name]) {
......
...@@ -15,20 +15,6 @@ function (angular, _, config) { ...@@ -15,20 +15,6 @@ function (angular, _, config) {
var defaults = {name: '', type: 'graphite', url: '', access: 'proxy', jsonData: {}}; var defaults = {name: '', type: 'graphite', url: '', access: 'proxy', jsonData: {}};
$scope.indexPatternTypes = [
{name: 'No pattern', value: undefined},
{name: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH'},
{name: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD'},
{name: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW'},
{name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM'},
{name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY'},
];
$scope.esVersions = [
{name: '1.x', value: 1},
{name: '2.x', value: 2},
];
$scope.init = function() { $scope.init = function() {
$scope.isNew = true; $scope.isNew = true;
$scope.datasources = []; $scope.datasources = [];
...@@ -59,7 +45,7 @@ function (angular, _, config) { ...@@ -59,7 +45,7 @@ function (angular, _, config) {
backendSrv.get('/api/datasources/' + id).then(function(ds) { backendSrv.get('/api/datasources/' + id).then(function(ds) {
$scope.isNew = false; $scope.isNew = false;
$scope.current = ds; $scope.current = ds;
$scope.typeChanged(); return $scope.typeChanged();
}); });
}; };
...@@ -127,11 +113,6 @@ function (angular, _, config) { ...@@ -127,11 +113,6 @@ function (angular, _, config) {
} }
}; };
$scope.indexPatternTypeChanged = function() {
var def = _.findWhere($scope.indexPatternTypes, {value: $scope.current.jsonData.interval});
$scope.current.database = def.example || 'es-index-name';
};
$scope.init(); $scope.init();
}); });
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div ng-include="datasourceMeta.partials.config" ng-if="datasourceMeta.partials.config"></div> <datasource-custom-settings-view ds-meta="datasourceMeta" current="current"></datasource-custom-settings-view>
<div ng-if="testing" style="margin-top: 25px"> <div ng-if="testing" style="margin-top: 25px">
<h5 ng-show="!testing.done">Testing.... <i class="fa fa-spiner fa-spin"></i></h5> <h5 ng-show="!testing.done">Testing.... <i class="fa fa-spiner fa-spin"></i></h5>
......
...@@ -43,28 +43,30 @@ function (angular, $, config) { ...@@ -43,28 +43,30 @@ function (angular, $, config) {
}; };
}); });
module.service('dynamicDirectiveSrv', function($compile, $parse, datasourceSrv) { module.directive('datasourceCustomSettingsView', function($compile) {
var self = this; return {
restrict: 'E',
this.addDirective = function(options, type, editorScope) { scope: {
var panelEl = angular.element(document.createElement(options.name + '-' + type)); dsMeta: "=",
options.parentElem.append(panelEl); current: "=",
$compile(panelEl)(editorScope); },
}; link: function(scope, elem) {
scope.$watch("dsMeta.module", function() {
this.define = function(options) { if (!scope.dsMeta) {
var editorScope; return;
options.scope.$watch(options.datasourceProperty, function(newVal) {
if (editorScope) {
editorScope.$destroy();
options.parentElem.empty();
} }
editorScope = options.scope.$new(); System.import(scope.dsMeta.module).then(function(module) {
datasourceSrv.get(newVal).then(function(ds) { console.log('datasourceCustomSettingsView', module);
self.addDirective(options, ds.meta.type, editorScope); var panelEl = angular.element(document.createElement('datasource-custom-settings-view-' + scope.dsMeta.id));
elem.append(panelEl);
$compile(panelEl)(scope);
}).catch(function(err) {
console.log('Failed to load plugin:', err);
scope.appEvent('alert-error', ['Plugin Load Error', 'Failed to load plugin ' + scope.dsMeta.id + ', ' + err]);
}); });
}); });
}
}; };
}); });
...@@ -99,20 +101,6 @@ function (angular, $, config) { ...@@ -99,20 +101,6 @@ function (angular, $, config) {
}; };
}); });
module.directive('datasourceEditorView', function(dynamicDirectiveSrv) {
return {
restrict: 'E',
link: function(scope, elem, attrs) {
dynamicDirectiveSrv.define({
datasourceProperty: attrs.datasource,
name: attrs.name,
scope: scope,
parentElem: elem,
});
}
};
});
module.directive('panelResizer', function($rootScope) { module.directive('panelResizer', function($rootScope) {
return { return {
restrict: 'E', restrict: 'E',
......
declare var Datasource: any; declare var Datasource: any;
export {Datasource}; export default Datasource;
...@@ -7,7 +7,6 @@ define([ ...@@ -7,7 +7,6 @@ define([
'./index_pattern', './index_pattern',
'./elastic_response', './elastic_response',
'./query_ctrl', './query_ctrl',
'./directives'
], ],
function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticResponse) { function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticResponse) {
'use strict'; 'use strict';
...@@ -305,7 +304,5 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes ...@@ -305,7 +304,5 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
}; };
} }
return { return ElasticDatasource;
Datasource: ElasticDatasource,
};
}); });
...@@ -20,6 +20,10 @@ function (angular) { ...@@ -20,6 +20,10 @@ function (angular) {
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/annotations.editor.html'}; return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/annotations.editor.html'};
}); });
module.directive('datasourceCustomSettingsViewElasticsearch', function() {
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/config.html'};
});
module.directive('elasticMetricAgg', function() { module.directive('elasticMetricAgg', function() {
return { return {
templateUrl: 'app/plugins/datasource/elasticsearch/partials/metric_agg.html', templateUrl: 'app/plugins/datasource/elasticsearch/partials/metric_agg.html',
......
///<reference path="../../../headers/common.d.ts" />
import angular from 'angular';
import _ from 'lodash';
export class EditViewCtrl {
constructor($scope) {
$scope.indexPatternTypes = [
{name: 'No pattern', value: undefined},
{name: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH'},
{name: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD'},
{name: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW'},
{name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM'},
{name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY'},
];
$scope.esVersions = [
{name: '1.x', value: 1},
{name: '2.x', value: 2},
];
$scope.indexPatternTypeChanged = function() {
var def = _.findWhere($scope.indexPatternTypes, {value: $scope.current.jsonData.interval});
$scope.current.database = def.example || 'es-index-name';
};
}
}
function editViewDirective() {
return {
templateUrl: 'app/plugins/datasource/elasticsearch/partials/edit_view.html',
controller: EditViewCtrl,
};
};
export default editViewDirective;
define([
'angular',
'./datasource',
'./edit_view',
'./bucket_agg',
'./metric_agg',
],
function (angular, ElasticDatasource, editView) {
'use strict';
var module = angular.module('grafana.directives');
module.directive('metricQueryEditorElasticsearch', function() {
return {controller: 'ElasticQueryCtrl', templateUrl: 'app/plugins/datasource/elasticsearch/partials/query.editor.html'};
});
module.directive('metricQueryOptionsElasticsearch', function() {
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/query.options.html'};
});
module.directive('annotationsQueryEditorElasticsearch', function() {
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/annotations.editor.html'};
});
module.directive('elasticMetricAgg', function() {
return {
templateUrl: 'app/plugins/datasource/elasticsearch/partials/metric_agg.html',
controller: 'ElasticMetricAggCtrl',
restrict: 'E',
scope: {
target: "=",
index: "=",
onChange: "&",
getFields: "&",
esVersion: '='
}
};
});
module.directive('elasticBucketAgg', function() {
return {
templateUrl: 'app/plugins/datasource/elasticsearch/partials/bucket_agg.html',
controller: 'ElasticBucketAggCtrl',
restrict: 'E',
scope: {
target: "=",
index: "=",
onChange: "&",
getFields: "&",
}
};
});
module.directive('datasourceCustomSettingsViewElasticsearch', editView.default);
return {
Datasource: ElasticDatasource,
};
});
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
</div>
<br>
<h5>Default query settings</h5> <h5>Default query settings</h5>
<div class="tight-form last"> <div class="tight-form last">
......
...@@ -3,14 +3,7 @@ ...@@ -3,14 +3,7 @@
"name": "Elasticsearch", "name": "Elasticsearch",
"id": "elasticsearch", "id": "elasticsearch",
"serviceName": "ElasticDatasource", "module": "app/plugins/datasource/elasticsearch/module",
"module": "app/plugins/datasource/elasticsearch/datasource",
"partials": {
"config": "app/plugins/datasource/elasticsearch/partials/config.html",
"annotations": "app/plugins/datasource/elasticsearch/partials/annotations.editor.html"
},
"defaultMatchFormat": "lucene", "defaultMatchFormat": "lucene",
"annotations": true, "annotations": true,
......
...@@ -3,7 +3,7 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/co ...@@ -3,7 +3,7 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/co
import moment from 'moment'; import moment from 'moment';
import angular from 'angular'; import angular from 'angular';
import helpers from 'test/specs/helpers'; import helpers from 'test/specs/helpers';
import {Datasource} from "../datasource"; import Datasource from "../datasource";
describe('ElasticDatasource', function() { describe('ElasticDatasource', function() {
var ctx = new helpers.ServiceTestContext(); var ctx = new helpers.ServiceTestContext();
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"type": "datasource", "type": "datasource",
"id": "graphite", "id": "graphite",
"serviceName": "GraphiteDatasource",
"module": "app/plugins/datasource/graphite/datasource", "module": "app/plugins/datasource/graphite/datasource",
"partials": { "partials": {
......
...@@ -5,7 +5,7 @@ import {Datasource} from "../datasource"; ...@@ -5,7 +5,7 @@ import {Datasource} from "../datasource";
describe('graphiteDatasource', function() { describe('graphiteDatasource', function() {
var ctx = new helpers.ServiceTestContext(); var ctx = new helpers.ServiceTestContext();
var instanceSettings: any = {url:['']}; var instanceSettings: any = {url: ['']};
beforeEach(angularMocks.module('grafana.core')); beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services')); beforeEach(angularMocks.module('grafana.services'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment