diff --git a/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts b/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts index 6f97be8..5bb8a27 100644 --- a/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts +++ b/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts @@ -1,195 +1,195 @@ -import { shortcut, store } from '@core/core'; -import { FormItem } from '../components/form_item/form_item'; -import { Collapse, EVENT_CHANGE } from 'src/modules/components/collapse/collapse'; -import { ConnectionJdecModel } from './connection_jdbc.model'; -import { ConnectionJDBC } from 'src/modules/crud/crud.typings'; -import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo } from '../../../app.service'; -import { CONNECTION_LAYOUT } from '@constants/constant'; -import { VerticalLayout } from '@fui/core'; -import { ApiFactory } from '../../../crud/apiFactory'; - -const api = new ApiFactory().create(); - -@shortcut() -@store(ConnectionJdecModel) -export class ConnectionJdbc extends BI.Widget { - static xtype = 'dec.dcm.connection_jdbc'; - - advancedSet: any; - model: ConnectionJdecModel['model']; - allDatabaseTypes = getAllDatabaseTypes(); - - render() { - const connectionData = this.model.connectionSelectedOne.connectionData as ConnectionJDBC; - const { - driver, - driverSource, - database, - user, - originalCharsetName, - schema, - connectionPoolAttr, - authType, - principal, - url, - fetchSize, - } = connectionData; - const databaseType = getJdbcDatabaseType(database, driver); - const { host, port, databaseName } = resolveUrlInfo(url, database); - const { hgap, vgap } = CONNECTION_LAYOUT; - - return { - type: BI.VerticalLayout.xtype, - hgap, - vgap, - items: [ - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Driver'), - value: BI.isKey(driverSource) ? `${driver} (${driverSource})` : driver, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'), - value: databaseName, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Host'), - value: host, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'), - value: port, - }, - authType ? - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_AuthType'), - value: authType, - } : { - type: BI.Layout.xtype, - }, - { - type: FormItem.xtype, - name: authType ? BI.i18nText('Dec-Dcm_Connection_Form_Principal') : BI.i18nText('Dec-Dcm_Connection_Form_UserName'), - value: authType ? principal : user, - }, - { - type: FormItem.xtype, - name: authType ? BI.i18nText('Dec-Dcm_Connection_Form_KeyPath') : BI.i18nText('Dec-Dcm_Connection_Form_Password'), - value: '******', - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'), - value: originalCharsetName ? originalCharsetName : BI.i18nText('Dec-Dcm_Connection_Form_Default'), - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'), - value: schema, - invisible: !databaseType.hasSchema, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'), - value: url, - }, - { - type: Collapse.xtype, - width: 70, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'), - listeners: [ - { - eventName: EVENT_CHANGE, - action: (isCollapse: boolean) => { - this.advancedSet.setVisible(!isCollapse); - }, - }, - ], - }, - { - type: BI.VerticalLayout.xtype, - tgap: -15, - vgap, - invisible: true, - ref: (_ref: VerticalLayout) => { - this.advancedSet = _ref; - }, - items: [ - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'), - value: connectionPoolAttr.initialSize, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'), - value: connectionPoolAttr.maxActive, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'), - value: connectionPoolAttr.maxIdle, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'), - value: connectionPoolAttr.minIdle, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'), - value: connectionPoolAttr.maxWait, - unit: BI.i18nText('Dec-Dcm_Millisecond'), - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Validation_Query'), - value: api.getPlain(connectionPoolAttr.validationQuery || ''), - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Borrow'), - value: connectionPoolAttr.testOnBorrow ? BI.i18nText('Dec-Dcm_Yes') : BI.i18nText('Dec-Dcm_No'), - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'), - value: connectionPoolAttr.testOnReturn ? BI.i18nText('Dec-Dcm_Yes') : BI.i18nText('Dec-Dcm_No'), - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'), - value: connectionPoolAttr.testWhileIdle ? BI.i18nText('Dec-Dcm_Yes') : BI.i18nText('Dec-Dcm_No'), - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'), - value: connectionPoolAttr.timeBetweenEvictionRunsMillis, - unit: BI.i18nText('Dec-Dcm_Millisecond'), - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'), - value: connectionPoolAttr.numTestsPerEvictionRun, - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'), - value: connectionPoolAttr.minEvictableIdleTimeMillis, - unit: BI.i18nText('BI-Basic_Seconds'), - }, { - type: FormItem.xtype, - invisible: fetchSize < 0 && fetchSize !== -2, - name: 'Fetchsize', - value: fetchSize === -2 ? '' : fetchSize, - }, - ], - }, - ], - }; - } -} +import { shortcut, store } from '@core/core'; +import { FormItem } from '../components/form_item/form_item'; +import { Collapse, EVENT_CHANGE } from 'src/modules/components/collapse/collapse'; +import { ConnectionJdecModel } from './connection_jdbc.model'; +import { ConnectionJDBC } from 'src/modules/crud/crud.typings'; +import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo } from '../../../app.service'; +import { CONNECTION_LAYOUT } from '@constants/constant'; +import { VerticalLayout } from '@fui/core'; +import { ApiFactory } from '../../../crud/apiFactory'; + +const api = new ApiFactory().create(); + +@shortcut() +@store(ConnectionJdecModel) +export class ConnectionJdbc extends BI.Widget { + static xtype = 'dec.dcm.connection_jdbc'; + + advancedSet: any; + model: ConnectionJdecModel['model']; + allDatabaseTypes = getAllDatabaseTypes(); + + render() { + const connectionData = this.model.connectionSelectedOne.connectionData as ConnectionJDBC; + const { + driver, + driverSource, + database, + user, + originalCharsetName, + schema, + connectionPoolAttr, + authType, + principal, + url, + fetchSize, + } = connectionData; + const databaseType = getJdbcDatabaseType(database, driver); + const { host, port, databaseName } = resolveUrlInfo(url, database); + const { hgap, vgap } = CONNECTION_LAYOUT; + + return { + type: BI.VerticalLayout.xtype, + hgap, + vgap, + items: [ + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Driver'), + value: BI.isKey(driverSource) ? `${driver} (${driverSource})` : driver, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'), + value: databaseName, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Host'), + value: host, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'), + value: port, + }, + authType ? + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_AuthType'), + value: authType, + } : { + type: BI.Layout.xtype, + }, + { + type: FormItem.xtype, + name: authType ? BI.i18nText('Dec-Dcm_Connection_Form_Principal') : BI.i18nText('Dec-Dcm_Connection_Form_UserName'), + value: authType ? principal : user, + }, + { + type: FormItem.xtype, + name: authType ? BI.i18nText('Dec-Dcm_Connection_Form_KeyPath') : BI.i18nText('Dec-Dcm_Connection_Form_Password'), + value: '******', + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'), + value: originalCharsetName ? originalCharsetName : BI.i18nText('Dec-Dcm_Connection_Form_Default'), + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'), + value: schema, + invisible: !databaseType.hasSchema, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'), + value: url, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'), + value: connectionPoolAttr.maxActive, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Borrow'), + value: connectionPoolAttr.testOnBorrow ? BI.i18nText('Dec-Dcm_Yes') : BI.i18nText('Dec-Dcm_No'), + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Validation_Query'), + value: api.getPlain(connectionPoolAttr.validationQuery || ''), + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'), + value: connectionPoolAttr.maxWait, + unit: BI.i18nText('Dec-Dcm_Millisecond'), + }, + { + type: Collapse.xtype, + width: 70, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'), + listeners: [ + { + eventName: EVENT_CHANGE, + action: (isCollapse: boolean) => { + this.advancedSet.setVisible(!isCollapse); + }, + }, + ], + }, + { + type: BI.VerticalLayout.xtype, + tgap: -15, + vgap, + invisible: true, + ref: (_ref: VerticalLayout) => { + this.advancedSet = _ref; + }, + items: [ + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'), + value: connectionPoolAttr.initialSize, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'), + value: connectionPoolAttr.maxIdle, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'), + value: connectionPoolAttr.minIdle, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'), + value: connectionPoolAttr.testOnReturn ? BI.i18nText('Dec-Dcm_Yes') : BI.i18nText('Dec-Dcm_No'), + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'), + value: connectionPoolAttr.testWhileIdle ? BI.i18nText('Dec-Dcm_Yes') : BI.i18nText('Dec-Dcm_No'), + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'), + value: connectionPoolAttr.timeBetweenEvictionRunsMillis, + unit: BI.i18nText('Dec-Dcm_Millisecond'), + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'), + value: connectionPoolAttr.numTestsPerEvictionRun, + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'), + value: connectionPoolAttr.minEvictableIdleTimeMillis, + unit: BI.i18nText('BI-Basic_Seconds'), + }, { + type: FormItem.xtype, + invisible: fetchSize < 0 && fetchSize !== -2, + name: 'Fetchsize', + value: fetchSize === -2 ? '' : fetchSize, + }, + ], + }, + ], + }; + } +} diff --git a/src/modules/pages/maintain/forms/components/form.jdbc.ts b/src/modules/pages/maintain/forms/components/form.jdbc.ts index d9fe88c..af4dbca 100644 --- a/src/modules/pages/maintain/forms/components/form.jdbc.ts +++ b/src/modules/pages/maintain/forms/components/form.jdbc.ts @@ -1,879 +1,879 @@ -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 } from '@constants/constant'; -import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service'; -import { TextChecker } from '../../../../components/text_checker/text_checker'; -import { ApiFactory } from 'src/modules/crud/apiFactory'; -import { - Editor, - EditorIconCheckCombo, - Label, - TextAreaEditor, - TextEditor, - TextValueCombo, - VerticalLayout, -} from '@fui/core'; -import { DriverSelector } from '../../components/driverselector/driverselector'; - -const api = new ApiFactory().create(); - -@shortcut() -export class FormJdbc extends BI.Widget { - static xtype = 'dec.dcm.maintain.form.jdbc'; - - props = { - formData: {} as Connection, - }; - - oldPassword = ''; - allDatabaseTypes = getAllDatabaseTypes(); - - advancedSet: VerticalLayout; - formUser: FormItem; - formPassword: FormItem; - formPrincipal: FormItem; - formKeyPath: FormItem; - labelTips: Label; - - form = { - connectionName: null, - driver: null, - database: null, - host: null, - port: null, - user: null, - password: null, - authType: null, - principal: null, - keyPath: null, - originalCharsetName: null, - schema: null, - url: null, - initialSize: null, - maxActive: null, - maxIdle: null, - maxWait: null, - 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, - fetchSize, - } = connectionData as ConnectionJDBC; - const { - initialSize, - maxActive, - maxIdle, - maxWait, - validationQuery, - testOnBorrow, - testOnReturn, - testWhileIdle, - timeBetweenEvictionRunsMillis, - numTestsPerEvictionRun, - minIdle, - minEvictableIdleTimeMillis, - } = connectionPoolAttr as ConnectionPoolJDBC; - const databaseType = getJdbcDatabaseType(database, driver); - this.oldPassword = password; - 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.formUser.setVisible(!type); - this.formPassword.setVisible(!type); - this.labelTips.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; - }, - }], - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_Principal'), - invisible: !authType, - ref: (_ref: FormItem) => { - this.formPrincipal = _ref; - }, - forms: [{ - type: BI.TextEditor.xtype, - $value: 'principal', - width: 300, - allowBlank: true, - value: principal, - watermark: BI.i18nText('Dec-Dcm_Connection_Form_Principal'), - ref: (_ref: TextEditor) => { - this.form.principal = _ref; - }, - }], - }, - { - type: FormItem.xtype, - name: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'), - invisible: !authType, - ref: (_ref: FormItem) => { - this.formKeyPath = _ref; - }, - forms: [{ - type: BI.Editor.xtype, - $value: 'key-path', - cls: 'bi-border', - width: 300, - height: 20, - allowBlank: true, - value: keyPath, - watermark: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'), - ref: (_ref: Editor) => { - this.form.keyPath = _ref; - }, - }], - }, - { - type: BI.Label.xtype, - cls: 'bi-tips', - textAlign: 'left', - invisible: true, - text: BI.i18nText('Dec-Dcm_Connection_JDBC_Warning'), - ref: (_ref: Label) => { - this.labelTips = _ref; - }, - }, - { - 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, - }, - { - 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: Collapse.xtype, - bgap: -15, - width: 70, - name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'), - listeners: [ - { - eventName: EVENT_CHANGE, - action: (isCollapse: boolean) => { - this.advancedSet.setVisible(!isCollapse); - }, - }, - ], - }, - { - type: BI.VerticalLayout.xtype, - vgap, - tgap: -15, - invisible: true, - ref: (_ref: VerticalLayout) => { - this.advancedSet = _ref; - }, - items: [ - { - type: FormItem.xtype, - tgap: 15, - 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_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_Max_Idle'), - forms: [{ - type: TextChecker.xtype, - $value: 'max-idle', - width: 300, - allowBlank: false, - value: maxIdle, - watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'), - validationChecker: [{ - errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), - checker: (value: string) => this.checkInteger(value), - autoFix: true, - }, valueRangeConfig], - ref: (_ref: TextChecker) => { - this.form.maxIdle = _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_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'), - }, - ], - }, - { - 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_Place_Input'), - 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_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_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 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)); - } - - 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 validation(): boolean { - return this.form.driver.validation(); - } - - 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: 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(), - keyPath: this.form.keyPath.getValue(), - fetchSize: BI.isEmptyString(this.form.fetchSize.getValue()) ? -2 : BI.parseInt(this.form.fetchSize.getValue()), - connectionPoolAttr: { - initialSize: this.form.initialSize.getValue(), - maxActive: this.form.maxActive.getValue(), - maxIdle: this.form.maxIdle.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(), - }, - }), - }; - } -} +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 } from '@constants/constant'; +import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service'; +import { TextChecker } from '../../../../components/text_checker/text_checker'; +import { ApiFactory } from 'src/modules/crud/apiFactory'; +import { + Editor, + EditorIconCheckCombo, + Label, + TextAreaEditor, + TextEditor, + TextValueCombo, + VerticalLayout, +} from '@fui/core'; +import { DriverSelector } from '../../components/driverselector/driverselector'; + +const api = new ApiFactory().create(); + +@shortcut() +export class FormJdbc extends BI.Widget { + static xtype = 'dec.dcm.maintain.form.jdbc'; + + props = { + formData: {} as Connection, + }; + + oldPassword = ''; + allDatabaseTypes = getAllDatabaseTypes(); + + advancedSet: VerticalLayout; + formUser: FormItem; + formPassword: FormItem; + formPrincipal: FormItem; + formKeyPath: FormItem; + labelTips: Label; + + form = { + connectionName: null, + driver: null, + database: null, + host: null, + port: null, + user: null, + password: null, + authType: null, + principal: null, + keyPath: null, + originalCharsetName: null, + schema: null, + url: null, + initialSize: null, + maxActive: null, + maxIdle: null, + maxWait: null, + 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, + fetchSize, + } = connectionData as ConnectionJDBC; + const { + initialSize, + maxActive, + maxIdle, + maxWait, + validationQuery, + testOnBorrow, + testOnReturn, + testWhileIdle, + timeBetweenEvictionRunsMillis, + numTestsPerEvictionRun, + minIdle, + minEvictableIdleTimeMillis, + } = connectionPoolAttr as ConnectionPoolJDBC; + const databaseType = getJdbcDatabaseType(database, driver); + this.oldPassword = password; + 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.formUser.setVisible(!type); + this.formPassword.setVisible(!type); + this.labelTips.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; + }, + }], + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_Principal'), + invisible: !authType, + ref: (_ref: FormItem) => { + this.formPrincipal = _ref; + }, + forms: [{ + type: BI.TextEditor.xtype, + $value: 'principal', + width: 300, + allowBlank: true, + value: principal, + watermark: BI.i18nText('Dec-Dcm_Connection_Form_Principal'), + ref: (_ref: TextEditor) => { + this.form.principal = _ref; + }, + }], + }, + { + type: FormItem.xtype, + name: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'), + invisible: !authType, + ref: (_ref: FormItem) => { + this.formKeyPath = _ref; + }, + forms: [{ + type: BI.Editor.xtype, + $value: 'key-path', + cls: 'bi-border', + width: 300, + height: 20, + allowBlank: true, + value: keyPath, + watermark: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'), + ref: (_ref: Editor) => { + this.form.keyPath = _ref; + }, + }], + }, + { + type: BI.Label.xtype, + cls: 'bi-tips', + textAlign: 'left', + invisible: true, + text: BI.i18nText('Dec-Dcm_Connection_JDBC_Warning'), + ref: (_ref: Label) => { + this.labelTips = _ref; + }, + }, + { + 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, + }, + { + 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_Place_Input'), + 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'), + }, + ], + }, + { + type: Collapse.xtype, + bgap: -15, + width: 70, + name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'), + listeners: [ + { + eventName: EVENT_CHANGE, + action: (isCollapse: boolean) => { + this.advancedSet.setVisible(!isCollapse); + }, + }, + ], + }, + { + type: BI.VerticalLayout.xtype, + vgap, + tgap: -15, + invisible: true, + ref: (_ref: VerticalLayout) => { + this.advancedSet = _ref; + }, + items: [ + { + type: FormItem.xtype, + tgap: 15, + 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_Max_Idle'), + forms: [{ + type: TextChecker.xtype, + $value: 'max-idle', + width: 300, + allowBlank: false, + value: maxIdle, + watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }, valueRangeConfig], + ref: (_ref: TextChecker) => { + this.form.maxIdle = _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 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)); + } + + 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 validation(): boolean { + return this.form.driver.validation(); + } + + 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: 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(), + keyPath: this.form.keyPath.getValue(), + fetchSize: BI.isEmptyString(this.form.fetchSize.getValue()) ? -2 : BI.parseInt(this.form.fetchSize.getValue()), + connectionPoolAttr: { + initialSize: this.form.initialSize.getValue(), + maxActive: this.form.maxActive.getValue(), + maxIdle: this.form.maxIdle.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(), + }, + }), + }; + } +}