帆软决策平台数据连接界面库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1438 lines
71 KiB

import { shortcut } from '@core/core';
import { Collapse, EVENT_CHANGE } from 'src/modules/components/collapse/collapse';
import { FormItem } from '../../components/form_item/form_item';
import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud/crud.typings';
import { connectionType } from '@constants/env';
import { CONNECT_CHARSET, CONNECTION_LAYOUT, INT_MAX_VALUE, INT_MIN_VALUE, CONNECT_SSH_TYPE, CONNECT_SSL_TYPE } from '@constants/constant';
import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service';
import { DatabaseType } from 'src/modules/app.typings';
import { TextChecker } from '../../../../components/text_checker/text_checker';
import { FileChooser } from '../../../../components/file_chooser/file_chooser';
import { ApiFactory } from 'src/modules/crud/apiFactory';
import { Editor, Label, TextAreaEditor, TextEditor, TextValueCombo, VerticalLayout, MultiSelectItem } from '@fui/core';
import { DriverSelector } from '../../components/driverselector/driverselector';
import { FileUpload } from '../../../../components/file_upload/file_upload';
const api = new ApiFactory().create();
@shortcut()
export class FormJdbc extends BI.Widget {
static xtype = 'dec.dcm.maintain.form.jdbc';
props = {
formData: {} as Connection,
};
oldPassword = '';
oldSshSecret = '';
databaseType: DatabaseType;
allDatabaseTypes = getAllDatabaseTypes();
sshSet: VerticalLayout;
sshForm: VerticalLayout;
sslSet: VerticalLayout;
sslForm: VerticalLayout;
advancedSet: VerticalLayout;
formUser: FormItem;
formPassword: FormItem;
formPrincipal: FormItem;
formKeyPath: FormItem;
formKrb5File: FormItem;
labelTips: Label;
form = {
connectionName: null,
driver: null,
database: null,
host: null,
port: null,
user: null,
password: null,
authType: null,
principal: null,
keyPath: null,
krb5Path: null,
originalCharsetName: null,
schema: null,
url: null,
initialSize: null,
maxActive: null,
maxWait: null,
// ssh
usingSsh: null,
sshIp: null,
sshPort: null,
sshUser: null,
sshType: null,
sshPrivateKeyPathForm: null,
sshPrivateKeyPath: null,
sshSecretForm: null,
sshSecret: null,
// ssl
usingSsl: null,
caCertificate: null,
verifyCa: null,
sslClientPrivateKey: null,
sslClientCertificate: null,
// more
validationQuery: null,
testOnBorrow: null,
testOnReturn: null,
testWhileIdle: null,
timeBetweenEvictionRunsMillis: null,
numTestsPerEvictionRun: null,
minIdle: null,
minEvictableIdleTimeMillis: null,
fetchSize: null,
};
render() {
const { connectionName, connectionData } = this.options.formData;
const {
driver,
driverSource,
user,
password,
originalCharsetName,
schema,
url,
connectionPoolAttr,
database,
authType,
principal,
keyPath,
krb5Path,
fetchSize,
// ssh
usingSsh = false,
sshIp, // sshIp默认值在表单那用||设置,因为在这可能是空字符串,解构默认值没用
sshPort = 22,
sshUser = '',
sshType = CONNECT_SSH_TYPE[0].value,
sshPrivateKeyPath = '',
sshSecret = '',
// ssl
usingSsl = false,
caCertificate = '',
verifyCa = false,
sslClientPrivateKey = '',
sslClientCertificate = '',
} = connectionData as ConnectionJDBC;
this.oldPassword = password;
this.oldSshSecret = sshSecret;
!BI.isUndefined(principal) && this.initPrincipals(keyPath, principal);
const {
initialSize,
maxActive,
maxWait,
validationQuery,
testOnBorrow,
testOnReturn,
testWhileIdle,
timeBetweenEvictionRunsMillis,
numTestsPerEvictionRun,
minIdle,
minEvictableIdleTimeMillis,
} = connectionPoolAttr as ConnectionPoolJDBC;
const databaseType = getJdbcDatabaseType(database, driver);
this.databaseType = databaseType;
const { host, port, databaseName } = resolveUrlInfo(url, database);
const { hgap, vgap } = CONNECTION_LAYOUT;
const valueRangeConfig = {
errorText: BI.i18nText('Dec-Dcm_Connection_Value_Out_Range'),
checker: (value: string) => this.checkValueRange(value),
autoFix: true,
};
return {
type: BI.VerticalLayout.xtype,
hgap,
vgap,
items: [
// 数据连接名称
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Name'),
forms: [
{
type: TextChecker.xtype,
$value: 'connection-name',
width: 300,
value: connectionName,
allowBlank: true,
ref: (_ref: TextChecker) => {
this.form.connectionName = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Data_Connections'),
},
],
},
// 驱动
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
forms: [
{
type: DriverSelector.xtype,
ref: (_ref: DriverSelector) => {
this.form.driver = _ref;
},
driver,
driverSource,
connectionData,
listeners: [
{
eventName: 'EVENT_CHANGE',
action: () => {
const value = this.form.driver.getValue();
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
// DEC-2020
const url = (connectionType.urls && connectionType.urls[value.driver]) || connectionType.url;
this.form.url.setValue(url);
const urlInfo = resolveUrlInfo(url, connectionData.database);
this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);
},
},
],
},
],
},
// 数据库名称
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
forms: [
{
type: BI.TextEditor.xtype,
$value: 'database-name',
width: 300,
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
value: databaseName,
ref: (_ref: any) => {
this.form.database = _ref;
},
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
},
],
},
],
},
// 主机
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
forms: [
{
type: BI.TextEditor.xtype,
$value: 'database-host',
width: 300,
allowBlank: true,
value: host,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
ref: (_ref: any) => {
this.form.host = _ref;
},
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
},
],
},
],
},
// 端口
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
forms: [
{
type: TextChecker.xtype,
$value: 'database-port',
width: 300,
allowBlank: true,
value: port,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.port = _ref;
},
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
},
],
},
],
},
// 认证方式
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_AuthType'),
invisible: !databaseType.kerberos,
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'auth-type',
width: 300,
value: authType,
ref: (_ref: TextValueCombo) => {
this.form.authType = _ref;
},
items: [
{
text: BI.i18nText('Dec-Dcm_Connection_Form_UserName_Password'),
value: '',
},
{
text: 'Kerberos',
value: 'kerberos',
},
],
listeners: [
{
eventName: BI.Combo.EVENT_CHANGE,
action: () => {
const type = this.form.authType.getValue()[0];
this.formPrincipal.setVisible(!!type);
this.formKeyPath.setVisible(!!type);
this.formKrb5File.setVisible(!!type);
this.form.krb5Path.setEnable(!type);
this.formUser.setVisible(!type);
this.formPassword.setVisible(!type);
},
},
],
},
],
},
// 用户名
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
invisible: !!authType,
ref: (_ref: FormItem) => {
this.formUser = _ref;
},
forms: [
{
type: BI.TextEditor.xtype,
$value: 'username',
width: 300,
allowBlank: true,
value: user,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
ref: (_ref: TextEditor) => {
this.form.user = _ref;
},
},
],
},
// 密码
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
invisible: !!authType,
ref: (_ref: FormItem) => {
this.formPassword = _ref;
},
forms: [
{
type: BI.Editor.xtype,
$value: 'password',
cls: 'bi-border bi-border-radius',
width: 300,
height: 20,
allowBlank: true,
value: password,
inputType: 'password',
autocomplete: 'new-password',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
ref: (_ref: Editor) => {
this.form.password = _ref;
},
},
],
},
// keytab密钥路径
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
invisible: !authType,
ref: (_ref: FormItem) => {
this.formKeyPath = _ref;
},
forms: [
{
type: FileUpload.xtype,
$value: 'key-path',
processId: "keytab",
allowBlank: true,
value: keyPath,
accept: '.keytab',
inter: '/v10/config/connection/upload/keytab?',
iconCls: "data-keytab-file",
watermark: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
ref: (_ref: FileUpload) => {
this.form.keyPath = _ref;
},
listeners: [
{
eventName: FileUpload.EVENT_CHECK_SUCCESS,
action: (value) => {
const principalsItems = BI.map(value.principals, function(index, item) {
return {
text: item,
value: item
}
})
this.form.principal.populate(principalsItems);
this.form.principal.setValue(principalsItems[0].value);
this.setKerberos();
this.form.krb5Path.setEnable(true);
},
}, {
eventName: FileUpload.EVENT_CLEAR_FILE,
action: () => {
this.form.krb5Path.setEnable(false);
this.form.principal.populate();
this.form.principal.setValue();
}
}
]
},
],
},
// 客户端principal
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Principal'),
invisible: !authType,
ref: (_ref: FormItem) => {
this.formPrincipal = _ref;
},
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'principal',
width: 300,
value: principal,
ref: (_ref: TextEditor) => {
this.form.principal = _ref;
},
listeners: [
{
eventName: BI.Combo.EVENT_CHANGE,
action: () => {
this.changePrincipal();
this.setKerberos();
},
},
],
}
],
},
// krb5.conf文件
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Krb5File'),
invisible: !authType,
ref: (_ref: FormItem) => {
this.formKrb5File = _ref;
},
forms: [
{
type: FileUpload.xtype,
$value: 'krb5-file',
processId: "krb5Conf",
allowBlank: true,
value: krb5Path,
iconCls: "data-conf-file",
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Krb5File'),
ref: (_ref: FileUpload) => {
this.form.krb5Path = _ref;
},
inter: '/v10/config/connection/upload/krb5?',
accept: '.conf',
listeners: [
{
eventName: FileUpload.EVENT_CHECK_SUCCESS,
action: () => {
this.setKerberos();
},
}
]
}
]
},
// 编码
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'original-charset-name',
width: 300,
value: originalCharsetName ? originalCharsetName : '',
items: CONNECT_CHARSET,
ref: (_ref: TextValueCombo) => {
this.form.originalCharsetName = _ref;
},
},
],
},
// 模式
{
type: FormItem.xtype,
invisible: !databaseType.hasSchema,
height: 64,
name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'),
forms: [
{
type: BI.VerticalLayout.xtype,
items: [
{
type: BI.FloatLeftLayout.xtype,
items: [
{
type: BI.TextButton.xtype,
cls: 'bi-high-light',
text: BI.i18nText('Dec-Dcm_Connection_Click_Connect_Database'),
handler: () => {
this.fireEvent('EVENT_TEST_CONNECTION');
},
},
{
type: BI.Label.xtype,
cls: 'bi-tips',
lgap: 3,
text: BI.i18nText('Dec-Dcm_Connection_Read_Mode_List'),
},
],
},
{
type: BI.TextValueCombo.xtype,
$value: 'schema',
width: 300,
vgap: 15,
disabled: true,
value: schema,
items: schema ? [{ text: schema, value: schema }] : [],
ref: (_ref: TextValueCombo) => {
this.form.schema = _ref;
},
},
],
},
],
},
// 分隔线
{
type: BI.Layout.xtype,
cls: 'bi-border-top',
bgap: 8,
},
// 数据连接URL
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
forms: [
{
type: BI.TextEditor.xtype,
$value: 'database-url',
width: 300,
allowBlank: true,
value: url,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
ref: (_ref: TextEditor) => {
this.form.url = _ref;
},
listeners: [
{
eventName: 'EVENT_CHANGE',
action: () => {
const urlInfo = resolveUrlInfo(this.form.url.getValue(), database);
this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);
},
},
],
},
],
},
// 最大活动连接数
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
forms: [
{
type: TextChecker.xtype,
$value: 'max-active',
width: 300,
allowBlank: false,
value: maxActive,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.maxActive = _ref;
},
},
],
},
// 获取连接前检验
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Borrow'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'check',
width: 300,
allowBlank: true,
value: testOnBorrow,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Borrow'),
ref: (_ref: TextValueCombo) => {
this.form.testOnBorrow = _ref;
},
},
],
},
// 校验语句
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
forms: [
{
type: BI.TextAreaEditor.xtype,
$value: 'validation-query',
cls: 'bi-border',
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query_Watermark'),
value: api.getPlain(validationQuery || ''),
width: 300,
height: 100,
ref: (_ref: TextAreaEditor) => {
this.form.validationQuery = _ref;
},
},
],
},
// 最大等待时间
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
forms: [
{
type: TextChecker.xtype,
$value: 'max-wait',
width: 300,
allowBlank: false,
value: maxWait,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.maxWait = _ref;
},
},
{
type: BI.Label.xtype,
lgap: 5,
height: CONNECTION_LAYOUT.labelHeight,
text: BI.i18nText('Dec-Dcm_Millisecond'),
},
],
},
// SSH设置
{
type: Collapse.xtype,
width: 100,
name: BI.i18nText('Dec-Dcm_Connection_Setting', 'SSH'),
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.sshSet.setVisible(!isCollapse);
},
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sshSet = _ref;
},
bgap: vgap,
invisible: true,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSH'),
forms: [
{
type: BI.MultiSelectItem.xtype,
ref: (_ref: MultiSelectItem) => {
this.form.usingSsh = _ref;
},
logic: { dynamic: true },
text: BI.i18nText('Dec-Basic_Use') + BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSH'),
selected: usingSsh,
listeners: [
{
eventName: BI.MultiSelectItem.EVENT_CHANGE,
action: () => {
const value = this.form.usingSsh.isSelected();
this.sshForm.setVisible(value);
},
},
],
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sshForm = _ref;
},
bgap: vgap,
invisible: !usingSsh,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshIp = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
allowBlank: false,
value: sshIp || 'hostname',
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshPort = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
allowBlank: false,
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
value: String(sshPort || 22),
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshUser = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
value: sshUser,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_VerifyType'),
forms: [
{
type: BI.TextValueCombo.xtype,
ref: (_ref: TextValueCombo) => {
this.form.sshType = _ref;
},
width: 300,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_VerifyType'),
items: CONNECT_SSH_TYPE,
value: sshType,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: () => {
const sshType = this.form.sshType.getValue()[0];
this.onSshTypeChange(sshType);
},
},
],
},
],
},
{
type: FormItem.xtype,
ref: (_ref: FormItem) => {
this.form.sshPrivateKeyPathForm = _ref;
},
name: BI.i18nText('Dec-Dcm_Connection_Form_PrivateKey'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: TextChecker) => {
this.form.sshPrivateKeyPath = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_PrivateKey'),
value: sshPrivateKeyPath,
},
],
},
{
type: FormItem.xtype,
ref: (ref: FormItem) => {
this.form.sshSecretForm = ref;
},
name: BI.i18nText(''),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshSecret = _ref;
},
watermark: BI.i18nText(''),
inputType: 'password',
autocomplete: 'new-password',
value: sshSecret,
},
],
},
],
},
},
],
},
},
// SSL设置
{
type: Collapse.xtype,
width: 100,
name: BI.i18nText('Dec-Dcm_Connection_Setting', 'SSL'),
invisible: !this.getSslSetEnabled(),
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.sslSet.setVisible(!isCollapse);
},
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sslSet = _ref;
},
bgap: vgap,
invisible: true,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSL'),
forms: [
{
type: BI.MultiSelectItem.xtype,
ref: (_ref: MultiSelectItem) => {
this.form.usingSsl = _ref;
},
logic: { dynamic: true },
text: BI.i18nText('Dec-Basic_Use') + BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSL'),
selected: usingSsl,
listeners: [
{
eventName: BI.MultiSelectItem.EVENT_CHANGE,
action: () => {
const value = this.form.usingSsl.isSelected();
this.sslForm.setVisible(value);
},
},
],
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sslForm = _ref;
},
bgap: vgap,
invisible: !usingSsl,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_CA_Certificate'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: FileChooser) => {
this.form.caCertificate = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_CA_Certificate'),
value: caCertificate,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Verify_CA_Certificate'),
forms: [
{
type: BI.TextValueCombo.xtype,
ref: (_ref: TextValueCombo) => {
this.form.verifyCa = _ref;
},
width: 300,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Verify_CA_Certificate'),
items: this.getBooleanItem(),
value: verifyCa,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_SecretKey'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: FileChooser) => {
this.form.sslClientPrivateKey = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_SecretKey'),
value: sslClientPrivateKey,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_Certificate'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: FileChooser) => {
this.form.sslClientCertificate = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_Certificate'),
value: sslClientCertificate,
},
],
},
],
},
},
],
},
},
// 高级设置
{
type: Collapse.xtype,
width: 100,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_More_Setting'),
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.advancedSet.setVisible(!isCollapse);
},
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
bgap: vgap,
invisible: true,
ref: (_ref: VerticalLayout) => {
this.advancedSet = _ref;
},
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
forms: [
{
type: TextChecker.xtype,
$value: 'initial-size',
width: 300,
allowBlank: false,
value: initialSize,
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
ref: (_ref: TextChecker) => {
this.form.initialSize = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
forms: [
{
type: TextChecker.xtype,
$value: 'min-idle',
width: 300,
allowBlank: false,
value: minIdle,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.minIdle = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'test-on-return',
width: 300,
allowBlank: true,
value: testOnReturn,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
ref: (_ref: TextValueCombo) => {
this.form.testOnReturn = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'test-while-idle',
width: 300,
allowBlank: true,
value: testWhileIdle,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
ref: (_ref: TextValueCombo) => {
this.form.testWhileIdle = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
forms: [
{
type: TextChecker.xtype,
$value: 'test-between-evicition-millis',
width: 300,
allowBlank: false,
value: timeBetweenEvictionRunsMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Number'),
checker: (value: string) => this.checkNumber(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.timeBetweenEvictionRunsMillis = _ref;
},
},
{
type: BI.Label.xtype,
lgap: 5,
height: CONNECTION_LAYOUT.labelHeight,
text: BI.i18nText('Dec-Dcm_Millisecond'),
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
forms: [
{
type: TextChecker.xtype,
$value: 'test-pereviction-run-num',
width: 300,
allowBlank: false,
value: numTestsPerEvictionRun,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.numTestsPerEvictionRun = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
forms: [
{
type: TextChecker.xtype,
$value: 'min-evictable-idle-time-millis',
width: 300,
allowBlank: false,
value: minEvictableIdleTimeMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.minEvictableIdleTimeMillis = _ref;
},
},
{
type: BI.Label.xtype,
lgap: 5,
height: CONNECTION_LAYOUT.labelHeight,
text: BI.i18nText('BI-Basic_Seconds'),
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
cls: 'bi-border-top',
invisible: fetchSize < 0 && fetchSize !== -2,
items: [
{
el: {
type: FormItem.xtype,
name: 'Fetchsize',
forms: [
{
type: TextChecker.xtype,
$value: 'fetch-size',
width: 300,
allowBlank: true,
value: fetchSize === -2 ? '' : fetchSize,
watermark: 'Fetchsize',
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Fetch_Size_Range'),
checker: (value: string) =>
BI.isInteger(value) && BI.parseInt(value) >= 0 && BI.parseInt(value) <= 1000000,
autoFix: true,
},
],
ref: (_ref: TextChecker) => {
this.form.fetchSize = _ref;
},
},
],
},
vgap: 15,
},
],
},
},
],
},
},
],
};
}
public mounted() {
const sshType = this.form.sshType.getValue()[0];
this.onSshTypeChange(sshType);
}
public setError(value: string) {
this.form.connectionName.setError(value);
}
private checkInteger(value: string) {
return /^[\d]+$/.test(value);
}
private checkNumber(value: string) {
return /^[(\-|\+)?\d]+$/.test(value);
}
private checkValueRange(value: string) {
return parseInt(value, 0) <= INT_MAX_VALUE && parseInt(value, 0) >= INT_MIN_VALUE;
}
private getDrivers() {
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
const drivers = connectionType.drivers
? connectionType.drivers.map((item) => {
return {
text: item,
value: item,
};
})
: [
{
text: connectionType.driver,
value: connectionType.driver,
},
];
if (!drivers.some((item) => item.text === connectionData.driver)) {
return [
{
text: connectionData.driver,
value: connectionData.driver,
},
...drivers,
];
}
return drivers;
}
private getBooleanItem() {
return [
{
text: BI.i18nText('Dec-Dcm_Yes'),
value: true,
},
{
text: BI.i18nText('Dec-Dcm_No'),
value: false,
},
];
}
private onHostPortChange(databaseType) {
const { urls, url } = databaseType;
const driver = this.form.driver.getValue();
const selectUrl = BI.get(urls, driver.driver) || url;
const host = this.form.host.getValue();
const port = this.form.port.getValue();
const database = this.form.database.getValue();
this.form.url.setValue(splitUrl(host, port, database, selectUrl));
}
private onSshTypeChange(sshType) {
const { privateKeyPathFormVisible, secretFormName } = CONNECT_SSH_TYPE.find((SSH_TYPE) => sshType === SSH_TYPE.value);
this.form.sshPrivateKeyPathForm.setVisible(privateKeyPathFormVisible);
this.form.sshSecretForm.setName(secretFormName);
this.form.sshSecret.setWatermark(secretFormName);
}
private getSslSetEnabled(): boolean {
const { databaseType } = this.databaseType;
return databaseType === 'mysql';
}
public setSchemas(schemas: string[]) {
this.form.schema.setEnable(true);
if (schemas.length > 0) {
const value = this.form.schema.getValue()[0];
this.form.schema.populate(
schemas.map((item) => {
return {
text: item,
value: item,
};
})
);
this.form.schema.setValue(value && schemas.some((item) => item === value) ? value : schemas[0]);
}
}
public setKerberos() {
const KerberosParams = BI.extend({},{
keytabPath: this.form.keyPath.getValue(),
krb5ConfPath: this.form.krb5Path.getValue(),
principal: this.form.principal.getValue()[0]
});
this.form.krb5Path.setFileInfo(KerberosParams);
this.form.keyPath.setFileInfo(KerberosParams);
}
public initPrincipals(keyPath, principal) {
let self = this;
api.getPrincipals(keyPath).then(res => {
const principalsItems = BI.map(res.data, function(index, item) {
return {
text: item,
value: item
}
});
self.form.principal.populate(principalsItems);
self.form.principal.setValue(principal);
})
}
public changePrincipal() {
let self = this;
const KerberosParams = BI.extend({},{
keytabPath: this.form.keyPath.getValue(),
krb5ConfPath: this.form.krb5Path.getValue(),
principal: this.form.principal.getValue()[0]
});
api.changePrincipal(KerberosParams).then(res =>{
self.form.keyPath.setValue(res.data.keytabPath);
self.form.krb5Path.setValue(res.data.krb5ConfPath);
});
}
public validation(): boolean {
const driver = this.form.driver.validation();
const sshSet = !this.form.usingSsh.isSelected() || (this.form.sshIp.getValue() !== '' && this.form.sshPort.getValue() !== '');
return driver && sshSet;
}
public getSubmitValue(): Connection {
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionPoolAttr = connectionData.connectionPoolAttr;
const originalCharsetName = this.form.originalCharsetName.getValue()[0] || '';
// TODO 获取表单数据这里待优化
return {
connectionType: connectionType.JDBC,
connectionId: this.form.connectionName.getValue(),
connectionName: this.form.connectionName.getValue(),
connectionData: <ConnectionJDBC>BI.extend({}, connectionData, {
database: connectionData.database,
connectionName: this.form.connectionName.getValue(),
...this.form.driver.getValue(),
url: this.form.url.getValue(),
user: this.form.user.getValue(),
password: this.oldPassword === this.form.password.getValue() ? this.oldPassword : api.getCipher(this.form.password.getValue()),
queryType: '',
newCharsetName: originalCharsetName ? 'gbk' : '', // 后台要求,originalCharsetName不为空时,newCharsetName为gbk
originalCharsetName,
schema: this.form.schema.getValue()[0],
host: this.form.host.getValue(),
authType: this.form.authType.getValue()[0] || '',
creator: Dec ? Dec.personal.username : '',
principal: this.form.principal.getValue()[0],
keyPath: this.form.keyPath.getValue(),
krb5Path: this.form.krb5Path.getValue(),
fetchSize: BI.isEmptyString(this.form.fetchSize.getValue()) ? -2 : BI.parseInt(this.form.fetchSize.getValue()),
// ssh
usingSsh: this.form.usingSsh.isSelected(),
// redirectPort: 0,
// redirectIp: '',
// sshKeepAlive: 10000,
// sshTimeOut: 10000,
sshIp: this.form.sshIp.getValue(),
sshPort: Number(this.form.sshPort.getValue()),
sshUser: this.form.sshUser.getValue(),
sshType: this.form.sshType.getValue()[0],
sshPrivateKeyPath: this.form.sshPrivateKeyPath.getValue(),
sshSecret: this.oldSshSecret === this.form.sshSecret.getValue() ? this.oldSshSecret : api.getCipher(this.form.sshSecret.getValue()),
// ssl
usingSsl: this.getSslSetEnabled() && this.form.usingSsl.isSelected(),
caCertificate: this.form.caCertificate.getValue(),
verifyCa: this.form.verifyCa.getValue()[0],
sslType: CONNECT_SSL_TYPE[0].value,
sslClientPrivateKey: this.form.sslClientPrivateKey.getValue(),
sslClientCertificate: this.form.sslClientCertificate.getValue(),
// 连接池
connectionPoolAttr: {
initialSize: this.form.initialSize.getValue(),
maxActive: this.form.maxActive.getValue(),
minIdle: this.form.minIdle.getValue(),
maxWait: this.form.maxWait.getValue(),
validationQuery: api.getCipher(this.form.validationQuery.getValue()),
testOnBorrow: BI.size(this.form.testOnBorrow.getValue()) > 0 ? this.form.testOnBorrow.getValue()[0] : connectionPoolAttr.testOnBorrow,
testOnReturn: BI.size(this.form.testOnReturn.getValue()) > 0 ? this.form.testOnReturn.getValue()[0] : connectionPoolAttr.testOnReturn,
testWhileIdle: BI.size(this.form.testWhileIdle.getValue()) > 0 ? this.form.testWhileIdle.getValue()[0] : connectionPoolAttr.testWhileIdle,
timeBetweenEvictionRunsMillis: this.form.timeBetweenEvictionRunsMillis.getValue(),
numTestsPerEvictionRun: this.form.numTestsPerEvictionRun.getValue(),
minEvictableIdleTimeMillis: this.form.minEvictableIdleTimeMillis.getValue(),
},
}),
};
}
}