query_editor.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. export class QueryEditorCtrl {
  5. target: any;
  6. datasource: any;
  7. panelCtrl: any;
  8. panel: any;
  9. constructor(public $scope, private $injector) {
  10. this.panel = this.panelCtrl.panel;
  11. if (!this.target.refId) {
  12. this.target.refId = this.getNextQueryLetter();
  13. }
  14. }
  15. getNextQueryLetter() {
  16. var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  17. return _.find(letters, refId => {
  18. return _.every(this.panel.targets, function(other) {
  19. return other.refId !== refId;
  20. });
  21. });
  22. }
  23. removeDataQuery(query) {
  24. this.panel.targets = _.without(this.panel.targets, query);
  25. this.panelCtrl.refresh();
  26. };
  27. duplicateDataQuery(query) {
  28. var clone = angular.copy(query);
  29. clone.refId = this.getNextQueryLetter();
  30. this.panel.targets.push(clone);
  31. }
  32. moveDataQuery(direction) {
  33. var index = _.indexOf(this.panel.targets, this.target);
  34. _.move(this.panel.targets, index, index + direction);
  35. }
  36. toggleHideQuery() {
  37. this.target.hide = !this.target.hide;
  38. this.panelCtrl.refresh();
  39. }
  40. }
  41. // var directivesModule = angular.module('grafana.directives');
  42. //
  43. // /** @ngInject */
  44. // function metricsQueryOptions(dynamicDirectiveSrv, datasourceSrv) {
  45. // return dynamicDirectiveSrv.create({
  46. // watchPath: "ctrl.panel.datasource",
  47. // directive: scope => {
  48. // return datasourceSrv.get(scope.ctrl.panel.datasource).then(ds => {
  49. // return System.import(ds.meta.module).then(dsModule => {
  50. // return {
  51. // name: 'metrics-query-options-' + ds.meta.id,
  52. // fn: dsModule.metricsQueryOptions
  53. // };
  54. // });
  55. // });
  56. // }
  57. // });
  58. // }
  59. //
  60. // directivesModule.directive('metricsQueryOptions', metricsQueryOptions);