From dbe84ee6c60e30858a5b737f0171248db2cd12b1 Mon Sep 17 00:00:00 2001 From: alan Date: Mon, 30 Sep 2019 13:35:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20DEC-10172=20&&=20DEC-10171=20&&=20DEC-10?= =?UTF-8?q?054=20=E4=BF=AE=E6=94=B9tooltip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/text_checker/text_checker.ts | 97 +++++++++++++++++++ .../maintain/forms/components/form.jdbc.ts | 89 +++++++++++------ .../maintain/forms/components/form.jndi.ts | 7 +- .../pages/maintain/forms/form.model.ts | 22 ++--- src/modules/pages/maintain/forms/form.ts | 38 ++++++-- 5 files changed, 199 insertions(+), 54 deletions(-) create mode 100644 src/modules/components/text_checker/text_checker.ts diff --git a/src/modules/components/text_checker/text_checker.ts b/src/modules/components/text_checker/text_checker.ts new file mode 100644 index 0000000..430e761 --- /dev/null +++ b/src/modules/components/text_checker/text_checker.ts @@ -0,0 +1,97 @@ +import { shortcut } from '@core/core'; +import { TextEditor, Absolute, Label } from 'ui'; +export const TextCheckerXtype = 'dec.dcm.components.text_checker'; +@shortcut(TextCheckerXtype) +export class TextChecker extends BI.Widget { + props = { + width: 300, + allowBlank: true, + value: '', + watermark: '', + validationChecker: [] as { + errorText: string; + checker: (value: string) => boolean; + autoFix?: boolean; + }[], + } + + textEditor: any; + errorLabel: any; + private isError; + private value: string; + private errorChecker: { + errorText: string; + checker: (value: string) => boolean; + autoFix?: boolean; + } + + render() { + const { width, allowBlank, value, watermark, validationChecker } = this.options; + this.value = value; + + return { + type: Absolute, + width, + height: 20, + items: [{ + el: { + type: TextEditor, + width, + allowBlank, + value, + watermark, + ref: (_ref: any) => { + this.textEditor = _ref; + }, + listeners: [{ + eventName: BI.Editor.EVENT_CHANGE, + action: () => { + const value = this.getValue(); + if (value) { + this.errorChecker = validationChecker.find(item => item.checker && !item.checker(value)); + this.errorLabel.setText(BI.get(this.errorChecker, 'errorText')); + this.isError = !!BI.get(this.errorChecker, 'errorText'); + } else { + this.errorLabel.setText(''); + this.isError = false; + } + if (!this.isError) { + this.value = value; + } + this.fireEvent(BI.Editor.EVENT_CHANGE); + }, + }, { + eventName: BI.TextEditor.EVENT_BLUR, + action: () => { + if (BI.get(this.errorChecker, 'autoFix')) { + this.setValue(this.value); + this.errorLabel.setText(''); + } + }, + }], + }, + }, { + el: { + type: Label, + cls: 'bi-error', + ref: (_ref: any) => { + this.errorLabel = _ref; + }, + }, + top: -15, + }], + }; + } + + public getValue(): string { + return this.textEditor.getValue(); + } + + public setValue(value: string) { + return this.textEditor.setValue(value); + } + + public setError(value: string) { + this.errorLabel.setText(value); + } +} diff --git a/src/modules/pages/maintain/forms/components/form.jdbc.ts b/src/modules/pages/maintain/forms/components/form.jdbc.ts index e9d16d4..48a8b10 100644 --- a/src/modules/pages/maintain/forms/components/form.jdbc.ts +++ b/src/modules/pages/maintain/forms/components/form.jdbc.ts @@ -6,7 +6,7 @@ import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud import { connectionType } from '@constants/env'; import { CONNECT_CHARSET, CONNECTION_LAYOUT } from '@constants/constant'; import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service'; - +import { TextCheckerXtype } from '../../../../components/text_checker/text_checker'; export const FormJdbcXtype = 'dec.dcm.maintain.form.jdbc'; @shortcut(FormJdbcXtype) export class FormJdbc extends BI.Widget { @@ -71,7 +71,7 @@ export class FormJdbc extends BI.Widget { type: FormItemXtype, name: BI.i18nText('Dec-Dcm_Connection_Name'), forms: [{ - type: TextEditor, + type: TextCheckerXtype, width: 300, value: connectionName, allowBlank: true, @@ -167,13 +167,16 @@ export class FormJdbc extends BI.Widget { type: FormItemXtype, name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'), forms: [{ - type: TextEditor, + type: TextCheckerXtype, width: 300, allowBlank: true, value: port, watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'), - errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), - validationChecker: (value: string) => this.checkInteger(value), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.port = _ref; }, @@ -403,12 +406,15 @@ export class FormJdbc extends BI.Widget { type: FormItemXtype, name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'), forms: [{ - type: TextEditor, + type: TextCheckerXtype, width: 300, allowBlank: true, value: initialSize, - errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), - validationChecker: (value: string) => this.checkInteger(value), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'), ref: (_ref: any) => { this.form.initialSize = _ref; @@ -419,13 +425,16 @@ export class FormJdbc extends BI.Widget { type: FormItemXtype, name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'), forms: [{ - type: TextEditor, + type: TextCheckerXtype, 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), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.maxActive = _ref; }, @@ -435,13 +444,16 @@ export class FormJdbc extends BI.Widget { type: FormItemXtype, name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'), forms: [{ - type: TextEditor, + type: TextCheckerXtype, 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), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.maxIdle = _ref; }, @@ -451,13 +463,16 @@ export class FormJdbc extends BI.Widget { type: FormItemXtype, name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'), forms: [{ - type: TextEditor, + type: TextCheckerXtype, width: 300, allowBlank: true, value: minIdle, watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'), - errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), - validationChecker: (value: string) => this.checkInteger(value), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.minIdle = _ref; }, @@ -468,13 +483,16 @@ export class FormJdbc extends BI.Widget { name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'), forms: [ { - type: TextEditor, + type: TextCheckerXtype, 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), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.maxWait = _ref; }, @@ -552,13 +570,16 @@ export class FormJdbc extends BI.Widget { name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'), forms: [ { - type: TextEditor, + type: TextCheckerXtype, 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), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Number'), + checker: (value: string) => this.checkNumber(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.timeBetweenEvictionRunsMillis = _ref; }, @@ -574,13 +595,16 @@ export class FormJdbc extends BI.Widget { type: FormItemXtype, name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'), forms: [{ - type: TextEditor, + type: TextCheckerXtype, 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), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.numTestsPerEvictionRun = _ref; }, @@ -591,13 +615,16 @@ export class FormJdbc extends BI.Widget { name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'), forms: [ { - type: TextEditor, + type: TextCheckerXtype, 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), + validationChecker: [{ + errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), + checker: (value: string) => this.checkInteger(value), + autoFix: true, + }], ref: (_ref: any) => { this.form.minEvictableIdleTimeMillis = _ref; }, @@ -615,6 +642,10 @@ export class FormJdbc extends BI.Widget { }; } + public setError(value: string) { + this.form.connectionName.setError(value); + } + private checkInteger(value: string) { return /^[\d]+$/.test(value); } diff --git a/src/modules/pages/maintain/forms/components/form.jndi.ts b/src/modules/pages/maintain/forms/components/form.jndi.ts index dea1b49..a271df4 100644 --- a/src/modules/pages/maintain/forms/components/form.jndi.ts +++ b/src/modules/pages/maintain/forms/components/form.jndi.ts @@ -5,6 +5,7 @@ import { ConnectionJNDI, Connection, ContextHashtable } from 'src/modules/crud/c import { CONNECT_CHARSET, CONNECTION_LAYOUT, JNDI_FACTORYS } from '@constants/constant'; import { CollapseXtype, EVENT_CHANGE } from 'src/modules/components/collapse/collapse'; import { connectionType } from '@constants/env'; +import { TextCheckerXtype } from '../../../../components/text_checker/text_checker'; export const FormJndiXtype = 'dec.dcm.maintain.form.jndi'; @shortcut(FormJndiXtype) export class FormJndi extends BI.Widget { @@ -49,7 +50,7 @@ export class FormJndi extends BI.Widget { name: BI.i18nText('Dec-Dcm_Connection_Name'), nameWidth: 200, forms: [{ - type: TextEditor, + type: TextCheckerXtype, width: 300, value: connectionName, ref: (_ref: any) => { @@ -359,6 +360,10 @@ export class FormJndi extends BI.Widget { }; } + public setError(value: string) { + this.form.connectionName.setError(value); + } + public getSubmitValue():Connection { const contextHashtable = { 'java.naming.factory.initial': this.form.initial.getValue()[0], diff --git a/src/modules/pages/maintain/forms/form.model.ts b/src/modules/pages/maintain/forms/form.model.ts index e062ba3..a7f5ec6 100644 --- a/src/modules/pages/maintain/forms/form.model.ts +++ b/src/modules/pages/maintain/forms/form.model.ts @@ -22,24 +22,11 @@ export class MaintainFormModel extends Model<{ context = ['datebaseTypeSelected', 'datebaseTypeSelectedOne', 'connectionSelectedOne', 'saveEvent', 'pageIndex', 'testEvent', 'connections', 'isCopy']; actions = { - addConnection: (data: Connection) => { - api.addConnection(data).then(result => { - if (result.errorCode) { - BI.Msg.toast(BI.i18nText(result.errorMsg), { - level: 'error', - }); - - return; - } - this.model.pageIndex = PAGE_INDEX.CONNECTION; - this.model.isCopy = false; - }); - }, + addConnection: (data: Connection) => api.addConnection(data), updateConnection: (name: string, data: Connection) => { data.connectionId = name; - api.updateConnection(data).then(() => { - this.model.pageIndex = PAGE_INDEX.CONNECTION; - }); + + return api.updateConnection(data); }, shutdownConnectionStatus: (name: string) => api.shutdownConnectionStatus(name), testConnection: (connection: Connection) => testConnection(connection), @@ -49,5 +36,8 @@ export class MaintainFormModel extends Model<{ isDriverError(errorCode: string) { return api.isDriverError(errorCode); }, + goFirstPage() { + this.model.pageIndex = PAGE_INDEX.CONNECTION; + }, } } diff --git a/src/modules/pages/maintain/forms/form.ts b/src/modules/pages/maintain/forms/form.ts index e6e8352..05a1903 100644 --- a/src/modules/pages/maintain/forms/form.ts +++ b/src/modules/pages/maintain/forms/form.ts @@ -29,11 +29,28 @@ export class MaintainForm extends BI.Widget { return; } if (this.connectionName && !this.model.isCopy) { - this.store.updateConnection(this.connectionName, this.form.getSubmitValue()); + const value = this.form.getSubmitValue(); + (value.connectionData as ConnectionJDBC).creator = BI.get(this.getFormData().connectionData, 'creator'); + this.store.updateConnection(this.connectionName, value).then(result => { + if (result.errorCode) { + this.setFromError(BI.i18nText(result.errorMsg)); + + return; + } + this.store.goFirstPage(); + }); } else { const form = this.form.getSubmitValue(); form.connectionId = this.connectionName; - this.store.addConnection(form); + this.store.addConnection(form).then(result => { + if (result.errorCode) { + this.setFromError(BI.i18nText(result.errorMsg)); + + return; + } + this.store.goFirstPage(); + this.store.setIsCopy(false); + }); } }, testEvent: () => { @@ -161,18 +178,14 @@ export class MaintainForm extends BI.Widget { private testValue():boolean { const value = this.form.getSubmitValue(); if (!value.connectionName) { - BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'), { - level: 'error', - }); + this.setFromError(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null')); return false; } if (this.connectionName !== value.connectionName) { const hasNamed = this.model.connections.some(item => item.connectionName === value.connectionName); if (hasNamed) { - BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Is_Existence'), { - level: 'error', - }); + this.setFromError(BI.i18nText('Dec-Dcm_Connection_Is_Existence')); return false; } @@ -181,6 +194,10 @@ export class MaintainForm extends BI.Widget { return true; } + private setFromError(errMsg: string) { + this.form.setError ? this.form.setError(errMsg) : null; + } + private getConnectionName(name = BI.i18nText('Dec-Dcm_Data_Connections')) { const connections = this.model.connections.filter(item => item.connectionName.startsWith(name)); if (connections.length === 0) { @@ -199,6 +216,11 @@ export class MaintainForm extends BI.Widget { private testConnection() { const formValue = this.form.getSubmitValue(); + if (!formValue.connectionName) { + this.setFromError(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null')); + + return; + } if (this.isEdit || this.model.isCopy) { formValue.connectionId = this.connectionName; }