metrics_panel_ctrl.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. import {PanelCtrl} from './panel_ctrl';
  4. class MetricsPanelCtrl extends PanelCtrl {
  5. error: boolean;
  6. loading: boolean;
  7. datasource: any;
  8. $q: any;
  9. datasourceSrv: any;
  10. constructor($scope, $injector) {
  11. super($scope, $injector);
  12. this.editorTabIndex = 1;
  13. if (!this.panel.targets) {
  14. this.panel.targets = [{}];
  15. }
  16. }
  17. initEditorTabs() {
  18. this.addEditorTab('Metrics', () => {
  19. return { templateUrl: 'public/app/partials/metrics.html' };
  20. });
  21. }
  22. refresh() {
  23. this.getData();
  24. }
  25. refreshData(data) {
  26. // null op
  27. return data;
  28. }
  29. loadSnapshot(data) {
  30. // null op
  31. return data;
  32. }
  33. getData() {
  34. if (this.otherPanelInFullscreenMode()) { return; }
  35. if (this.panel.snapshotData) {
  36. if (this.loadSnapshot) {
  37. this.loadSnapshot(this.panel.snapshotData);
  38. }
  39. return;
  40. }
  41. delete this.error;
  42. this.loading = true;
  43. this.datasourceSrv.get(this.panel.datasource).then(datasource => {
  44. this.datasource = datasource;
  45. return this.refreshData(this.datasource) || this.$q.when({});
  46. }).then(() => {
  47. this.loading = false;
  48. }, err => {
  49. console.log('Panel data error:', err);
  50. this.loading = false;
  51. this.error = err.message || "Timeseries data request error";
  52. this.inspector = {error: err};
  53. });
  54. }
  55. }
  56. export {MetricsPanelCtrl};