You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.7 KiB
85 lines
3.7 KiB
6 years ago
|
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();
|
||
|
});
|
||
|
}
|