Commit bec4a91d by zhaochengxiang

采集

parent 25c0900a
...@@ -4,6 +4,12 @@ import moment from 'moment'; ...@@ -4,6 +4,12 @@ import moment from 'moment';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
function compare(val1, val2) {
var a = val1.seq;
var b = val2.seq;
return (a - b);
}
const ScheduleAction = (props) => { const ScheduleAction = (props) => {
const { action, id, form, tid, onChange } = props; const { action, id, form, tid, onChange } = props;
...@@ -11,7 +17,7 @@ const ScheduleAction = (props) => { ...@@ -11,7 +17,7 @@ const ScheduleAction = (props) => {
useEffect(() => { useEffect(() => {
reset(); reset();
if (action === 'add' && tid) { if (action === 'add') {
getScheduleForm(); getScheduleForm();
} else if (action === 'edit' && id) { } else if (action === 'edit' && id) {
getScheduleById(); getScheduleById();
...@@ -26,6 +32,9 @@ const ScheduleAction = (props) => { ...@@ -26,6 +32,9 @@ const ScheduleAction = (props) => {
targetConfId: tid targetConfId: tid
}, },
callback: data => { callback: data => {
(data?.targetParameters||[]).sort(compare);
(data?.scheduleParameters||[]).sort(compare);
setSchedule(data||{}); setSchedule(data||{});
onChange && onChange(data||{}); onChange && onChange(data||{});
} }
...@@ -39,12 +48,6 @@ const ScheduleAction = (props) => { ...@@ -39,12 +48,6 @@ const ScheduleAction = (props) => {
id id
}, },
callback: data => { callback: data => {
function compare(val1, val2) {
var a = val1.seq;
var b = val2.seq;
return (a - b);
}
(data?.targetParameters||[]).sort(compare); (data?.targetParameters||[]).sort(compare);
(data?.scheduleParameters||[]).sort(compare); (data?.scheduleParameters||[]).sort(compare);
......
...@@ -170,7 +170,7 @@ const FC = (props) => { ...@@ -170,7 +170,7 @@ const FC = (props) => {
return () => { return () => {
clearInterval(interval); clearInterval(interval);
} }
}, []) }, [env])
const _columns = useMemo(() => { const _columns = useMemo(() => {
if (visibleCols) { if (visibleCols) {
...@@ -191,6 +191,7 @@ const FC = (props) => { ...@@ -191,6 +191,7 @@ const FC = (props) => {
&& (configState.datasourceId===undefined || item.target?.id === configState.datasourceId) && (configState.datasourceId===undefined || item.target?.id === configState.datasourceId)
&& (configState.targetType===undefined || item.target?.type === configState.targetType) && (configState.targetType===undefined || item.target?.type === configState.targetType)
&& (!keyword || (item.taskCode||'').indexOf(keyword)!==-1 || (item.schema||'').indexOf(keyword)!==-1) && (!keyword || (item.taskCode||'').indexOf(keyword)!==-1 || (item.schema||'').indexOf(keyword)!==-1)
&& item.target?.namespace === env?.domainId?.toString()
}); });
newTasks?.forEach(item => { newTasks?.forEach(item => {
const index = (supportedTargetTypes||[]).findIndex(_item => _item.targetType === item.type); const index = (supportedTargetTypes||[]).findIndex(_item => _item.targetType === item.type);
...@@ -216,7 +217,7 @@ const FC = (props) => { ...@@ -216,7 +217,7 @@ const FC = (props) => {
} }
return [] return []
}, [tasks, pagination, configState, supportedTargetTypes, sortedInfo, keyword]) }, [tasks, pagination, configState, supportedTargetTypes, sortedInfo, keyword, env])
const total = useMemo(() => { const total = useMemo(() => {
if (tasks) { if (tasks) {
...@@ -225,13 +226,14 @@ const FC = (props) => { ...@@ -225,13 +226,14 @@ const FC = (props) => {
&& (configState.datasourceId===undefined || item.target?.id === configState.datasourceId) && (configState.datasourceId===undefined || item.target?.id === configState.datasourceId)
&& (configState.targetType===undefined || item.target?.type === configState.targetType) && (configState.targetType===undefined || item.target?.type === configState.targetType)
&& (!keyword || item.taskCode?.indexOf(keyword)!==-1 || item.schema?.indexOf(keyword)!==-1) && (!keyword || item.taskCode?.indexOf(keyword)!==-1 || item.schema?.indexOf(keyword)!==-1)
&& item.target?.namespace === env?.domainId?.toString()
}); });
return (newTasks||[]).length; return (newTasks||[]).length;
} }
return 0; return 0;
}, [tasks, pagination, configState, keyword]) }, [tasks, pagination, configState, keyword, env])
const getAllTasks = () => { const getAllTasks = () => {
setLoadingTasks(true); setLoadingTasks(true);
...@@ -299,12 +301,9 @@ const FC = (props) => { ...@@ -299,12 +301,9 @@ const FC = (props) => {
setPagination({pageNum: page, pageSize: size }); setPagination({pageNum: page, pageSize: size });
} }
const onUpdateTaskCancel = () => { const onUpdateTaskCancel = (refresh = false) => {
setUpdateTaskParam({ visible: false, action: undefined, id: undefined }); setUpdateTaskParam({ visible: false, action: undefined, id: undefined });
} refresh && getAllTasks();
const onUpdateTaskChange = () => {
getAllTasks();
} }
const onColConfigCancel = (refresh = false) => { const onColConfigCancel = (refresh = false) => {
...@@ -444,7 +443,7 @@ const FC = (props) => { ...@@ -444,7 +443,7 @@ const FC = (props) => {
dataSource={_tasks||[]} dataSource={_tasks||[]}
pagination={false} pagination={false}
onChange={onTableChange} onChange={onTableChange}
scroll={{ y: 'calc(100vh - 330px)' }} scroll={{ y: 'calc(100vh - 315px)' }}
sticky sticky
/> />
<Pagination <Pagination
...@@ -466,7 +465,6 @@ const FC = (props) => { ...@@ -466,7 +465,6 @@ const FC = (props) => {
action={updateTaskParam.action} action={updateTaskParam.action}
id={updateTaskParam.id} id={updateTaskParam.id}
onCancel={onUpdateTaskCancel} onCancel={onUpdateTaskCancel}
onChange={onUpdateTaskChange}
/> />
<ColConfig <ColConfig
...@@ -481,8 +479,6 @@ const FC = (props) => { ...@@ -481,8 +479,6 @@ const FC = (props) => {
export default FC; export default FC;
export const reducer = (prevState, action) => { export const reducer = (prevState, action) => {
const scope = undefined, targetType = undefined, datasourceId = undefined;
if (action.type === 'selectScope') { if (action.type === 'selectScope') {
const [scope] = action.payload const [scope] = action.payload
return { ...prevState, scope } return { ...prevState, scope }
...@@ -493,7 +489,7 @@ export const reducer = (prevState, action) => { ...@@ -493,7 +489,7 @@ export const reducer = (prevState, action) => {
const [datasourceId] = action.payload const [datasourceId] = action.payload
return { ...prevState, datasourceId } return { ...prevState, datasourceId }
} else if (action.type === 'init') { } else if (action.type === 'init') {
return { ...prevState, scope, targetType, datasourceId } return { ...prevState, scope: undefined, targetType: undefined, datasourceId: undefined }
} }
return prevState return prevState
...@@ -531,10 +527,10 @@ export function Config({ onState, autoSelect, setTargetTypes }) { ...@@ -531,10 +527,10 @@ export function Config({ onState, autoSelect, setTargetTypes }) {
setTreeData(env.children); setTreeData(env.children);
setTreeExpandKeys(newExpandKeys); setTreeExpandKeys(newExpandKeys);
dispatchState('init'); dispatchState({type: 'init'});
} else { } else {
setTreeData([]); setTreeData([]);
dispatchState('init'); dispatchState({type: 'init'});
} }
}, [env]) }, [env])
...@@ -544,7 +540,7 @@ export function Config({ onState, autoSelect, setTargetTypes }) { ...@@ -544,7 +540,7 @@ export function Config({ onState, autoSelect, setTargetTypes }) {
useEffect(() => { useEffect(() => {
getDatasources(); getDatasources();
}, [scope]) }, [scope, env])
useEffect(() => { useEffect(() => {
if (autoSelect && (datasources||[]).length > 0) { if (autoSelect && (datasources||[]).length > 0) {
......
...@@ -79,10 +79,13 @@ const FC = (props) => { ...@@ -79,10 +79,13 @@ const FC = (props) => {
}, [reportData]) }, [reportData])
const taskCodes = useMemo(() => { const taskCodes = useMemo(() => {
return tasks?.filter(item => item.taskCode).map(item => item.taskCode) return tasks?.filter(item => item.target?.namespace===env?.domainId?.toString() && item.taskCode).map(item => item.taskCode)
}, [tasks]) }, [tasks, env])
useEffect(() => { useEffect(() => {
setTaskCode(undefined);
setDatasourceName(undefined);
setReportState(undefined);
getAllTasks(); getAllTasks();
getDatasources(); getDatasources();
}, [env]) }, [env])
...@@ -377,7 +380,7 @@ const FC = (props) => { ...@@ -377,7 +380,7 @@ const FC = (props) => {
}, },
}} }}
pagination={false} pagination={false}
scroll={{ y: 'calc(100vh - 415px)' }} scroll={{ y: 'calc(100vh - 400px)' }}
sticky sticky
/> />
<Pagination <Pagination
......
import React, { useEffect, useMemo, useState } from 'react'; import React, { useEffect, useMemo, useState } from 'react';
import { Modal, Checkbox, Row, Col, Divider, Input, Typography, Form, Switch, Spin } from 'antd'; import { Modal, Checkbox, Row, Col, Divider, Input, Typography, Form, Switch, Spin, Space } from 'antd';
import { Config } from './Task'; import { Config } from './Task';
import ScheduleAction from '../../DatasourceManage/Component/ScheduleAction'; import ScheduleAction from '../../DatasourceManage/Component/ScheduleAction';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
const FC = (props) => { const FC = (props) => {
const {visible, onCancel, onChange, action, id} = props; const {visible, onCancel, action, id} = props;
const [schemas, setSchemas] = useState([]); const [schemas, setSchemas] = useState([]);
const [filterSchemas, setFilterSchemas] = useState([]); const [filterSchemas, setFilterSchemas] = useState([]);
const [selectedSchemas, setSelectedSchemas] = useState([]); const [selectedSchemas, setSelectedSchemas] = useState([]);
...@@ -17,21 +17,25 @@ const FC = (props) => { ...@@ -17,21 +17,25 @@ const FC = (props) => {
const [confirmLoading, setConfirmLoading] = useState(false); const [confirmLoading, setConfirmLoading] = useState(false);
const [checkAllValue, setCheckAllValue] = useState(false); const [checkAllValue, setCheckAllValue] = useState(false);
const [configState, setConfigState] = useState(undefined); const [configState, setConfigState] = useState(undefined);
const [step, setStep] = useState(1);
const [scheduleParam, setScheduleParam] = useState({ const [scheduleParam, setScheduleParam] = useState({
action: undefined, action: undefined,
id: undefined, id: undefined,
tid: undefined tid: undefined
}); });
const [editSchedule, setEditSchedule] = useState(undefined); const [editSchedule, setEditSchedule] = useState(undefined);
const [notConfigSchedule, setNotConfigSchedule] = useState(false);
const [showScheduleCheckbox, setShowScheduleCheckbox] = useState(true);
const [ form ] = Form.useForm(); const [ form ] = Form.useForm();
const [ scheduleForm ] = Form.useForm(); const [ scheduleForm ] = Form.useForm();
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
if (action==='edit' && id) { if (action === 'add') {
setScheduleParam({ action, id: undefined, tid: undefined });
} else if (action==='edit' && id) {
getTask(); getTask();
getSchedules(id);
} }
} }
}, [visible, action]) }, [visible, action])
...@@ -126,10 +130,11 @@ const FC = (props) => { ...@@ -126,10 +130,11 @@ const FC = (props) => {
} }
}, },
callback: data => { callback: data => {
setStep(2);
if ((data?.datas||[]).length === 0) { if ((data?.datas||[]).length === 0) {
setNotConfigSchedule(true);
setScheduleParam({action: 'add', tid}); setScheduleParam({action: 'add', tid});
} else { } else {
setShowScheduleCheckbox(false);
setScheduleParam({action: 'edit', id: data?.datas[0].id}); setScheduleParam({action: 'edit', id: data?.datas[0].id});
} }
...@@ -143,62 +148,59 @@ const FC = (props) => { ...@@ -143,62 +148,59 @@ const FC = (props) => {
const onOk = async() => { const onOk = async() => {
try { try {
if (step === 1) { const row = await form.validateFields();
const row = await form.validateFields();
//深拷贝 if (!notConfigSchedule) {
let newTask = JSON.parse(JSON.stringify(taskSettings));
if (action === 'edit') {
newTask = {...newTask, ...currentTask};
}
newTask?.targetConfParameters?.forEach(item => {
if (item.name === 'schema') {
item.value = selectedSchemas.join(',');
} else {
item.value = row[item.name]||'';
}
});
setConfirmLoading(true);
dispatch({
type: 'datasource.saveTask',
payload: {
data: newTask
},
callback: data => {
setConfirmLoading(false);
onChange?.();
if (action === 'add') {
setStep(2);
setScheduleParam({action, tid: data});
} else {
getSchedules(data);
}
},
error: () => {
setConfirmLoading(false);
}
})
} else {
await scheduleForm.validateFields(); await scheduleForm.validateFields();
}
setConfirmLoading(true); //深拷贝
dispatch({ let newTask = JSON.parse(JSON.stringify(taskSettings));
type: 'datasource.saveAndStartSchedule',
payload: { if (action === 'edit') {
data: editSchedule newTask = {...newTask, ...currentTask};
}, }
callback: () => {
newTask?.targetConfParameters?.forEach(item => {
if (item.name === 'schema') {
item.value = selectedSchemas.join(',');
} else {
item.value = row[item.name]||'';
}
});
setConfirmLoading(true);
dispatch({
type: 'datasource.saveTask',
payload: {
data: newTask
},
callback: data => {
if (!notConfigSchedule) {
dispatch({
type: 'datasource.saveAndStartSchedule',
payload: {
data: {...editSchedule, targetConfId: data}
},
callback: () => {
setConfirmLoading(false);
reset();
onCancel?.(true);
},
error: () => {
setConfirmLoading(false);
}
})
} else {
setConfirmLoading(false); setConfirmLoading(false);
reset(); reset();
onCancel?.(); onCancel?.(true);
},
error: () => {
setConfirmLoading(false);
} }
}) },
} error: () => {
setConfirmLoading(false);
}
})
} catch (errInfo) { } catch (errInfo) {
console.log('Validate Failed:', errInfo); console.log('Validate Failed:', errInfo);
} }
...@@ -212,8 +214,12 @@ const FC = (props) => { ...@@ -212,8 +214,12 @@ const FC = (props) => {
setConfigState(undefined); setConfigState(undefined);
setKeyword(''); setKeyword('');
setCheckAllValue(false); setCheckAllValue(false);
setStep(1); setEditSchedule(undefined);
setNotConfigSchedule(false);
setShowScheduleCheckbox(true);
setScheduleParam({ action: undefined, id: undefined, tid: undefined });
form.resetFields(); form.resetFields();
scheduleForm.resetFields();
} }
const onSearchInputChange = (e) => { const onSearchInputChange = (e) => {
...@@ -242,6 +248,10 @@ const FC = (props) => { ...@@ -242,6 +248,10 @@ const FC = (props) => {
} }
} }
const onScheduleCheckChange = (e) => {
setNotConfigSchedule(e.target.checked);
}
const onScheduleChange = (data) => { const onScheduleChange = (data) => {
setEditSchedule(data); setEditSchedule(data);
} }
...@@ -271,87 +281,91 @@ const FC = (props) => { ...@@ -271,87 +281,91 @@ const FC = (props) => {
onOk={onOk} onOk={onOk}
confirmLoading={confirmLoading} confirmLoading={confirmLoading}
> >
{ <React.Fragment>
step === 1 && <React.Fragment> {
{ (action === 'add') && <div className='flex' style={{ justifyContent: 'end' }}>
(action === 'add') && <div className='flex' style={{ justifyContent: 'end' }}> <Config autoSelect onState={(state) => {
<Config autoSelect onState={(state) => { setConfigState(state);
setConfigState(state); }} />
}} /> </div>
</div> }
} <Spin spinning={loading}>
<Spin spinning={loading}> <Divider>{isNeo4jTarget?'neo4j数据库信息':'schema信息'}</Divider>
<Divider>{isNeo4jTarget?'neo4j数据库信息':'schema信息'}</Divider> <div className='d-flex mb-3' style={{ alignItems: 'center' }}>
<div className='d-flex mb-3' style={{ alignItems: 'center' }}> <span className='mr-3'>{isNeo4jTarget?'neo4j数据库搜索':'schema搜索'}:</span>
<span className='mr-3'>{isNeo4jTarget?'neo4j数据库搜索':'schema搜索'}:</span> <Input
<Input placeholder={`请输入${isNeo4jTarget?'neo4j数据库':'schema'}名称`}
placeholder={`请输入${isNeo4jTarget?'neo4j数据库':'schema'}名称`} allowClear
allowClear value={keyword}
value={keyword} onChange={onSearchInputChange}
onChange={onSearchInputChange} style={{ width: 230 }}
style={{ width: 230 }} />
/> <Switch
<Switch checkedChildren="全不选"
checkedChildren="全不选" unCheckedChildren="全选"
unCheckedChildren="全选" checked={ checkAllValue }
checked={ checkAllValue } onChange={ onCheckAll }
onChange={ onCheckAll } style={{ marginLeft: 'auto' }}
style={{ marginLeft: 'auto' }} />
/> </div>
</div> <div style={{ maxHeight: 300, overflow: 'auto' }}>
<div style={{ maxHeight: 300, overflow: 'auto' }}> <Row className='mb-3'>
<Row className='mb-3'>
{
(filterSchemas||[]).map((schema, index) => {
return (
<Col className='mt-1' key={index} md={8}>
<div className='d-flex'>
<Checkbox checked={ selectedSchemas.indexOf(schema)!==-1 } value={schema||''} onChange={onCheckChange} >
</Checkbox>
<Typography.Paragraph className='ml-1' title={schema||''} ellipsis>
{schema||''}
</Typography.Paragraph>
</div>
</Col>
);
})
}
</Row>
</div>
<Divider>过滤信息</Divider>
<Form {...formItemLayout} form={form}>
{ {
taskSettings && (taskSettings.targetConfParameters||[]).filter(item => item.name!=='schema').map((param, index) => { (filterSchemas||[]).map((schema, index) => {
return ( return (
<Form.Item <Col className='mt-1' key={index} md={8}>
label={param.cnName||''} <div className='d-flex'>
name={param.name||''} <Checkbox checked={ selectedSchemas.indexOf(schema)!==-1 } value={schema||''} onChange={onCheckChange} >
key={index} </Checkbox>
rules={[{ required: param.required, message: '必填项'}]} <Typography.Paragraph className='ml-1' title={schema||''} ellipsis>
> {schema||''}
{ </Typography.Paragraph>
( param.show ? <Input placeholder={param.explain||''} /> : <Input.Password placeholder={param.explain||''} visibilityToggle={false} /> ) </div>
} </Col>
</Form.Item> );
)
}) })
} }
</Form> </Row>
</Spin> </div>
</React.Fragment> <Divider>过滤信息</Divider>
} <Form {...formItemLayout} form={form}>
{ {
step === 2 && <React.Fragment> taskSettings && (taskSettings.targetConfParameters||[]).filter(item => item.name!=='schema').map((param, index) => {
<Divider>定时调度</Divider> return (
<ScheduleAction <Form.Item
action={scheduleParam.action} label={param.cnName||''}
id={scheduleParam.id} name={param.name||''}
form={scheduleForm} key={index}
tid={scheduleParam.tid} rules={[{ required: param.required, message: '必填项'}]}
onChange={onScheduleChange} >
/> {
</React.Fragment> ( param.show ? <Input placeholder={param.explain||''} /> : <Input.Password placeholder={param.explain||''} visibilityToggle={false} /> )
} }
</Form.Item>
)
})
}
</Form>
<Divider>{
<Space>
<span>定时调度</span>
{
showScheduleCheckbox && <Checkbox checked={notConfigSchedule} onChange={onScheduleCheckChange}>暂不设置</Checkbox>
}
</Space>
}</Divider>
{
!notConfigSchedule && <ScheduleAction
action={scheduleParam.action}
id={scheduleParam.id}
form={scheduleForm}
tid={scheduleParam.tid}
onChange={onScheduleChange}
/>
}
</Spin>
</React.Fragment>
</Modal> </Modal>
); );
} }
......
.metadata-harvester { .metadata-harvester {
height: calc(100vh - 124px); height: calc(100vh - 124px);
padding: 20px; padding: 5px 20px 20px;
background: #fff; background: #fff;
overflow: hidden; overflow: hidden;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment