metrics_tab.ts 2.0 KB

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