Browse Source

Merge pull request #97 in DEC/decision-webui-dcm from ~ALAN/decision-webui-dcm:feature/10.0 to feature/10.0

* commit 'dbe84ee6c60e30858a5b737f0171248db2cd12b1':
  fix: DEC-10172 && DEC-10171 && DEC-10054 修改tooltip
qufenxi
alan 5 years ago
parent
commit
69d5831b09
  1. 97
      src/modules/components/text_checker/text_checker.ts
  2. 89
      src/modules/pages/maintain/forms/components/form.jdbc.ts
  3. 7
      src/modules/pages/maintain/forms/components/form.jndi.ts
  4. 22
      src/modules/pages/maintain/forms/form.model.ts
  5. 38
      src/modules/pages/maintain/forms/form.ts

97
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);
}
}

89
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 { connectionType } from '@constants/env';
import { CONNECT_CHARSET, CONNECTION_LAYOUT } from '@constants/constant'; import { CONNECT_CHARSET, CONNECTION_LAYOUT } from '@constants/constant';
import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service'; import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service';
import { TextCheckerXtype } from '../../../../components/text_checker/text_checker';
export const FormJdbcXtype = 'dec.dcm.maintain.form.jdbc'; export const FormJdbcXtype = 'dec.dcm.maintain.form.jdbc';
@shortcut(FormJdbcXtype) @shortcut(FormJdbcXtype)
export class FormJdbc extends BI.Widget { export class FormJdbc extends BI.Widget {
@ -71,7 +71,7 @@ export class FormJdbc extends BI.Widget {
type: FormItemXtype, type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Name'), name: BI.i18nText('Dec-Dcm_Connection_Name'),
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
value: connectionName, value: connectionName,
allowBlank: true, allowBlank: true,
@ -167,13 +167,16 @@ export class FormJdbc extends BI.Widget {
type: FormItemXtype, type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: port, value: port,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.port = _ref; this.form.port = _ref;
}, },
@ -403,12 +406,15 @@ export class FormJdbc extends BI.Widget {
type: FormItemXtype, type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: initialSize, value: initialSize,
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), 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'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.initialSize = _ref; this.form.initialSize = _ref;
@ -419,13 +425,16 @@ export class FormJdbc extends BI.Widget {
type: FormItemXtype, type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: maxActive, value: maxActive,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.maxActive = _ref; this.form.maxActive = _ref;
}, },
@ -435,13 +444,16 @@ export class FormJdbc extends BI.Widget {
type: FormItemXtype, type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'),
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: maxIdle, value: maxIdle,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.maxIdle = _ref; this.form.maxIdle = _ref;
}, },
@ -451,13 +463,16 @@ export class FormJdbc extends BI.Widget {
type: FormItemXtype, type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: minIdle, value: minIdle,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.minIdle = _ref; this.form.minIdle = _ref;
}, },
@ -468,13 +483,16 @@ export class FormJdbc extends BI.Widget {
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
forms: [ forms: [
{ {
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: maxWait, value: maxWait,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.maxWait = _ref; 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'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
forms: [ forms: [
{ {
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: timeBetweenEvictionRunsMillis, value: timeBetweenEvictionRunsMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Number'), validationChecker: [{
validationChecker: (value: string) => this.checkNumber(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Number'),
checker: (value: string) => this.checkNumber(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.timeBetweenEvictionRunsMillis = _ref; this.form.timeBetweenEvictionRunsMillis = _ref;
}, },
@ -574,13 +595,16 @@ export class FormJdbc extends BI.Widget {
type: FormItemXtype, type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: numTestsPerEvictionRun, value: numTestsPerEvictionRun,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.numTestsPerEvictionRun = _ref; 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'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
forms: [ forms: [
{ {
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
allowBlank: true, allowBlank: true,
value: minEvictableIdleTimeMillis, value: minEvictableIdleTimeMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'), validationChecker: [{
validationChecker: (value: string) => this.checkInteger(value), errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
}],
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.minEvictableIdleTimeMillis = _ref; 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) { private checkInteger(value: string) {
return /^[\d]+$/.test(value); return /^[\d]+$/.test(value);
} }

7
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 { CONNECT_CHARSET, CONNECTION_LAYOUT, JNDI_FACTORYS } from '@constants/constant';
import { CollapseXtype, EVENT_CHANGE } from 'src/modules/components/collapse/collapse'; import { CollapseXtype, EVENT_CHANGE } from 'src/modules/components/collapse/collapse';
import { connectionType } from '@constants/env'; import { connectionType } from '@constants/env';
import { TextCheckerXtype } from '../../../../components/text_checker/text_checker';
export const FormJndiXtype = 'dec.dcm.maintain.form.jndi'; export const FormJndiXtype = 'dec.dcm.maintain.form.jndi';
@shortcut(FormJndiXtype) @shortcut(FormJndiXtype)
export class FormJndi extends BI.Widget { export class FormJndi extends BI.Widget {
@ -49,7 +50,7 @@ export class FormJndi extends BI.Widget {
name: BI.i18nText('Dec-Dcm_Connection_Name'), name: BI.i18nText('Dec-Dcm_Connection_Name'),
nameWidth: 200, nameWidth: 200,
forms: [{ forms: [{
type: TextEditor, type: TextCheckerXtype,
width: 300, width: 300,
value: connectionName, value: connectionName,
ref: (_ref: any) => { 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 { public getSubmitValue():Connection {
const contextHashtable = { const contextHashtable = {
'java.naming.factory.initial': this.form.initial.getValue()[0], 'java.naming.factory.initial': this.form.initial.getValue()[0],

22
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']; context = ['datebaseTypeSelected', 'datebaseTypeSelectedOne', 'connectionSelectedOne', 'saveEvent', 'pageIndex', 'testEvent', 'connections', 'isCopy'];
actions = { actions = {
addConnection: (data: Connection) => { addConnection: (data: Connection) => api.addConnection(data),
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;
});
},
updateConnection: (name: string, data: Connection) => { updateConnection: (name: string, data: Connection) => {
data.connectionId = name; data.connectionId = name;
api.updateConnection(data).then(() => {
this.model.pageIndex = PAGE_INDEX.CONNECTION; return api.updateConnection(data);
});
}, },
shutdownConnectionStatus: (name: string) => api.shutdownConnectionStatus(name), shutdownConnectionStatus: (name: string) => api.shutdownConnectionStatus(name),
testConnection: (connection: Connection) => testConnection(connection), testConnection: (connection: Connection) => testConnection(connection),
@ -49,5 +36,8 @@ export class MaintainFormModel extends Model<{
isDriverError(errorCode: string) { isDriverError(errorCode: string) {
return api.isDriverError(errorCode); return api.isDriverError(errorCode);
}, },
goFirstPage() {
this.model.pageIndex = PAGE_INDEX.CONNECTION;
},
} }
} }

38
src/modules/pages/maintain/forms/form.ts

@ -29,11 +29,28 @@ export class MaintainForm extends BI.Widget {
return; return;
} }
if (this.connectionName && !this.model.isCopy) { 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 { } else {
const form = this.form.getSubmitValue(); const form = this.form.getSubmitValue();
form.connectionId = this.connectionName; 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: () => { testEvent: () => {
@ -161,18 +178,14 @@ export class MaintainForm extends BI.Widget {
private testValue():boolean { private testValue():boolean {
const value = this.form.getSubmitValue(); const value = this.form.getSubmitValue();
if (!value.connectionName) { if (!value.connectionName) {
BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'), { this.setFromError(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'));
level: 'error',
});
return false; return false;
} }
if (this.connectionName !== value.connectionName) { if (this.connectionName !== value.connectionName) {
const hasNamed = this.model.connections.some(item => item.connectionName === value.connectionName); const hasNamed = this.model.connections.some(item => item.connectionName === value.connectionName);
if (hasNamed) { if (hasNamed) {
BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Is_Existence'), { this.setFromError(BI.i18nText('Dec-Dcm_Connection_Is_Existence'));
level: 'error',
});
return false; return false;
} }
@ -181,6 +194,10 @@ export class MaintainForm extends BI.Widget {
return true; return true;
} }
private setFromError(errMsg: string) {
this.form.setError ? this.form.setError(errMsg) : null;
}
private getConnectionName(name = BI.i18nText('Dec-Dcm_Data_Connections')) { private getConnectionName(name = BI.i18nText('Dec-Dcm_Data_Connections')) {
const connections = this.model.connections.filter(item => item.connectionName.startsWith(name)); const connections = this.model.connections.filter(item => item.connectionName.startsWith(name));
if (connections.length === 0) { if (connections.length === 0) {
@ -199,6 +216,11 @@ export class MaintainForm extends BI.Widget {
private testConnection() { private testConnection() {
const formValue = this.form.getSubmitValue(); 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) { if (this.isEdit || this.model.isCopy) {
formValue.connectionId = this.connectionName; formValue.connectionId = this.connectionName;
} }

Loading…
Cancel
Save