module.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { DataSourcePlugin } from '@grafana/data';
  2. import {
  3. createChangeHandler,
  4. createResetHandler,
  5. PasswordFieldEnum,
  6. } from '../../../features/datasources/utils/passwordHandlers';
  7. import { MysqlDatasource } from './datasource';
  8. import { MysqlQueryCtrl } from './query_ctrl';
  9. import { MySQLQuery } from './types';
  10. class MysqlConfigCtrl {
  11. static templateUrl = 'partials/config.html';
  12. current: any;
  13. onPasswordReset: ReturnType<typeof createResetHandler>;
  14. onPasswordChange: ReturnType<typeof createChangeHandler>;
  15. constructor() {
  16. this.onPasswordReset = createResetHandler(this, PasswordFieldEnum.Password);
  17. this.onPasswordChange = createChangeHandler(this, PasswordFieldEnum.Password);
  18. }
  19. }
  20. const defaultQuery = `SELECT
  21. UNIX_TIMESTAMP(<time_column>) as time_sec,
  22. <text_column> as text,
  23. <tags_column> as tags
  24. FROM <table name>
  25. WHERE $__timeFilter(time_column)
  26. ORDER BY <time_column> ASC
  27. LIMIT 100
  28. `;
  29. class MysqlAnnotationsQueryCtrl {
  30. static templateUrl = 'partials/annotations.editor.html';
  31. declare annotation: any;
  32. /** @ngInject */
  33. constructor($scope: any) {
  34. this.annotation = $scope.ctrl.annotation;
  35. this.annotation.rawQuery = this.annotation.rawQuery || defaultQuery;
  36. }
  37. }
  38. export {
  39. MysqlDatasource,
  40. MysqlDatasource as Datasource,
  41. MysqlQueryCtrl as QueryCtrl,
  42. MysqlConfigCtrl as ConfigCtrl,
  43. MysqlAnnotationsQueryCtrl as AnnotationsQueryCtrl,
  44. };
  45. export const plugin = new DataSourcePlugin<MysqlDatasource, MySQLQuery>(MysqlDatasource)
  46. .setQueryCtrl(MysqlQueryCtrl)
  47. .setConfigCtrl(MysqlConfigCtrl)
  48. .setAnnotationQueryCtrl(MysqlAnnotationsQueryCtrl);