From 9b00df9af8587e56ef29e2edb8e3aa3e0db4a8af Mon Sep 17 00:00:00 2001 From: alan Date: Fri, 27 Sep 2019 16:11:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=B9=E6=8D=AE=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E4=BF=AE=E6=94=B9=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=A8=A1=E5=BC=8F=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/scripts/dec.js | 1 + src/modules/constants/env.ts | 1 + .../connection/list/list_item/list_item.ts | 72 +------------- .../maintain/forms/components/form.jdbc.ts | 68 +++++++------ .../pages/maintain/forms/form.server.ts | 84 ++++++++++++++++ src/modules/pages/maintain/forms/form.ts | 99 ++++--------------- 6 files changed, 147 insertions(+), 178 deletions(-) create mode 100644 src/modules/pages/maintain/forms/form.server.ts diff --git a/assets/scripts/dec.js b/assets/scripts/dec.js index 5752599..a9a806e 100644 --- a/assets/scripts/dec.js +++ b/assets/scripts/dec.js @@ -2,6 +2,7 @@ window.DecCst = { ErrorCode: { CONNECTION_DELETED: '21300035', CONNECTION_UNDER_EDIT: '21300034', + DUPLICATE_NAMES: '21300005', }, Connect: { ConnectionType: { diff --git a/src/modules/constants/env.ts b/src/modules/constants/env.ts index dbf063b..3ddd37c 100644 --- a/src/modules/constants/env.ts +++ b/src/modules/constants/env.ts @@ -10,4 +10,5 @@ export const editStatusEvent = DecCst.Connect.EditStatusEvent; export const errorCode: { CONNECTION_DELETED: string; CONNECTION_UNDER_EDIT: string; + DUPLICATE_NAMES: string; } = DecCst.ErrorCode; diff --git a/src/modules/pages/connection/list/list_item/list_item.ts b/src/modules/pages/connection/list/list_item/list_item.ts index e0bd557..f7fe1fa 100644 --- a/src/modules/pages/connection/list/list_item/list_item.ts +++ b/src/modules/pages/connection/list/list_item/list_item.ts @@ -2,12 +2,10 @@ import { shortcut, store } from '@core/core'; import { Label, LeftRightVerticalAdapt, IconLabel, IconButton, DownListCombo, SignEditor, Layout } from 'ui'; import './list_item.less'; import { ListItemModel, ListItemModelXtype } from './list_item.model'; -import { PAGE_INDEX, DATA_BASE_DRIVER_LINK } from '@constants/constant'; -import { TestStatusXtype, TestStatus, EVENT_CLOSE, EVENT_RELOAD } from 'src/modules/components/test_status/test_status'; +import { PAGE_INDEX } from '@constants/constant'; import { hasRegistered } from '../list.service'; -import { connectionType } from '@constants/env'; -import { ConnectionJDBC } from 'src/modules/crud/crud.typings'; import { connectionCanEdit, getTextByDatabaseType } from '../../../../app.service'; +import { testConnection } from '../../../maintain/forms/form.server'; export const ListItemXtype = 'dec.dcm.connection.list_item'; @shortcut(ListItemXtype) @@ -28,7 +26,6 @@ export class ListItem extends BI.BasicButton { nameLabel: any; nameEditor: any; downListCombo: any; - testStatus: TestStatus; watch = { isEdit: (isEdit: boolean) => { @@ -185,69 +182,8 @@ export class ListItem extends BI.BasicButton { } private testConnectionAction() { - const { name, databaseType } = this.options; - const id = BI.UUID(); - const testConnection = () => { - this.store.testConnection(name).then(re => { - if (re && re.errorCode) { - // 判断是否是缺少驱动,如果缺少驱动则显示下载驱动的连接 - if (this.store.isDriverError(re.errorCode)) { - const thisConnection = this.model.connections.find(item => item.connectionName === name); - if (thisConnection.connectionType === connectionType.JDBC) { - const driver = (thisConnection.connectionData as ConnectionJDBC).driver; - const databaseLink = BI.get(DATA_BASE_DRIVER_LINK.find(item => item.databaseType === databaseType), 'link'); - this.testStatus.setFail(re.errorMsg, driver, Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][databaseLink]); - } else { - this.testStatus.setFail(re.errorMsg); - } - } else { - this.testStatus.setFail(re.errorMsg); - } - } else if (re.data) { - this.testStatus.setSuccess(); - setTimeout(() => { - BI.Maskers.remove(id); - }, 1000 * 2); - } else { - BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Error'), { - level: 'error', - }); - BI.Maskers.remove(id); - } - }); - }; - BI.Maskers.create(id, null, { - render: { - type: TestStatusXtype, - loadingText: BI.i18nText('Dec-Dcm_Connection_Testing'), - loadingCls: 'upload-loading-icon', - successText: BI.i18nText('Dec-Dcm_Connection_Test_Success'), - successCls: 'upload-success-icon', - failText: BI.i18nText('Dec-Dcm_Connection_Test_Fail', name), - failCls: 'upload-fail-icon', - retryText: BI.i18nText('Dec-Dcm_Connection_ReConnect'), - ref: (_ref: any) => { - this.testStatus = _ref; - }, - listeners: [ - { - eventName: EVENT_RELOAD, - action: () => { - this.testStatus.setLoading(); - testConnection(); - }, - }, - { - eventName: EVENT_CLOSE, - action: () => { - BI.Maskers.remove(id); - }, - }, - ], - }, - }); - BI.Maskers.show(id); - testConnection(); + const { name } = this.options; + testConnection(this.model.connections.find(item => item.connectionName === name)); } private itemActionCalculate() { diff --git a/src/modules/pages/maintain/forms/components/form.jdbc.ts b/src/modules/pages/maintain/forms/components/form.jdbc.ts index 5ebfaaa..c79ee50 100644 --- a/src/modules/pages/maintain/forms/components/form.jdbc.ts +++ b/src/modules/pages/maintain/forms/components/form.jdbc.ts @@ -1,5 +1,5 @@ import { shortcut } from '@core/core'; -import { Vertical, TextEditor, TextValueCombo, Label, TextAreaEditor, Editor, SingleSelectInsertCombo } from 'ui'; +import { Vertical, TextEditor, TextValueCombo, Label, TextAreaEditor, Editor, SingleSelectInsertCombo, Left, TextButton } 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'; @@ -328,33 +328,33 @@ export class FormJdbc extends BI.Widget { 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: Vertical, + items: [{ + type: Left, + items: [{ + type: TextButton, + cls: 'bi-high-light', + text: BI.i18nText('Dec-Dcm_Connection_Click_Connect_Database'), + handler: () => { + this.fireEvent('EVENT_TEST_CONNECTION'); + }, + }, { + type: Label, + cls: 'bi-tips', + lgap: 3, + text: BI.i18nText('Dec-Dcm_Connection_Read_Mode_List'), + }], + }, { + type: TextValueCombo, + width: 300, + vgap: 15, + disabled: true, + value: schema, + items: this.schemas, + ref: (_ref: any) => { + this.form.schema = _ref; + }, + }], }], }, { @@ -659,8 +659,16 @@ export class FormJdbc extends BI.Widget { public setSchemas(schemas: string[]) { this.schemas = schemas; + this.form.schema.setEnable(true); if (schemas.length > 0) { - this.form.schema.setValue(schemas[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 ? value : schemas[0]); } } @@ -682,7 +690,7 @@ export class FormJdbc extends BI.Widget { queryType: '', newCharsetName: this.form.newCharsetName.getValue()[0] || '', originalCharsetName: this.form.newCharsetName.getValue()[0] || '', - schema: this.form.schema.getValue(), + schema: this.form.schema.getValue()[0], host: this.form.host.getValue(), authType: this.form.authType.getValue()[0] || '', creator: Dec ? Dec.personal.username : '', diff --git a/src/modules/pages/maintain/forms/form.server.ts b/src/modules/pages/maintain/forms/form.server.ts new file mode 100644 index 0000000..8ec4473 --- /dev/null +++ b/src/modules/pages/maintain/forms/form.server.ts @@ -0,0 +1,84 @@ +import { Connection, ConnectionJDBC } from '../../../crud/crud.typings'; +import { connectionType, errorCode } from '@constants/env'; +import { DATA_BASE_DRIVER_LINK } from '@constants/constant'; +import { TestStatusXtype, EVENT_RELOAD, EVENT_CLOSE } from '../../../components/test_status/test_status'; +import { ApiFactory } from '../../../crud/apiFactory'; +const api = new ApiFactory().create(); +export function testConnection(value: Connection): Promise { + return new Promise(resolve => { + let testStatus = null; + if (!value.connectionName) { + BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'), { + level: 'error', + }); + + return false; + } + const id = BI.UUID(); + const testConnection = () => { + const formValue = value; + api.testConnection(formValue).then(re => { + if (re && re.errorCode) { + // 判断是否是缺少驱动,如果缺少驱动则显示下载驱动的连接 + if (api.isDriverError(re.errorCode)) { + if (formValue.connectionType === connectionType.JDBC) { + const driver = (formValue.connectionData as ConnectionJDBC).driver; + const databaseType = (formValue.connectionData as ConnectionJDBC).database; + const databaseLink = BI.get(DATA_BASE_DRIVER_LINK.find(item => item.databaseType === databaseType), 'link'); + testStatus.setFail(re.errorMsg, driver, Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][databaseLink]); + } else { + testStatus.setFail(re.errorMsg); + } + } else if (re.errorCode === errorCode.DUPLICATE_NAMES) { + testStatus.setFail(BI.i18nText(re.errorMsg)); + } else { + testStatus.setFail(re.errorMsg); + } + } else if (re.data) { + testStatus.setSuccess(); + resolve(re.data); + setTimeout(() => { + BI.Maskers.remove(id); + }, 1000 * 2); + } else { + BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Error'), { + level: 'error', + }); + BI.Maskers.remove(id); + } + }); + }; + BI.Maskers.create(id, null, { + render: { + type: TestStatusXtype, + loadingText: BI.i18nText('Dec-Dcm_Connection_Testing'), + loadingCls: 'upload-loading-icon', + successText: BI.i18nText('Dec-Dcm_Connection_Test_Success'), + successCls: 'upload-success-icon', + failText: BI.i18nText('Dec-Dcm_Connection_Test_Fail', name), + failCls: 'upload-fail-icon', + retryText: BI.i18nText('Dec-Dcm_Connection_ReConnect'), + ref: (_ref: any) => { + testStatus = _ref; + }, + listeners: [ + { + eventName: EVENT_RELOAD, + action: () => { + testStatus.setLoading(); + testConnection(); + }, + }, + { + eventName: EVENT_CLOSE, + action: () => { + BI.Maskers.remove(id); + }, + }, + ], + }, + }); + BI.Maskers.show(id); + testConnection(); + }); +} diff --git a/src/modules/pages/maintain/forms/form.ts b/src/modules/pages/maintain/forms/form.ts index e7db2a3..6094efa 100644 --- a/src/modules/pages/maintain/forms/form.ts +++ b/src/modules/pages/maintain/forms/form.ts @@ -5,10 +5,9 @@ import { FormJndiXtype } from './components/form.jndi'; import { FormPluginXtype } from './components/form.plugin'; import { connectionType } from '@constants/env'; import { ConnectionJDBC, Connection } from 'src/modules/crud/crud.typings'; -import { TestStatusXtype, EVENT_RELOAD, EVENT_CLOSE } from 'src/modules/components/test_status/test_status'; -import { DEFAULT_JNDI_DATA, DEFAULT_JDBC_POOL, DATA_BASE_DRIVER_LINK, DATEBASE_FILTER_TYPE } from '@constants/constant'; +import { DEFAULT_JNDI_DATA, DEFAULT_JDBC_POOL, DATEBASE_FILTER_TYPE } from '@constants/constant'; import { getJdbcDatabaseType } from 'src/modules/app.service'; - +import { testConnection } from './form.server'; export const MaintainFormXtype = 'dec.dcm.maintain.form'; @shortcut(MaintainFormXtype) @store(MaintainFormModelXtype) @@ -39,83 +38,7 @@ export class MaintainForm extends BI.Widget { } }, testEvent: () => { - const value = this.form.getSubmitValue(); - if (!value.connectionName) { - BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'), { - level: 'error', - }); - - return false; - } - const id = BI.UUID(); - const testConnection = () => { - const formValue = this.form.getSubmitValue(); - if (this.isEdit || this.model.isCopy) { - formValue.connectionId = this.connectionName; - } - this.store.testConnection(formValue).then(re => { - if (re && re.errorCode) { - // 判断是否是缺少驱动,如果缺少驱动则显示下载驱动的连接 - if (this.store.isDriverError(re.errorCode)) { - if (formValue.connectionType === connectionType.JDBC) { - const driver = (formValue.connectionData as ConnectionJDBC).driver; - const databaseType = (formValue.connectionData as ConnectionJDBC).database; - const databaseLink = BI.get(DATA_BASE_DRIVER_LINK.find(item => item.databaseType === databaseType), 'link'); - this.testStatus.setFail(re.errorMsg, driver, Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][databaseLink]); - } else { - this.testStatus.setFail(re.errorMsg); - } - } else { - this.testStatus.setFail(re.errorMsg); - } - } else if (re.data) { - this.testStatus.setSuccess(); - if (re.data.length > 0) { - this.form.setSchemas && this.form.setSchemas(re.data); - } - setTimeout(() => { - BI.Maskers.remove(id); - }, 1000 * 2); - } else { - BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Error'), { - level: 'error', - }); - BI.Maskers.remove(id); - } - }); - }; - BI.Maskers.create(id, null, { - render: { - type: TestStatusXtype, - loadingText: BI.i18nText('Dec-Dcm_Connection_Testing'), - loadingCls: 'upload-loading-icon', - successText: BI.i18nText('Dec-Dcm_Connection_Test_Success'), - successCls: 'upload-success-icon', - failText: BI.i18nText('Dec-Dcm_Connection_Test_Fail', name), - failCls: 'upload-fail-icon', - retryText: BI.i18nText('Dec-Dcm_Connection_ReConnect'), - ref: (_ref: any) => { - this.testStatus = _ref; - }, - listeners: [ - { - eventName: EVENT_RELOAD, - action: () => { - this.testStatus.setLoading(); - testConnection(); - }, - }, - { - eventName: EVENT_CLOSE, - action: () => { - BI.Maskers.remove(id); - }, - }, - ], - }, - }); - BI.Maskers.show(id); - testConnection(); + this.testConnection(); }, } @@ -132,6 +55,12 @@ export class MaintainForm extends BI.Widget { ref: (_ref: any) => { this.form = _ref; }, + listeners: [{ + eventName: 'EVENT_TEST_CONNECTION', + action: () => { + this.testConnection(); + }, + }], }; } @@ -263,4 +192,14 @@ export class MaintainForm extends BI.Widget { return `${name}${index + 1}`; } + + private testConnection() { + const formValue = this.form.getSubmitValue(); + if (this.isEdit || this.model.isCopy) { + formValue.connectionId = this.connectionName; + } + testConnection(formValue).then(re => { + this.form.setSchemas(re); + }); + } }