Browse Source

数据源管理功能完善

master
peng.peng 2 years ago
parent
commit
1d073dc453
  1. 35
      api/app/lib/controllers/metadataAcquisition/dataSource.js
  2. 6
      web/client/src/sections/metadataAcquisition/components/adapterStep.js
  3. 2
      web/client/src/sections/metadataAcquisition/components/dataSourceManagementModal.js
  4. 10
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepOne.js
  5. 58
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js
  6. 16
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepTwo.js
  7. 14
      web/client/src/sections/metadataAcquisition/containers/dataSourceManagement.js

35
api/app/lib/controllers/metadataAcquisition/dataSource.js

@ -6,10 +6,18 @@ function addDataSource(opts) {
const models = ctx.fs.dc.models;
try {
let rslt = ctx.request.body;
await models.DataSource.create(Object.assign({}, rslt))
ctx.status = 204;
ctx.body = { message: '新建数据源成功' }
const { name } = ctx.request.body
const checkName = await models.DataSource.findOne({ where: { name, name } });
if (checkName) {
ctx.status = 400;
ctx.body = { message: '该数据源名称已存在' }
} else {
let rslt = ctx.request.body;
await models.DataSource.create(Object.assign({}, rslt))
let datasource = await models.DataSource.findOne({ where: { name } })
ctx.status = 200;
ctx.body = { message: '新建数据源成功', id: datasource.id }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
@ -69,12 +77,19 @@ function editDataSource(opts) {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
const body = ctx.request.body;
await models.DataSource.update(
body,
{ where: { id: id, } }
)
ctx.status = 204;
ctx.body = { message: '修改数据源成功' }
const { name } = ctx.request.body
const checkName = await models.DataSource.findOne({ where: { id: { $not: id }, name, name } });
if (checkName) {
ctx.status = 400;
ctx.body = { message: '该数据源名称已存在' }
} else {
await models.DataSource.update(
body,
{ where: { id: id, } }
)
ctx.status = 204;
ctx.body = { message: '修改数据源成功' }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;

6
web/client/src/sections/metadataAcquisition/components/adapterStep.js

@ -28,10 +28,10 @@ const AdapterStep = (props) => {
setCurrent(current - 1);
};
const onFinish = () => {
const onFinish = (values) => {
props.onFinish({
stepOneValues,
stepTwoValues
stepTwoValues: values || stepTwoValues
})
}
@ -41,7 +41,7 @@ const AdapterStep = (props) => {
const stepTwoValuesFinish = (values) => {
setStepTwoValues(values)
if (stepProps == 2) onFinish()
if (stepProps == 2) onFinish(values)
}
const steps = [

2
web/client/src/sections/metadataAcquisition/components/dataSourceManagementModal.js

@ -22,7 +22,7 @@ function DataSourceModal(props) {
onFinish={onFinish}
stepProps={2}
currentChange={c => { setCurrent(c) }}
stepOneInitValue={{ ...editData, ...editData?.adapterInfo }}
stepOneInitValue={{ ...editData, ...editData?.adapterInfo, description: editData?.description }}
stepTwoInitValue={{ ...editData?.config }}
{...props}
/>

10
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepOne.js

@ -18,15 +18,6 @@ function StepOne(props) {
mountPath: 1,
}
const checkName = async (rule, value) => {
let filter = dataSources?.rows?.find(s => s?.name == value && value !== stepOneInitValue?.name)
if (filter) {
return Promise.reject(new Error('已存该数据源名称!'));
}
return Promise.resolve();
}
const formItemLayout = { labelCol: { span: 3 }, wrapperCol: { span: 10 } };
return <>
<ProForm
@ -56,7 +47,6 @@ function StepOne(props) {
rules={[
{ required: true, message: '请输入数据源名称' },
{ max: 255, message: '数据源名称长度不能大于255个字符' },
{ validator: checkName }
]}
name="name"
label="数据源名称"

58
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js

@ -5,7 +5,9 @@ import {
ProFormSelect,
ProFormTextArea,
ProFormText,
ProFormDigit
ProFormDigit,
ProFormCheckbox,
ProFormDependency
} from '@ant-design/pro-form';
import '../../style.less';
@ -43,7 +45,7 @@ function StepThree(props) {
rules={[{ required: true, message: '请输入数据源名称' },
{ max: 255, message: '数据源名称长度不能大于255个字符' },
]}
name="name"
name="taskName"
label="名称"
style={{
minWidth: 140,
@ -54,30 +56,50 @@ function StepThree(props) {
rules={[{ required: true, message: '请输入cron表达式' },
{ max: 255, message: 'cron表达式长度不能大于255个字符' },
]}
name="name"
name="cron"
label="请输入cron表达式"
style={{
minWidth: 140,
}}
addonAfter={<Button>测试</Button>}
/>
<ProFormDigit
rules={[{ required: true, message: '请输入重试次数' },
{ max: 10, message: '重试次数不能大于10个字符' },
]}
name="name"
label="重试次数"
fieldProps={{ precision: 0, max: 10, }}
<ProFormCheckbox
// rules={[{ required: true, message: '请选择重试次数' }]}
name="retried"
label="重试"
/>
<ProFormText
rules={[{ required: true, message: '请输入时间间隔' },
{ max: 255, message: '时间间隔长度不能大于255个字符' },
]}
name="name"
label="时间间隔"
addonAfter={'分钟'}
/>
<ProFormDependency name={['retried']}>
{({ retried }) => {
return retried ?
<>
<ProFormDigit
rules={[
// { required: true, message: '请输入重试次数' },
// { max: 10, message: '重试次数不能大于10个字符' },
]}
name="retryCount"
label="重试次数"
fieldProps={{ precision: 0, max: 10, }}
/>
<ProFormDigit
rules={[
// { required: true, message: '请输入时间间隔' },
// { max: 255, message: '时间间隔长度不能大于255个字符' },
]}
name="retryTime"
label="时间间隔"
addonAfter={'分钟'}
/>
</>
: null
}}
</ProFormDependency>
</ProForm.Group>

16
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepTwo.js

@ -68,7 +68,7 @@ function StepTwo(props) {
key: 'value',
render: (text, record) => {
return <Input
type={text == "password" ? "password" : ''}
// type={text == "password" ? "password" : ''}
defaultValue={stepTwoValues ? stepTwoValues[text] : ''}
onChange={(e) => {
const obj = {};
@ -116,12 +116,14 @@ function StepTwo(props) {
<div className='step-footer'>
<Button style={{ margin: '0 8px', }} onClick={() => prev()}>上一步</Button>
<Button disabled={connect !== '连接成功'} type="primary" onClick={() => {
if (checkNext() === true) {
stepTwoValuesFinish(params)
next()
}
}}>
<Button
// disabled={connect !== '连接成功'}
type="primary" onClick={() => {
if (checkNext() === true) {
stepTwoValuesFinish(params)
next()
}
}}>
{stepProps > 2 ? '下一步' : '保存'}
</Button>
</div>

14
web/client/src/sections/metadataAcquisition/containers/dataSourceManagement.js

@ -125,13 +125,19 @@ function DataSourceManagement(props) {
}
if (editData) {
dispatch(actions.metadataAcquisition.modifyDataSource(editData?.id, dataToSave)).then(res => {
setVisible(false)
queryData();
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
} else {
dispatch(actions.metadataAcquisition.addDataSource(dataToSave)).then(res => {
setVisible(false)
queryData();
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
}
}

Loading…
Cancel
Save