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

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 { 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],

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'];
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;
},
}
}

38
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;
}

Loading…
Cancel
Save