query_editor.ts 1.8 KB

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