|
@@ -15,7 +15,7 @@ import {
|
|
|
} from '@ant-design/icons';
|
|
|
import { DagToData } from './utils';
|
|
|
// import MediateDataTable from './MediateDataTable';
|
|
|
-import { uploadFile } from './request';
|
|
|
+import { uploadFile, postRequirements, getRequirementsStatus } from './request';
|
|
|
|
|
|
const Item = Toolbar.Item; // eslint-disable-line
|
|
|
const Group = Toolbar.Group; // eslint-disable-line
|
|
@@ -25,7 +25,8 @@ export default class ToolBar extends React.Component<any, any> {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
modalVisible: false,
|
|
|
- packageData: ''
|
|
|
+ packageData: '',
|
|
|
+ status: ''
|
|
|
};
|
|
|
}
|
|
|
|
|
@@ -33,18 +34,33 @@ export default class ToolBar extends React.Component<any, any> {
|
|
|
this.setState({ modalVisible: true });
|
|
|
};
|
|
|
|
|
|
- submitEdit = () => {
|
|
|
- const node = this.props.graph.getSelectedCells()[0];
|
|
|
- node.data.packageData = this.state.packageData;
|
|
|
- this.setState({ modalVisible: false });
|
|
|
+ submitEdit = async () => {
|
|
|
+ const { data } = await postRequirements({
|
|
|
+ requirements: this.state.packageData,
|
|
|
+ dag_uuid: this.props.dagId
|
|
|
+ });
|
|
|
+ if (data.code === 200) {
|
|
|
+ this.props.saveGraph(
|
|
|
+ DagToData(this.props.graph, this.props.dagId, this.state.packageData)
|
|
|
+ );
|
|
|
+ this.setState({ modalVisible: false });
|
|
|
+ message.success('添加成功');
|
|
|
+ } else {
|
|
|
+ message.success(data.msg);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
onClick = (name: string) => {
|
|
|
- // const zoomNumber = this.props.graph.zoom()
|
|
|
switch (name) {
|
|
|
case 'save':
|
|
|
- this.props.saveGraph(DagToData(this.props.graph, this.props.dagId));
|
|
|
- message.success('保存成功!');
|
|
|
+ const text = this.props.context.current;
|
|
|
+ text.ready.then(() => {
|
|
|
+ const dagJson: any = text.model.toJSON();
|
|
|
+ this.props.saveGraph(
|
|
|
+ DagToData(this.props.graph, this.props.dagId, dagJson.requirements)
|
|
|
+ );
|
|
|
+ message.success('保存成功!');
|
|
|
+ });
|
|
|
break;
|
|
|
case 'zoomOut':
|
|
|
this.props.graph.zoom(-0.1, {
|
|
@@ -60,26 +76,46 @@ export default class ToolBar extends React.Component<any, any> {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- async uploadDagFile() {
|
|
|
+ uploadDagFile() {
|
|
|
const text = this.props.context.current;
|
|
|
const filename = text.path.split('/').pop();
|
|
|
- const content = JSON.stringify(
|
|
|
- DagToData(this.props.graph, this.props.dagId)
|
|
|
- );
|
|
|
- let blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
|
|
|
- let file = new File([blob], filename, {
|
|
|
- lastModified: Date.now()
|
|
|
+ text.ready.then(async () => {
|
|
|
+ const dagJson: any = text.model.toJSON();
|
|
|
+ const content = JSON.stringify(
|
|
|
+ DagToData(this.props.graph, this.props.dagId, dagJson.requirements)
|
|
|
+ );
|
|
|
+ let blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
|
|
|
+ let file = new File([blob], filename, {
|
|
|
+ lastModified: Date.now()
|
|
|
+ });
|
|
|
+ const dagfile = new FormData();
|
|
|
+ dagfile.append('file', file);
|
|
|
+ dagfile.append('project_id', 'test');
|
|
|
+ dagfile.append('file_type', 'dag');
|
|
|
+ const { data } = await uploadFile(dagfile);
|
|
|
+ if (data.code === 200) {
|
|
|
+ message.success('上传成功');
|
|
|
+ } else {
|
|
|
+ message.error(data.msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ openRequirements() {
|
|
|
+ const text = this.props.context.current;
|
|
|
+ text.ready.then(async () => {
|
|
|
+ const dagJson: any = text.model.toJSON();
|
|
|
+ const { data } = await getRequirementsStatus(this.props.dagId);
|
|
|
+ if (data.code === 200) {
|
|
|
+ this.setState({
|
|
|
+ modalVisible: true,
|
|
|
+ packageData: dagJson.requirements,
|
|
|
+ status: data.data
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ message.success(data.msg);
|
|
|
+ }
|
|
|
});
|
|
|
- const dagfile = new FormData();
|
|
|
- dagfile.append('file', file);
|
|
|
- dagfile.append('project_id', 'test');
|
|
|
- dagfile.append('file_type', 'dag');
|
|
|
- const { data } = await uploadFile(dagfile);
|
|
|
- if (data.code === 200) {
|
|
|
- message.success('上传成功');
|
|
|
- } else {
|
|
|
- message.error(data.msg);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
DropDown(toolType: string) {
|
|
@@ -113,19 +149,7 @@ export default class ToolBar extends React.Component<any, any> {
|
|
|
<MenuItem
|
|
|
name="packageEdit"
|
|
|
onClick={() => {
|
|
|
- const selected = this.props.graph.getSelectedCells();
|
|
|
- if (
|
|
|
- selected.length === 1 &&
|
|
|
- selected[0].data &&
|
|
|
- selected[0].data.type === 'script'
|
|
|
- ) {
|
|
|
- this.setState({
|
|
|
- modalVisible: true,
|
|
|
- packageData: selected[0].data.packageData
|
|
|
- });
|
|
|
- } else {
|
|
|
- message.warning('请选择单个脚本节点');
|
|
|
- }
|
|
|
+ this.openRequirements();
|
|
|
}}
|
|
|
>
|
|
|
依赖编辑
|
|
@@ -188,6 +212,8 @@ export default class ToolBar extends React.Component<any, any> {
|
|
|
}}
|
|
|
>
|
|
|
<Form
|
|
|
+ labelCol={{ span: 4 }}
|
|
|
+ wrapperCol={{ span: 18 }}
|
|
|
initialValues={{
|
|
|
packageData: this.state.packageData
|
|
|
}}
|
|
@@ -201,6 +227,9 @@ export default class ToolBar extends React.Component<any, any> {
|
|
|
}}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
+ <Form.Item label="状态" name="status">
|
|
|
+ <span>{this.state.status}</span>
|
|
|
+ </Form.Item>
|
|
|
</Form>
|
|
|
</Modal>
|
|
|
</div>
|