config_ctrl.ts 1.4 KB

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