query_ctrl.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. export class QueryCtrl {
  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. removeQuery() {
  24. this.panel.targets = _.without(this.panel.targets, this.target);
  25. this.panelCtrl.refresh();
  26. };
  27. duplicateQuery() {
  28. var clone = angular.copy(this.target);
  29. clone.refId = this.getNextQueryLetter();
  30. this.panel.targets.push(clone);
  31. }
  32. moveQuery(direction) {
  33. var index = _.indexOf(this.panel.targets, this.target);
  34. _.move(this.panel.targets, index, index + direction);
  35. }
  36. refresh() {
  37. this.panelCtrl.refresh();
  38. }
  39. toggleHideQuery() {
  40. this.target.hide = !this.target.hide;
  41. this.panelCtrl.refresh();
  42. }
  43. }
  44. // var directivesModule = angular.module('grafana.directives');
  45. //
  46. // /** @ngInject */
  47. // function metricsQueryOptions(dynamicDirectiveSrv, datasourceSrv) {
  48. // return dynamicDirectiveSrv.create({
  49. // watchPath: "ctrl.panel.datasource",
  50. // directive: scope => {
  51. // return datasourceSrv.get(scope.ctrl.panel.datasource).then(ds => {
  52. // return System.import(ds.meta.module).then(dsModule => {
  53. // return {
  54. // name: 'metrics-query-options-' + ds.meta.id,
  55. // fn: dsModule.metricsQueryOptions
  56. // };
  57. // });
  58. // });
  59. // }
  60. // });
  61. // }
  62. //
  63. // directivesModule.directive('metricsQueryOptions', metricsQueryOptions);