config_ctrl.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import _ from 'lodash';
  2. export class PostgresConfigCtrl {
  3. static templateUrl = 'partials/config.html';
  4. current: any;
  5. datasourceSrv: any;
  6. showTimescaleDBHelp: boolean;
  7. /** @ngInject **/
  8. constructor($scope, datasourceSrv) {
  9. this.datasourceSrv = datasourceSrv;
  10. this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full';
  11. this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903;
  12. this.showTimescaleDBHelp = false;
  13. this.autoDetectFeatures();
  14. }
  15. autoDetectFeatures() {
  16. if (!this.current.id) {
  17. return;
  18. }
  19. this.datasourceSrv.loadDatasource(this.current.name).then(ds => {
  20. return ds.getVersion().then(version => {
  21. version = Number(version[0].text);
  22. // timescaledb is only available for 9.6+
  23. if (version >= 906) {
  24. ds.getTimescaleDBVersion().then(version => {
  25. if (version.length === 1) {
  26. this.current.jsonData.timescaledb = true;
  27. }
  28. });
  29. }
  30. let major = Math.trunc(version / 100);
  31. let minor = version % 100;
  32. let name = String(major);
  33. if (version < 1000) {
  34. name = String(major) + '.' + String(minor);
  35. }
  36. if (!_.find(this.postgresVersions, (p: any) => p.value === version)) {
  37. this.postgresVersions.push({ name: name, value: version });
  38. }
  39. this.current.jsonData.postgresVersion = version;
  40. });
  41. });
  42. }
  43. toggleTimescaleDBHelp() {
  44. this.showTimescaleDBHelp = !this.showTimescaleDBHelp;
  45. }
  46. // the value portion is derived from postgres server_version_num/100
  47. postgresVersions = [
  48. { name: '9.3', value: 903 },
  49. { name: '9.4', value: 904 },
  50. { name: '9.5', value: 905 },
  51. { name: '9.6', value: 906 },
  52. { name: '10', value: 1000 },
  53. ];
  54. }