module.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. import {MysqlDatasource} from './datasource';
  5. import {QueryCtrl} from 'app/plugins/sdk';
  6. export interface MysqlQuery {
  7. refId: string;
  8. format: string;
  9. alias: string;
  10. }
  11. export interface QueryMeta {
  12. sql: string;
  13. }
  14. class MysqlQueryCtrl extends QueryCtrl {
  15. static templateUrl = 'partials/query.editor.html';
  16. showLastQuerySQL: boolean;
  17. formats: any[];
  18. target: MysqlQuery;
  19. lastQueryMeta: QueryMeta;
  20. lastQueryError: string;
  21. constructor($scope, $injector) {
  22. super($scope, $injector);
  23. this.target.format = this.target.format || 'time_series';
  24. this.target.alias = "";
  25. this.formats = [
  26. {text: 'Time series', value: 'time_series'},
  27. {text: 'Table', value: 'table'},
  28. ];
  29. this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
  30. this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
  31. }
  32. onDataReceived(dataList) {
  33. this.lastQueryMeta = null;
  34. this.lastQueryError = null;
  35. let anySeriesFromQuery = _.find(dataList, {refId: this.target.refId});
  36. if (anySeriesFromQuery) {
  37. this.lastQueryMeta = anySeriesFromQuery.meta;
  38. }
  39. }
  40. onDataError(err) {
  41. if (err.data && err.data.results) {
  42. let queryRes = err.data.results[this.target.refId];
  43. if (queryRes) {
  44. this.lastQueryMeta = queryRes.meta;
  45. this.lastQueryError = queryRes.error;
  46. }
  47. }
  48. }
  49. }
  50. class MysqlConfigCtrl {
  51. static templateUrl = 'partials/config.html';
  52. }
  53. export {
  54. MysqlDatasource,
  55. MysqlDatasource as Datasource,
  56. MysqlQueryCtrl as QueryCtrl,
  57. MysqlConfigCtrl as ConfigCtrl,
  58. };