2016-01-14 07:37:04 -06:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import angular from 'angular';
|
2016-02-01 05:42:10 -06:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2016-02-02 02:12:58 -06:00
|
|
|
export class QueryEditorCtrl {
|
|
|
|
target: any;
|
|
|
|
datasource: any;
|
|
|
|
panelCtrl: any;
|
|
|
|
panel: any;
|
|
|
|
|
2016-02-02 03:19:15 -06:00
|
|
|
constructor(public $scope, private $injector) {
|
2016-02-02 02:12:58 -06:00
|
|
|
this.panel = this.panelCtrl.panel;
|
|
|
|
|
|
|
|
if (!this.target.refId) {
|
|
|
|
this.target.refId = this.getNextQueryLetter();
|
2016-01-14 07:37:04 -06:00
|
|
|
}
|
2016-02-02 02:12:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
getNextQueryLetter() {
|
|
|
|
var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
|
|
|
|
return _.find(letters, refId => {
|
|
|
|
return _.every(this.panel.targets, function(other) {
|
|
|
|
return other.refId !== refId;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
removeDataQuery(query) {
|
|
|
|
this.panel.targets = _.without(this.panel.targets, query);
|
|
|
|
this.panelCtrl.refresh();
|
|
|
|
};
|
|
|
|
|
|
|
|
duplicateDataQuery(query) {
|
|
|
|
var clone = angular.copy(query);
|
|
|
|
clone.refId = this.getNextQueryLetter();
|
|
|
|
this.panel.targets.push(clone);
|
|
|
|
}
|
|
|
|
|
|
|
|
moveDataQuery(direction) {
|
|
|
|
var index = _.indexOf(this.panel.targets, this.target);
|
|
|
|
_.move(this.panel.targets, index, index + direction);
|
|
|
|
}
|
|
|
|
|
2016-02-02 03:19:15 -06:00
|
|
|
toggleHideQuery() {
|
|
|
|
this.target.hide = !this.target.hide;
|
2016-02-02 02:12:58 -06:00
|
|
|
this.panelCtrl.refresh();
|
|
|
|
}
|
2016-01-14 07:37:04 -06:00
|
|
|
}
|
|
|
|
|
2016-02-02 02:12:58 -06:00
|
|
|
// var directivesModule = angular.module('grafana.directives');
|
|
|
|
//
|
|
|
|
// /** @ngInject */
|
|
|
|
// function metricsQueryOptions(dynamicDirectiveSrv, datasourceSrv) {
|
|
|
|
// return dynamicDirectiveSrv.create({
|
|
|
|
// watchPath: "ctrl.panel.datasource",
|
|
|
|
// directive: scope => {
|
|
|
|
// return datasourceSrv.get(scope.ctrl.panel.datasource).then(ds => {
|
|
|
|
// return System.import(ds.meta.module).then(dsModule => {
|
|
|
|
// return {
|
|
|
|
// name: 'metrics-query-options-' + ds.meta.id,
|
|
|
|
// fn: dsModule.metricsQueryOptions
|
|
|
|
// };
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// directivesModule.directive('metricsQueryOptions', metricsQueryOptions);
|