query_ctrl.ts 1.9 KB

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