query_ctrl.ts 1.9 KB

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