mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(plugins): more work on how plugins expose directives
This commit is contained in:
@@ -18,10 +18,10 @@ Press `Shift`+`?` to open the keyboard shortcut dialog from anywhere within the
|
|||||||
|---|---|
|
|---|---|
|
||||||
|`Esc`|Exit fullscreen edit/view mode, close search or any editor view|
|
|`Esc`|Exit fullscreen edit/view mode, close search or any editor view|
|
||||||
|`F`|Open dashboard search view (also contains import/playlist controls)|
|
|`F`|Open dashboard search view (also contains import/playlist controls)|
|
||||||
|
|`R`|Refresh (Fetches new data and rerenders panels)|
|
||||||
|`CTRL`+`S`|Save dashboard|
|
|`CTRL`+`S`|Save dashboard|
|
||||||
|`CTRL`+`H`|Hide row controls|
|
|`CTRL`+`H`|Hide row controls|
|
||||||
|`CTRL`+`Z`|Zoom out|
|
|`CTRL`+`Z`|Zoom out|
|
||||||
|`CTRL`+`R`|Refresh (Fetches new data and rerenders panels)|
|
|
||||||
|`CTRL`+`O`|Enable/Disable shared graph crosshair|
|
|`CTRL`+`O`|Enable/Disable shared graph crosshair|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import coreModule from '../core_module';
|
|||||||
class DynamicDirectiveSrv {
|
class DynamicDirectiveSrv {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private $compile, private $parse) {}
|
constructor(private $compile, private $parse, private $rootScope) {}
|
||||||
|
|
||||||
addDirective(element, name, scope) {
|
addDirective(element, name, scope) {
|
||||||
var child = angular.element(document.createElement(name));
|
var child = angular.element(document.createElement(name));
|
||||||
@@ -16,25 +16,35 @@ class DynamicDirectiveSrv {
|
|||||||
element.append(child);
|
element.append(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
link(scope, elem, attrs, options) {
|
||||||
|
options.directive(scope).then(directiveInfo => {
|
||||||
|
if (!directiveInfo || !directiveInfo.fn) {
|
||||||
|
elem.empty();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!directiveInfo.fn.registered) {
|
||||||
|
coreModule.directive(attrs.$normalize(directiveInfo.name), directiveInfo.fn);
|
||||||
|
directiveInfo.fn.registered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addDirective(elem, directiveInfo.name, scope);
|
||||||
|
}).catch(err => {
|
||||||
|
console.log('Plugin load:', err);
|
||||||
|
this.$rootScope.appEvent('alert-error', ['Plugin error', err.toString()]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
create(options) {
|
create(options) {
|
||||||
let directiveDef = {
|
let directiveDef = {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: options.scope,
|
scope: options.scope,
|
||||||
link: (scope, elem, attrs) => {
|
link: (scope, elem, attrs) => {
|
||||||
options.directive(scope).then(directiveInfo => {
|
if (options.watch) {
|
||||||
if (!directiveInfo || !directiveInfo.fn) {
|
scope.$watch(options.watch,() => this.link(scope, elem, attrs, options));
|
||||||
return;
|
} else {
|
||||||
}
|
this.link(scope, elem, attrs, options);
|
||||||
|
}
|
||||||
if (!directiveInfo.fn.registered) {
|
|
||||||
coreModule.directive(attrs.$normalize(directiveInfo.name), directiveInfo.fn);
|
|
||||||
directiveInfo.fn.registered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addDirective(elem, directiveInfo.name, scope);
|
|
||||||
}).catch(function(err) {
|
|
||||||
console.log('Dynamic directive load error: ', err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
define([
|
define([
|
||||||
'./panellinks/module',
|
'./panellinks/module',
|
||||||
'./dashlinks/module',
|
'./dashlinks/module',
|
||||||
'./annotations/annotationsSrv',
|
'./annotations/annotations_srv',
|
||||||
'./templating/templateSrv',
|
'./templating/templateSrv',
|
||||||
'./dashboard/all',
|
'./dashboard/all',
|
||||||
'./playlist/all',
|
'./playlist/all',
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
'./editorCtrl'
|
'./editor_ctrl',
|
||||||
|
'./query_editor'
|
||||||
], function (angular, _) {
|
], function (angular, _) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -91,10 +91,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<annnotations-ds-query-editor
|
<annotations-query-editor datasource="currentDatasource" annotation="currentAnnotation">
|
||||||
datasource="currentAnnotation.datasource"
|
</annotations-query-editor>
|
||||||
current-annotation="currentAnnotation"></annotations-ds-query-editor>
|
|
||||||
<datasource-editor-view datasource="currentAnnotation.datasource" name="annotations-query-editor"></datasource-editor-view>
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<button ng-show="mode === 'new'" type="button" class="btn btn-success" ng-click="add()">Add</button>
|
<button ng-show="mode === 'new'" type="button" class="btn btn-success" ng-click="add()">Add</button>
|
||||||
|
|||||||
26
public/app/features/annotations/query_editor.ts
Normal file
26
public/app/features/annotations/query_editor.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
///<reference path="../../headers/common.d.ts" />
|
||||||
|
|
||||||
|
import angular from 'angular';
|
||||||
|
|
||||||
|
/** @ngInject */
|
||||||
|
function annotationsQueryEditor(dynamicDirectiveSrv) {
|
||||||
|
return dynamicDirectiveSrv.create({
|
||||||
|
scope: {
|
||||||
|
annotation: "=",
|
||||||
|
datasource: "="
|
||||||
|
},
|
||||||
|
watch: "datasource.type",
|
||||||
|
directive: scope => {
|
||||||
|
console.log(scope.datasource);
|
||||||
|
return System.import(scope.datasource.meta.module).then(function(dsModule) {
|
||||||
|
return {
|
||||||
|
name: 'annotation-query-editor-' + scope.datasource.meta.id,
|
||||||
|
fn: dsModule.annotationsQueryEditor,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
angular.module('grafana.directives').directive('annotationsQueryEditor', annotationsQueryEditor);
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
import './edit_ctrl';
|
import './edit_ctrl';
|
||||||
import './list_ctrl';
|
import './list_ctrl';
|
||||||
import './config_loader';
|
import './config_view';
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ function(angular, $) {
|
|||||||
scope.appEvent('save-dashboard', evt);
|
scope.appEvent('save-dashboard', evt);
|
||||||
}, { inputDisabled: true });
|
}, { inputDisabled: true });
|
||||||
|
|
||||||
keyboardManager.bind('ctrl+r', function() {
|
keyboardManager.bind('r', function() {
|
||||||
scope.broadcastRefresh();
|
scope.broadcastRefresh();
|
||||||
}, { inputDisabled: true });
|
}, { inputDisabled: true });
|
||||||
|
|
||||||
|
|||||||
@@ -43,20 +43,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('queryEditorLoader', function($compile, $parse, datasourceSrv) {
|
module.directive('queryEditorLoader', function($compile, $parse, datasourceSrv) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
<td><span class="label label-info">F</span></td>
|
<td><span class="label label-info">F</span></td>
|
||||||
<td>Open dashboard search view (also contains import/playlist controls)</td>
|
<td>Open dashboard search view (also contains import/playlist controls)</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><span class="label label-info">R</span></td>
|
||||||
|
<td>Refresh (Fetches new data and rerenders panels)</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><span class="label label-info">CTRL+S</span></td>
|
<td><span class="label label-info">CTRL+S</span></td>
|
||||||
<td>Save dashboard</td>
|
<td>Save dashboard</td>
|
||||||
@@ -36,10 +40,6 @@
|
|||||||
<td><span class="label label-info">CTRL+Z</span></td>
|
<td><span class="label label-info">CTRL+Z</span></td>
|
||||||
<td>Zoom out</td>
|
<td>Zoom out</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td><span class="label label-info">CTRL+R</span></td>
|
|
||||||
<td>Refresh (Fetches new data and rerenders panels)</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><span class="label label-info">CTRL+O</span></td>
|
<td><span class="label label-info">CTRL+O</span></td>
|
||||||
<td>Enable/Disable shared graph crosshair</td>
|
<td>Enable/Disable shared graph crosshair</td>
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ function (angular, CloudWatchDatasource) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.directive('datasourceCustomSettingsViewCloudwatch', function() {
|
function configView() {
|
||||||
return {templateUrl: 'app/plugins/datasource/cloudwatch/partials/edit_view.html'};
|
return {templateUrl: 'app/plugins/datasource/cloudwatch/partials/edit_view.html'};
|
||||||
});
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Datasource: CloudWatchDatasource
|
Datasource: CloudWatchDatasource,
|
||||||
|
configView: configView,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,18 +10,6 @@ function (angular, ElasticDatasource, editView) {
|
|||||||
|
|
||||||
var module = angular.module('grafana.directives');
|
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() {
|
module.directive('elasticMetricAgg', function() {
|
||||||
return {
|
return {
|
||||||
templateUrl: 'app/plugins/datasource/elasticsearch/partials/metric_agg.html',
|
templateUrl: 'app/plugins/datasource/elasticsearch/partials/metric_agg.html',
|
||||||
@@ -51,11 +39,22 @@ function (angular, ElasticDatasource, editView) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.directive('datasourceCustomSettingsViewElasticsearch', editView.default);
|
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'};
|
||||||
|
});
|
||||||
|
|
||||||
|
function annotationsQueryEditor() {
|
||||||
|
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/annotations.editor.html'};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Datasource: ElasticDatasource,
|
Datasource: ElasticDatasource,
|
||||||
configView: editView.default,
|
configView: editView.default,
|
||||||
|
annotationsQueryEditor: annotationsQueryEditor,
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,15 +15,17 @@ function (angular, GraphiteDatasource) {
|
|||||||
return {templateUrl: 'app/plugins/datasource/graphite/partials/query.options.html'};
|
return {templateUrl: 'app/plugins/datasource/graphite/partials/query.options.html'};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.directive('annotationsQueryEditorGraphite', function() {
|
function annotationsQueryEditor() {
|
||||||
return {templateUrl: 'app/plugins/datasource/graphite/partials/annotations.editor.html'};
|
return {templateUrl: 'app/plugins/datasource/graphite/partials/annotations.editor.html'};
|
||||||
});
|
}
|
||||||
|
|
||||||
module.directive('datasourceCustomSettingsViewGraphite', function() {
|
function configView() {
|
||||||
return {templateUrl: 'app/plugins/datasource/graphite/partials/config.html'};
|
return {templateUrl: 'app/plugins/datasource/graphite/partials/config.html'};
|
||||||
});
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Datasource: GraphiteDatasource,
|
Datasource: GraphiteDatasource,
|
||||||
|
configView: configView,
|
||||||
|
annotationsQueryEditor: annotationsQueryEditor,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<div class="editor-row">
|
<div class="editor-row">
|
||||||
<div class="editor-option">
|
<div class="editor-option">
|
||||||
<label class="small">Graphite target expression</label>
|
<label class="small">Graphite target expression</label>
|
||||||
<input type="text" class="span10" ng-model='currentAnnotation.target' placeholder=""></input>
|
<input type="text" class="span10" ng-model='annotation.target' placeholder=""></input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="editor-row">
|
<div class="editor-row">
|
||||||
<div class="editor-option">
|
<div class="editor-option">
|
||||||
<label class="small">Graphite event tags</label>
|
<label class="small">Graphite event tags</label>
|
||||||
<input type="text" ng-model='currentAnnotation.tags' placeholder=""></input>
|
<input type="text" ng-model='annotation.tags' placeholder=""></input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user