config_ctrl.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import DatasourceSrv from 'app/features/plugins/datasource_srv';
  2. export class GraphiteConfigCtrl {
  3. static templateUrl = 'public/app/plugins/datasource/graphite/partials/config.html';
  4. datasourceSrv: any;
  5. current: any;
  6. /** @ngInject */
  7. constructor($scope: any, datasourceSrv: DatasourceSrv) {
  8. this.datasourceSrv = datasourceSrv;
  9. this.current.jsonData = this.current.jsonData || {};
  10. this.current.jsonData.graphiteVersion = this.current.jsonData.graphiteVersion || '0.9';
  11. this.autoDetectGraphiteVersion();
  12. }
  13. autoDetectGraphiteVersion() {
  14. if (!this.current.id) {
  15. return;
  16. }
  17. this.datasourceSrv
  18. .loadDatasource(this.current.name)
  19. .then((ds: any) => {
  20. return ds.getVersion();
  21. })
  22. .then((version: any) => {
  23. this.graphiteVersions.push({ name: version, value: version });
  24. this.current.jsonData.graphiteVersion = version;
  25. });
  26. }
  27. graphiteVersions = [
  28. { name: '0.9.x', value: '0.9' },
  29. { name: '1.0.x', value: '1.0' },
  30. { name: '1.1.x', value: '1.1' },
  31. ];
  32. }