metrics_tab.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import {DashboardModel} from '../dashboard/model';
  4. export class MetricsTabCtrl {
  5. dsName: string;
  6. panel: any;
  7. panelCtrl: any;
  8. datasources: any[];
  9. current: any;
  10. nextRefId: string;
  11. dashboard: DashboardModel;
  12. panelDsValue: any;
  13. addQueryDropdown: any;
  14. /** @ngInject */
  15. constructor($scope, private uiSegmentSrv, private datasourceSrv) {
  16. this.panelCtrl = $scope.ctrl;
  17. $scope.ctrl = this;
  18. this.panel = this.panelCtrl.panel;
  19. this.dashboard = this.panelCtrl.dashboard;
  20. this.datasources = datasourceSrv.getMetricSources();
  21. this.panelDsValue = this.panelCtrl.panel.datasource || null;
  22. for (let ds of this.datasources) {
  23. if (ds.value === this.panelDsValue) {
  24. this.current = ds;
  25. }
  26. }
  27. this.addQueryDropdown = {text: 'Add Query', value: null, fake: true};
  28. // update next ref id
  29. this.panelCtrl.nextRefId = this.dashboard.getNextQueryLetter(this.panel);
  30. }
  31. getOptions(includeBuiltin) {
  32. return Promise.resolve(this.datasources.filter(value => {
  33. return includeBuiltin || !value.meta.builtIn;
  34. }).map(ds => {
  35. return {value: ds.value, text: ds.name, datasource: ds};
  36. }));
  37. }
  38. datasourceChanged(option) {
  39. if (!option) {
  40. return;
  41. }
  42. this.current = option.datasource;
  43. this.panelCtrl.setDatasource(option.datasource);
  44. }
  45. addMixedQuery(option) {
  46. if (!option) {
  47. return;
  48. }
  49. var target: any = {isNew: true};
  50. this.panelCtrl.addQuery({isNew: true, datasource: option.datasource.name});
  51. this.addQueryDropdown = {text: 'Add Query', value: null, fake: true};
  52. }
  53. addQuery() {
  54. this.panelCtrl.addQuery({isNew: true});
  55. }
  56. }
  57. /** @ngInject **/
  58. export function metricsTabDirective() {
  59. 'use strict';
  60. return {
  61. restrict: 'E',
  62. scope: true,
  63. templateUrl: 'public/app/features/panel/partials/metrics_tab.html',
  64. controller: MetricsTabCtrl,
  65. };
  66. }