query_ctrl.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import _ from 'lodash';
  2. import { QueryCtrl } from 'app/plugins/sdk';
  3. import './query_aggregation_ctrl';
  4. import './query_filter_ctrl';
  5. import { StackdriverPicker } from './components/StackdriverPicker';
  6. import { react2AngularDirective } from 'app/core/utils/react2angular';
  7. import { registerAngularDirectives } from './angular_wrappers';
  8. import { Target, QueryMeta } from './types';
  9. export const DefaultTarget = {
  10. defaultProject: 'loading project...',
  11. metricType: '',
  12. service: '',
  13. metric: '',
  14. unit: '',
  15. crossSeriesReducer: 'REDUCE_MEAN',
  16. alignmentPeriod: 'stackdriver-auto',
  17. perSeriesAligner: 'ALIGN_MEAN',
  18. groupBys: [],
  19. filters: [],
  20. showAggregationOptions: false,
  21. aliasBy: '',
  22. metricKind: '',
  23. valueType: '',
  24. };
  25. export class StackdriverQueryCtrl extends QueryCtrl {
  26. static templateUrl = 'partials/query.editor.html';
  27. target: Target;
  28. defaults = {
  29. defaultProject: 'loading project...',
  30. metricType: '',
  31. service: '',
  32. metric: '',
  33. unit: '',
  34. crossSeriesReducer: 'REDUCE_MEAN',
  35. alignmentPeriod: 'stackdriver-auto',
  36. perSeriesAligner: 'ALIGN_MEAN',
  37. groupBys: [],
  38. filters: [],
  39. showAggregationOptions: false,
  40. aliasBy: '',
  41. metricKind: '',
  42. valueType: '',
  43. };
  44. showHelp: boolean;
  45. showLastQuery: boolean;
  46. lastQueryMeta: QueryMeta;
  47. lastQueryError?: string;
  48. labelData: QueryMeta;
  49. loadLabelsPromise: Promise<any>;
  50. templateSrv: any;
  51. $rootScope: any;
  52. uiSegmentSrv: any;
  53. /** @ngInject */
  54. constructor($scope, $injector, templateSrv, $rootScope, uiSegmentSrv) {
  55. super($scope, $injector);
  56. this.templateSrv = templateSrv;
  57. this.$rootScope = $rootScope;
  58. this.uiSegmentSrv = uiSegmentSrv;
  59. _.defaultsDeep(this.target, this.defaults);
  60. react2AngularDirective('stackdriverPicker', StackdriverPicker, [
  61. 'options',
  62. 'onChange',
  63. 'selected',
  64. 'searchable',
  65. 'className',
  66. 'placeholder',
  67. 'groupName',
  68. ['templateVariables', { watchDepth: 'reference' }],
  69. ]);
  70. registerAngularDirectives();
  71. }
  72. handleQueryChange(target: Target) {
  73. Object.assign(this.target, target);
  74. }
  75. handleExecuteQuery() {
  76. this.$scope.ctrl.refresh();
  77. }
  78. }