Browse Source

fix: 根据最新交互修改,调整数据库模式交互逻辑。

qufenxi
alan 5 years ago
parent
commit
d4b3980bf1
  1. 1
      assets/scripts/dec.js
  2. 1
      src/modules/constants/env.ts
  3. 72
      src/modules/pages/connection/list/list_item/list_item.ts
  4. 58
      src/modules/pages/maintain/forms/components/form.jdbc.ts
  5. 84
      src/modules/pages/maintain/forms/form.server.ts
  6. 99
      src/modules/pages/maintain/forms/form.ts

1
assets/scripts/dec.js

@ -2,6 +2,7 @@ window.DecCst = {
ErrorCode: { ErrorCode: {
CONNECTION_DELETED: '21300035', CONNECTION_DELETED: '21300035',
CONNECTION_UNDER_EDIT: '21300034', CONNECTION_UNDER_EDIT: '21300034',
DUPLICATE_NAMES: '21300005',
}, },
Connect: { Connect: {
ConnectionType: { ConnectionType: {

1
src/modules/constants/env.ts

@ -10,4 +10,5 @@ export const editStatusEvent = DecCst.Connect.EditStatusEvent;
export const errorCode: { export const errorCode: {
CONNECTION_DELETED: string; CONNECTION_DELETED: string;
CONNECTION_UNDER_EDIT: string; CONNECTION_UNDER_EDIT: string;
DUPLICATE_NAMES: string;
} = DecCst.ErrorCode; } = DecCst.ErrorCode;

72
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 { Label, LeftRightVerticalAdapt, IconLabel, IconButton, DownListCombo, SignEditor, Layout } from 'ui';
import './list_item.less'; import './list_item.less';
import { ListItemModel, ListItemModelXtype } from './list_item.model'; import { ListItemModel, ListItemModelXtype } from './list_item.model';
import { PAGE_INDEX, DATA_BASE_DRIVER_LINK } from '@constants/constant'; import { PAGE_INDEX } from '@constants/constant';
import { TestStatusXtype, TestStatus, EVENT_CLOSE, EVENT_RELOAD } from 'src/modules/components/test_status/test_status';
import { hasRegistered } from '../list.service'; 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 { connectionCanEdit, getTextByDatabaseType } from '../../../../app.service';
import { testConnection } from '../../../maintain/forms/form.server';
export const ListItemXtype = 'dec.dcm.connection.list_item'; export const ListItemXtype = 'dec.dcm.connection.list_item';
@shortcut(ListItemXtype) @shortcut(ListItemXtype)
@ -28,7 +26,6 @@ export class ListItem extends BI.BasicButton {
nameLabel: any; nameLabel: any;
nameEditor: any; nameEditor: any;
downListCombo: any; downListCombo: any;
testStatus: TestStatus;
watch = { watch = {
isEdit: (isEdit: boolean) => { isEdit: (isEdit: boolean) => {
@ -185,69 +182,8 @@ export class ListItem extends BI.BasicButton {
} }
private testConnectionAction() { private testConnectionAction() {
const { name, databaseType } = this.options; const { name } = this.options;
const id = BI.UUID(); testConnection(this.model.connections.find(item => item.connectionName === name));
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();
} }
private itemActionCalculate() { private itemActionCalculate() {

58
src/modules/pages/maintain/forms/components/form.jdbc.ts

@ -1,5 +1,5 @@
import { shortcut } from '@core/core'; 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 { CollapseXtype, EVENT_CHANGE } from 'src/modules/components/collapse/collapse';
import { FormItemXtype } from '../../components/form_item/form_item'; import { FormItemXtype } from '../../components/form_item/form_item';
import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud/crud.typings'; import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud/crud.typings';
@ -328,33 +328,33 @@ export class FormJdbc extends BI.Widget {
invisible: !databaseType.hasSchema, invisible: !databaseType.hasSchema,
name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'), name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'),
forms: [{ forms: [{
type: SingleSelectInsertCombo, 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, width: 300,
vgap: 15,
disabled: true,
value: schema, value: schema,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'), items: this.schemas,
ref: (_ref: any) => { ref: (_ref: any) => {
this.form.schema = _ref; 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,
});
},
}], }],
}, },
{ {
@ -659,8 +659,16 @@ export class FormJdbc extends BI.Widget {
public setSchemas(schemas: string[]) { public setSchemas(schemas: string[]) {
this.schemas = schemas; this.schemas = schemas;
this.form.schema.setEnable(true);
if (schemas.length > 0) { 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: '', queryType: '',
newCharsetName: this.form.newCharsetName.getValue()[0] || '', newCharsetName: this.form.newCharsetName.getValue()[0] || '',
originalCharsetName: 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(), host: this.form.host.getValue(),
authType: this.form.authType.getValue()[0] || '', authType: this.form.authType.getValue()[0] || '',
creator: Dec ? Dec.personal.username : '', creator: Dec ? Dec.personal.username : '',

84
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<string[]> {
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();
});
}

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

@ -5,10 +5,9 @@ import { FormJndiXtype } from './components/form.jndi';
import { FormPluginXtype } from './components/form.plugin'; import { FormPluginXtype } from './components/form.plugin';
import { connectionType } from '@constants/env'; import { connectionType } from '@constants/env';
import { ConnectionJDBC, Connection } from 'src/modules/crud/crud.typings'; 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, DATEBASE_FILTER_TYPE } from '@constants/constant';
import { DEFAULT_JNDI_DATA, DEFAULT_JDBC_POOL, DATA_BASE_DRIVER_LINK, DATEBASE_FILTER_TYPE } from '@constants/constant';
import { getJdbcDatabaseType } from 'src/modules/app.service'; import { getJdbcDatabaseType } from 'src/modules/app.service';
import { testConnection } from './form.server';
export const MaintainFormXtype = 'dec.dcm.maintain.form'; export const MaintainFormXtype = 'dec.dcm.maintain.form';
@shortcut(MaintainFormXtype) @shortcut(MaintainFormXtype)
@store(MaintainFormModelXtype) @store(MaintainFormModelXtype)
@ -39,83 +38,7 @@ export class MaintainForm extends BI.Widget {
} }
}, },
testEvent: () => { testEvent: () => {
const value = this.form.getSubmitValue(); this.testConnection();
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();
}, },
} }
@ -132,6 +55,12 @@ export class MaintainForm extends BI.Widget {
ref: (_ref: any) => { ref: (_ref: any) => {
this.form = _ref; 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}`; 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);
});
}
} }

Loading…
Cancel
Save