2020-05-26 18:50:17 +08:00
|
|
|
|
import React, { Component } from "react";
|
|
|
|
|
|
import { getImageUrl } from "educoder";
|
2020-06-05 11:29:11 +08:00
|
|
|
|
import { Form, Input, Button, Radio, Icon, Spin } from "antd";
|
2020-05-26 18:50:17 +08:00
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
|
import "./index.css";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
2020-05-26 18:50:17 +08:00
|
|
|
|
import axios from "axios";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
const TextArea = Input.TextArea;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
class UserSubmitComponent extends Component {
|
|
|
|
|
|
constructor(props) {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
super(props);
|
2020-05-26 18:50:17 +08:00
|
|
|
|
this.state = {
|
2020-05-27 17:07:36 +08:00
|
|
|
|
submitType: "0",
|
2020-06-05 11:29:11 +08:00
|
|
|
|
filename: "",
|
|
|
|
|
|
isSpin: false
|
2020-05-26 18:50:17 +08:00
|
|
|
|
};
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-26 18:50:17 +08:00
|
|
|
|
changeSubmittype = (e) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.setState({
|
2020-05-26 18:50:17 +08:00
|
|
|
|
submitType: e.target.value,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
2020-06-04 18:28:26 +08:00
|
|
|
|
// 命名文件
|
|
|
|
|
|
changeFileName = (e) => {
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
filename: e.target.value,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
// 提交变更
|
2020-05-26 18:50:17 +08:00
|
|
|
|
subMitFrom = () => {
|
2020-06-04 18:47:55 +08:00
|
|
|
|
const { filepath, content,editor_type } = this.props;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
const { branch, projectsId } = this.props.match.params;
|
2020-06-04 18:28:26 +08:00
|
|
|
|
const { submitType, filename } = this.state;
|
2020-06-05 11:29:11 +08:00
|
|
|
|
this.setState({isSpin: true})
|
2020-06-04 18:47:55 +08:00
|
|
|
|
let path = editor_type === "upload" ? filepath : filepath.substr(1);
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
2020-05-26 18:50:17 +08:00
|
|
|
|
if (!err) {
|
2020-03-25 17:52:13 +08:00
|
|
|
|
const url = `/repositories/${projectsId}/create_file.json`;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
axios
|
|
|
|
|
|
.post(url, {
|
2020-06-04 18:28:26 +08:00
|
|
|
|
filepath: filename ? filename : path,
|
2020-05-26 18:50:17 +08:00
|
|
|
|
branch: branch,
|
|
|
|
|
|
new_branch: submitType === "1" ? values.branchname : undefined,
|
|
|
|
|
|
content,
|
|
|
|
|
|
message: values.desc,
|
|
|
|
|
|
})
|
|
|
|
|
|
.then((result) => {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
this.setState({isSpin: false})
|
2020-06-05 12:02:26 +08:00
|
|
|
|
if (result.data && result.data.name) {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
let url = values.branchname
|
|
|
|
|
|
? `/projects/${projectsId}/coders?branch=${values.branchname}`
|
|
|
|
|
|
: `/projects/${projectsId}/coders`;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
this.props.history.push(url);
|
2020-06-05 14:46:26 +08:00
|
|
|
|
this.props.showNotification("文件新建成功!");
|
2020-05-26 18:50:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
this.setState({isSpin: false})
|
2020-05-26 18:50:17 +08:00
|
|
|
|
console.log(error);
|
|
|
|
|
|
});
|
2020-06-05 11:29:11 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
this.setState({isSpin: false})
|
2020-05-26 18:50:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 确认修改文件
|
2020-05-27 17:07:36 +08:00
|
|
|
|
UpdateFile = () => {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
this.setState({isSpin: true})
|
2020-05-27 17:07:36 +08:00
|
|
|
|
const { branch, detail, content, filepath } = this.props;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
const { projectsId } = this.props.match.params;
|
|
|
|
|
|
const { submitType } = this.state;
|
2020-05-27 17:07:36 +08:00
|
|
|
|
const url = `/repositories/${projectsId}/update_file.json`;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
|
|
|
|
|
if (!err) {
|
2020-05-27 17:07:36 +08:00
|
|
|
|
axios
|
|
|
|
|
|
.put(url, {
|
|
|
|
|
|
filepath: detail.path,
|
|
|
|
|
|
branch: branch,
|
|
|
|
|
|
new_branch: submitType === "1" ? values.branchname : undefined,
|
|
|
|
|
|
content: content,
|
|
|
|
|
|
sha: detail.sha,
|
|
|
|
|
|
message: values.desc,
|
|
|
|
|
|
})
|
|
|
|
|
|
.then((result) => {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
this.setState({isSpin: false})
|
2020-06-05 12:02:26 +08:00
|
|
|
|
if (result.data && result.data.status === 1) {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
let url = values.branchname
|
2020-05-27 17:07:36 +08:00
|
|
|
|
? `/projects/${projectsId}/coders?branch=${values.branchname}`
|
|
|
|
|
|
: `/projects/${projectsId}/coders`;
|
2020-06-05 11:29:11 +08:00
|
|
|
|
|
2020-05-26 18:50:17 +08:00
|
|
|
|
this.props.history.push(url);
|
2020-05-27 17:07:36 +08:00
|
|
|
|
this.props.showNotification("修改成功!");
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
this.setState({isSpin: false})
|
2020-05-27 17:07:36 +08:00
|
|
|
|
console.log(error);
|
|
|
|
|
|
});
|
2020-06-05 11:29:11 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
this.setState({isSpin: false})
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
2020-05-27 17:07:36 +08:00
|
|
|
|
});
|
|
|
|
|
|
};
|
2020-05-26 18:50:17 +08:00
|
|
|
|
|
|
|
|
|
|
render() {
|
2020-06-05 11:29:11 +08:00
|
|
|
|
const { submitType,filename, isSpin } = this.state;
|
2020-03-16 14:12:11 +08:00
|
|
|
|
const { getFieldDecorator } = this.props.form;
|
|
|
|
|
|
|
2020-05-26 18:50:17 +08:00
|
|
|
|
const { branch, projectsId } = this.props.match.params;
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
2020-05-26 18:50:17 +08:00
|
|
|
|
const { current_user, filepath, projectDetail } = this.props;
|
2020-05-27 17:07:36 +08:00
|
|
|
|
const { editor_type } = this.props;
|
2020-06-04 18:47:55 +08:00
|
|
|
|
console.log("88888", filepath)
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
2020-05-26 18:50:17 +08:00
|
|
|
|
const changeSubmitBranch = () => {
|
|
|
|
|
|
if (submitType === "1") {
|
|
|
|
|
|
return (
|
2020-05-20 18:11:32 +08:00
|
|
|
|
<div className="mt15">
|
2020-05-26 18:50:17 +08:00
|
|
|
|
<Form.Item style={{ paddingLeft: "24px" }}>
|
|
|
|
|
|
{getFieldDecorator("branchname", {
|
|
|
|
|
|
rules: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入分支名称",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2020-04-23 12:06:31 +08:00
|
|
|
|
})(
|
2020-05-26 18:50:17 +08:00
|
|
|
|
<Input
|
|
|
|
|
|
placeholder={`请输入分支名称`}
|
|
|
|
|
|
style={{ width: "220px" }}
|
|
|
|
|
|
/>
|
2020-04-23 12:06:31 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</div>
|
2020-05-26 18:50:17 +08:00
|
|
|
|
);
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
2020-05-26 18:50:17 +08:00
|
|
|
|
};
|
|
|
|
|
|
return (
|
2020-05-20 18:11:32 +08:00
|
|
|
|
<div>
|
2020-06-01 18:28:42 +08:00
|
|
|
|
<span className="df mt30" style={{ alignItems: "center" }}>
|
2020-05-26 18:50:17 +08:00
|
|
|
|
<Link
|
|
|
|
|
|
to={`/users/${current_user && current_user.login}/projects`}
|
|
|
|
|
|
className="show-user-link"
|
|
|
|
|
|
>
|
|
|
|
|
|
<img
|
|
|
|
|
|
src={getImageUrl(
|
|
|
|
|
|
`images/${current_user && current_user.image_url}`
|
|
|
|
|
|
)}
|
|
|
|
|
|
alt=""
|
|
|
|
|
|
className="screwImg"
|
|
|
|
|
|
/>
|
2020-05-27 17:07:36 +08:00
|
|
|
|
<span className="color-grey-3 ver-middle">
|
2020-05-26 18:50:17 +08:00
|
|
|
|
{current_user && current_user.username}:
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
|
|
|
|
<span className="color-grey-8">提交变更</span>
|
2020-05-20 18:11:32 +08:00
|
|
|
|
</span>
|
2020-06-05 11:29:11 +08:00
|
|
|
|
<Spin spinning={isSpin}>
|
2020-05-20 18:11:32 +08:00
|
|
|
|
<div className="userScrew">
|
|
|
|
|
|
<div className="screwPanel">
|
|
|
|
|
|
<Form>
|
2020-06-04 18:28:26 +08:00
|
|
|
|
<Form.Item style={{display: editor_type === "upload" ? "block" : "none"}}>
|
2020-05-26 18:50:17 +08:00
|
|
|
|
{getFieldDecorator("path", {
|
2020-05-20 18:11:32 +08:00
|
|
|
|
rules: [],
|
|
|
|
|
|
})(
|
2020-06-04 18:28:26 +08:00
|
|
|
|
// <Input
|
|
|
|
|
|
// placeholder={`/${
|
|
|
|
|
|
// projectDetail && projectDetail.identifier
|
|
|
|
|
|
// }${filepath}`}
|
|
|
|
|
|
// readOnly
|
|
|
|
|
|
// />
|
|
|
|
|
|
<div className="setInputAddon">
|
2020-05-26 18:50:17 +08:00
|
|
|
|
<Input
|
2020-06-04 18:28:26 +08:00
|
|
|
|
addonBefore={`/${
|
2020-05-26 18:50:17 +08:00
|
|
|
|
projectDetail && projectDetail.identifier
|
2020-06-04 18:28:26 +08:00
|
|
|
|
}/`}
|
|
|
|
|
|
value={filename ? filename: filepath}
|
|
|
|
|
|
onChange={this.changeFileName}
|
2020-06-04 18:47:55 +08:00
|
|
|
|
placeholder="文件路径..."
|
2020-05-26 18:50:17 +08:00
|
|
|
|
/>
|
2020-06-04 18:28:26 +08:00
|
|
|
|
</div>
|
2020-05-20 18:11:32 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item>
|
2020-05-26 18:50:17 +08:00
|
|
|
|
{getFieldDecorator("desc", {
|
|
|
|
|
|
rules: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
2020-05-27 17:07:36 +08:00
|
|
|
|
message: "请添加描述信息",
|
2020-05-26 18:50:17 +08:00
|
|
|
|
},
|
|
|
|
|
|
],
|
2020-05-20 18:11:32 +08:00
|
|
|
|
})(
|
2020-05-26 18:50:17 +08:00
|
|
|
|
<TextArea
|
2020-05-27 17:07:36 +08:00
|
|
|
|
placeholder={`必填,描述主要修改类型和内容`}
|
2020-05-26 18:50:17 +08:00
|
|
|
|
authSize={{ minRows: 3, maxRows: 5 }}
|
|
|
|
|
|
/>
|
2020-05-20 18:11:32 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
<Radio.Group value={submitType} onChange={this.changeSubmittype}>
|
2020-05-26 18:50:17 +08:00
|
|
|
|
<Radio value="0" className="mb10">
|
|
|
|
|
|
<i className="iconfont icon-banbenku font-16 mr5"></i>
|
|
|
|
|
|
直接提交至<span className="color-orange">{branch}</span>分支
|
|
|
|
|
|
</Radio>
|
|
|
|
|
|
<Radio value="1">
|
|
|
|
|
|
<Icon type="pull-request" className="mr5" />
|
|
|
|
|
|
为此提交创建一个<span className="font-bd">新的分支</span>
|
|
|
|
|
|
并发起合并请求
|
|
|
|
|
|
</Radio>
|
2020-05-20 18:11:32 +08:00
|
|
|
|
</Radio.Group>
|
|
|
|
|
|
{changeSubmitBranch()}
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
</div>
|
2020-03-16 14:12:11 +08:00
|
|
|
|
</div>
|
2020-06-01 18:28:42 +08:00
|
|
|
|
<div className="mt20 text-center">
|
2020-05-27 17:07:36 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
type="primary"
|
2020-06-04 18:28:26 +08:00
|
|
|
|
onClick={editor_type === "edit" ? this.UpdateFile : this.subMitFrom}
|
2020-05-27 17:07:36 +08:00
|
|
|
|
className="mr30"
|
|
|
|
|
|
>
|
2020-05-26 18:50:17 +08:00
|
|
|
|
提交变更
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="primary grey"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
this.props.history.push(`/projects/${projectsId}/coders`);
|
|
|
|
|
|
}}
|
|
|
|
|
|
className="mr20"
|
|
|
|
|
|
>
|
|
|
|
|
|
取消
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
2020-06-05 11:29:11 +08:00
|
|
|
|
</Spin>
|
|
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
</div>
|
2020-05-26 18:50:17 +08:00
|
|
|
|
);
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-26 18:50:17 +08:00
|
|
|
|
const WrappedUserSubmitForm = Form.create({ name: "UserSubmitForm" })(
|
|
|
|
|
|
UserSubmitComponent
|
|
|
|
|
|
);
|
|
|
|
|
|
export default WrappedUserSubmitForm;
|