2018-08-15 02:48:06 -05:00
|
|
|
import _ from 'lodash';
|
2019-04-15 04:11:17 -05:00
|
|
|
import {
|
|
|
|
createChangeHandler,
|
|
|
|
createResetHandler,
|
|
|
|
PasswordFieldEnum,
|
|
|
|
} from '../../../features/datasources/utils/passwordHandlers';
|
2019-07-01 04:11:57 -05:00
|
|
|
import DatasourceSrv from 'app/features/plugins/datasource_srv';
|
2018-08-15 02:48:06 -05:00
|
|
|
|
|
|
|
export class PostgresConfigCtrl {
|
|
|
|
static templateUrl = 'partials/config.html';
|
|
|
|
|
|
|
|
current: any;
|
|
|
|
datasourceSrv: any;
|
2018-08-27 16:20:17 -05:00
|
|
|
showTimescaleDBHelp: boolean;
|
2019-04-15 04:11:17 -05:00
|
|
|
onPasswordReset: ReturnType<typeof createResetHandler>;
|
|
|
|
onPasswordChange: ReturnType<typeof createChangeHandler>;
|
2018-08-15 02:48:06 -05:00
|
|
|
|
2018-08-31 12:02:46 -05:00
|
|
|
/** @ngInject */
|
2019-07-01 04:11:57 -05:00
|
|
|
constructor($scope: any, datasourceSrv: DatasourceSrv) {
|
2018-08-15 02:48:06 -05:00
|
|
|
this.datasourceSrv = datasourceSrv;
|
|
|
|
this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full';
|
|
|
|
this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903;
|
2018-08-27 16:20:17 -05:00
|
|
|
this.showTimescaleDBHelp = false;
|
2018-08-15 03:41:06 -05:00
|
|
|
this.autoDetectFeatures();
|
2019-04-15 04:11:17 -05:00
|
|
|
this.onPasswordReset = createResetHandler(this, PasswordFieldEnum.Password);
|
|
|
|
this.onPasswordChange = createChangeHandler(this, PasswordFieldEnum.Password);
|
2018-08-15 02:48:06 -05:00
|
|
|
}
|
|
|
|
|
2018-08-15 03:41:06 -05:00
|
|
|
autoDetectFeatures() {
|
2018-08-15 02:48:06 -05:00
|
|
|
if (!this.current.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-01 04:11:57 -05:00
|
|
|
this.datasourceSrv.loadDatasource(this.current.name).then((ds: any) => {
|
|
|
|
return ds.getVersion().then((version: any) => {
|
2018-08-15 02:48:06 -05:00
|
|
|
version = Number(version[0].text);
|
2018-08-15 03:41:06 -05:00
|
|
|
|
|
|
|
// timescaledb is only available for 9.6+
|
|
|
|
if (version >= 906) {
|
2019-07-01 04:11:57 -05:00
|
|
|
ds.getTimescaleDBVersion().then((version: any) => {
|
2018-08-15 03:41:06 -05:00
|
|
|
if (version.length === 1) {
|
|
|
|
this.current.jsonData.timescaledb = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-31 12:02:46 -05:00
|
|
|
const major = Math.trunc(version / 100);
|
|
|
|
const minor = version % 100;
|
2018-08-15 02:48:06 -05:00
|
|
|
let name = String(major);
|
|
|
|
if (version < 1000) {
|
|
|
|
name = String(major) + '.' + String(minor);
|
|
|
|
}
|
|
|
|
if (!_.find(this.postgresVersions, (p: any) => p.value === version)) {
|
|
|
|
this.postgresVersions.push({ name: name, value: version });
|
|
|
|
}
|
|
|
|
this.current.jsonData.postgresVersion = version;
|
|
|
|
});
|
2018-08-15 03:41:06 -05:00
|
|
|
});
|
2018-08-15 02:48:06 -05:00
|
|
|
}
|
|
|
|
|
2018-08-27 16:20:17 -05:00
|
|
|
toggleTimescaleDBHelp() {
|
|
|
|
this.showTimescaleDBHelp = !this.showTimescaleDBHelp;
|
|
|
|
}
|
|
|
|
|
2018-08-15 02:48:06 -05:00
|
|
|
// the value portion is derived from postgres server_version_num/100
|
|
|
|
postgresVersions = [
|
|
|
|
{ name: '9.3', value: 903 },
|
|
|
|
{ name: '9.4', value: 904 },
|
|
|
|
{ name: '9.5', value: 905 },
|
|
|
|
{ name: '9.6', value: 906 },
|
|
|
|
{ name: '10', value: 1000 },
|
|
|
|
];
|
|
|
|
}
|