帆软决策平台数据连接界面库
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.
 
 
 
 

705 lines
31 KiB

import { shortcut } from '@core/core';
import { Vertical, TextEditor, TextValueCombo, Label, TextAreaEditor, Editor, SingleSelectInsertCombo } from 'ui';
import { CollapseXtype, EVENT_CHANGE } from 'src/modules/components/collapse/collapse';
import { FormItemXtype } from '../../components/form_item/form_item';
import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud/crud.typings';
import { connectionType } from '@constants/env';
import { CONNECT_CHARSET } from '@constants/constant';
import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service';
export const FormJdbcXtype = 'dec.dcm.maintain.form.jdbc';
@shortcut(FormJdbcXtype)
export class FormJdbc extends BI.Widget {
props = {
formData: {} as Connection,
}
oldPassword = '';
allDatabaseTypes = getAllDatabaseTypes();
private schemas = [] as string[];
testStatus: any;
advancedSet: any;
formUser: any;
formPassword: any;
formPrincipal: any;
formKeyPath: any;
labelTips: any;
form = {
connectionName: null,
driver: null,
database: null,
host: null,
port: null,
user: null,
password: null,
authType: null,
principal: null,
keyPath: null,
newCharsetName: 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,
minEvictableIdleTimeMillis: null,
};
render() {
const { connectionName, connectionData } = this.options.formData;
const { driver, user, password, newCharsetName, schema, url, connectionPoolAttr, database, authType, principal, keyPath } = connectionData as ConnectionJDBC;
// minIdle 暂未使用
const { initialSize, maxActive, maxIdle, maxWait, validationQuery, testOnBorrow, testOnReturn, testWhileIdle, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis } = connectionPoolAttr as ConnectionPoolJDBC;
const databaseType = getJdbcDatabaseType(database, driver);
this.oldPassword = password;
const { host, port, databaseName } = resolveUrlInfo(url);
return {
type: Vertical,
hgap: 15,
vgap: 15,
items: [
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Name'),
forms: [{
type: TextEditor,
width: 300,
value: connectionName,
allowBlank: true,
ref: (_ref: any) => {
this.form.connectionName = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Data_Connections'),
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
forms: [{
type: SingleSelectInsertCombo,
width: 300,
value: driver,
ref: (_ref: any) => {
this.form.driver = _ref;
},
itemsCreator: (options: {
keywords?: string[],
selectedValues: string[],
times: number,
type: number,
}, callback: Function) => {
let drivers = this.getDrivers();
if (options.selectedValues.length > 0) {
drivers = drivers.filter(item => item.text !== options.selectedValues[0]);
}
callback({
items: drivers,
hasNext: false,
});
},
listeners: [{
eventName: BI.SingleSelectInsertCombo.EVENT_CONFIRM,
action: () => {
const value = this.form.driver.getValue();
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
if (connectionType.urls) {
this.form.url.setValue(connectionType.urls[value]);
const urlInfo = resolveUrlInfo(connectionType.urls[value]);
this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);
}
},
}],
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
forms: [{
type: TextEditor,
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: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
forms: [{
type: TextEditor,
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: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: port,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
ref: (_ref: any) => {
this.form.port = _ref;
},
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
}],
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_AuthType'),
invisible: !databaseType.kerberos,
forms: [{
type: TextValueCombo,
width: 300,
value: authType,
ref: (_ref: any) => {
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: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
invisible: !!authType,
ref: (_ref: any) => {
this.formUser = _ref;
},
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: user,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
ref: (_ref: any) => {
this.form.user = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
invisible: !!authType,
ref: (_ref: any) => {
this.formPassword = _ref;
},
forms: [{
type: Editor,
cls: 'bi-border',
width: 300,
height: 20,
allowBlank: true,
value: password,
inputType: 'password',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
ref: (_ref: any) => {
this.form.password = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Principal'),
invisible: !authType,
ref: (_ref: any) => {
this.formPrincipal = _ref;
},
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: principal,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Principal'),
ref: (_ref: any) => {
this.form.principal = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
invisible: !authType,
ref: (_ref: any) => {
this.formKeyPath = _ref;
},
forms: [{
type: Editor,
cls: 'bi-border',
width: 300,
height: 20,
allowBlank: true,
value: keyPath,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
ref: (_ref: any) => {
this.form.keyPath = _ref;
},
}],
},
{
type: Label,
cls: 'bi-tips',
textAlign: 'left',
invisible: true,
text: BI.i18nText('Dec-Dcm_Connection_JDBC_Warning'),
ref: (_ref: any) => {
this.labelTips = _ref;
},
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
forms: [{
type: TextValueCombo,
width: 300,
value: newCharsetName ? newCharsetName : '',
items: CONNECT_CHARSET,
ref: (_ref: any) => {
this.form.newCharsetName = _ref;
},
}],
},
{
type: FormItemXtype,
invisible: !databaseType.hasSchema,
name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'),
forms: [{
type: SingleSelectInsertCombo,
width: 300,
value: schema,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'),
ref: (_ref: any) => {
this.form.schema = _ref;
},
itemsCreator: (options: {
keywords?: string[],
selectedValues: string[],
times: number,
type: number,
}, callback: Function) => {
let schemas = this.schemas;
if (options.selectedValues && options.selectedValues.length > 0) {
schemas = schemas.filter(item => item !== options.selectedValues[0]);
}
callback({
items: schemas.map(item => {
return {
text: item,
value: item,
};
}),
hasNext: false,
});
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: url,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
ref: (_ref: any) => {
this.form.url = _ref;
},
listeners: [{
eventName: 'EVENT_CHANGE',
action: () => {
const urlInfo = resolveUrlInfo(this.form.url.getValue());
this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);
},
}],
}],
},
{
type: CollapseXtype,
width: 70,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'),
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.advancedSet.setVisible(!isCollapse);
},
},
],
},
{
type: Vertical,
vgap: 15,
invisible: true,
ref: (_ref: any) => {
this.advancedSet = _ref;
},
items: [
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: initialSize,
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
validationChecker: (value: string) => this.checkInteger(value),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
ref: (_ref: any) => {
this.form.initialSize = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: maxActive,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
validationChecker: (value: string) => this.checkInteger(value),
ref: (_ref: any) => {
this.form.maxActive = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'),
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: maxIdle,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
validationChecker: (value: string) => this.checkInteger(value),
ref: (_ref: any) => {
this.form.maxIdle = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
forms: [
{
type: TextEditor,
width: 300,
allowBlank: true,
value: maxWait,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
validationChecker: (value: string) => this.checkInteger(value),
ref: (_ref: any) => {
this.form.maxWait = _ref;
},
},
{
type: Label,
lgap: 5,
text: BI.i18nText('Dec-Dcm_Millisecond'),
},
],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
forms: [{
type: TextAreaEditor,
cls: 'bi-border',
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
value: validationQuery,
width: 300,
height: 100,
ref: (_ref: any) => {
this.form.validationQuery = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
forms: [{
type: TextValueCombo,
width: 300,
allowBlank: true,
value: testOnBorrow,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
ref: (_ref: any) => {
this.form.testOnBorrow = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
forms: [{
type: TextValueCombo,
width: 300,
allowBlank: true,
value: testOnReturn,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
ref: (_ref: any) => {
this.form.testOnReturn = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
forms: [{
type: TextValueCombo,
width: 300,
allowBlank: true,
value: testWhileIdle,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
ref: (_ref: any) => {
this.form.testWhileIdle = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
forms: [
{
type: TextEditor,
width: 300,
allowBlank: true,
value: timeBetweenEvictionRunsMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Number'),
validationChecker: (value: string) => this.checkNumber(value),
ref: (_ref: any) => {
this.form.timeBetweenEvictionRunsMillis = _ref;
},
},
{
type: Label,
lgap: 5,
text: BI.i18nText('Dec-Dcm_Millisecond'),
},
],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
forms: [{
type: TextEditor,
width: 300,
allowBlank: true,
value: numTestsPerEvictionRun,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
validationChecker: (value: string) => this.checkInteger(value),
ref: (_ref: any) => {
this.form.numTestsPerEvictionRun = _ref;
},
}],
},
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
forms: [
{
type: TextEditor,
width: 300,
allowBlank: true,
value: minEvictableIdleTimeMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
validationChecker: (value: string) => this.checkInteger(value),
ref: (_ref: any) => {
this.form.minEvictableIdleTimeMillis = _ref;
},
},
{
type: Label,
lgap: 5,
text: BI.i18nText('BI-Basic_Seconds'),
},
],
},
],
},
],
};
}
private checkInteger(value: string) {
return /^[\d]+$/.test(value);
}
private checkNumber(value: string) {
return /^[(\-|\+)?\d]+$/.test(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,
},
];
}
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 { url = '' } = databaseType;
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, url));
}
public setSchemas(schemas: string[]) {
this.schemas = schemas;
if (schemas.length > 0) {
this.form.schema.setValue(schemas[0]);
}
}
public getSubmitValue():Connection {
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionPoolAttr = connectionData.connectionPoolAttr;
return {
connectionType: connectionType.JDBC,
connectionId: this.form.connectionName.getValue(),
connectionName: this.form.connectionName.getValue(),
connectionData: {
database: connectionData.database,
connectionName: this.form.connectionName.getValue(),
driver: this.form.driver.getValue(),
url: this.form.url.getValue(),
user: this.form.user.getValue(),
password: this.oldPassword === this.form.password.getValue() ? this.oldPassword : BI.encode(this.form.password.getValue()),
queryType: '',
newCharsetName: this.form.newCharsetName.getValue()[0] || '',
originalCharsetName: this.form.newCharsetName.getValue()[0] || '',
schema: this.form.schema.getValue(),
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(),
connectionPoolAttr: {
initialSize: this.form.initialSize.getValue(),
maxActive: this.form.maxActive.getValue(),
maxIdle: this.form.maxIdle.getValue(),
maxWait: this.form.maxWait.getValue(),
validationQuery: this.form.validationQuery.getValue(),
testOnBorrow: this.form.testOnBorrow.getValue()[0] || connectionPoolAttr.testOnBorrow,
testOnReturn: this.form.testOnReturn.getValue()[0] || connectionPoolAttr.testOnReturn,
testWhileIdle: this.form.testWhileIdle.getValue()[0] || connectionPoolAttr.testWhileIdle,
timeBetweenEvictionRunsMillis: this.form.timeBetweenEvictionRunsMillis.getValue(),
numTestsPerEvictionRun: this.form.numTestsPerEvictionRun.getValue(),
minEvictableIdleTimeMillis: this.form.minEvictableIdleTimeMillis.getValue(),
},
},
};
}
}