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: "",
|
2020-06-24 14:30:02 +08:00
|
|
|
|
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-24 14:30:02 +08:00
|
|
|
|
// 命名文件
|
|
|
|
|
|
changeFileName = (e) => {
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
filename: e.target.value,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2020-06-04 18:28:26 +08:00
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
// 提交变更
|
2020-05-26 18:50:17 +08:00
|
|
|
|
subMitFrom = () => {
|
2020-06-24 14:30:02 +08:00
|
|
|
|
const { filepath, content, editor_type } = this.props;
|
2020-08-13 11:42:44 +08:00
|
|
|
|
const { branch, projectsId , owner } = this.props.match.params;
|
2020-06-04 18:28:26 +08:00
|
|
|
|
const { submitType, filename } = this.state;
|
2020-06-24 14:30:02 +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-08-13 11:42:44 +08:00
|
|
|
|
const url = `/${owner}/${projectsId}/create_file.json`;
|
2020-07-27 18:45:18 +08:00
|
|
|
|
axios.post(url, {
|
|
|
|
|
|
filepath: filename ? filename : path,
|
|
|
|
|
|
branch: branch,
|
|
|
|
|
|
new_branch: submitType === "1" ? values.branchname : undefined,
|
|
|
|
|
|
content,
|
|
|
|
|
|
message: values.desc,
|
|
|
|
|
|
})
|
|
|
|
|
|
.then((result) => {
|
|
|
|
|
|
this.setState({ isSpin: false });
|
|
|
|
|
|
if (result.data && result.data.name) {
|
|
|
|
|
|
this.props.showNotification("文件新建成功!");
|
|
|
|
|
|
if(submitType === "1"){
|
|
|
|
|
|
const { getTopCount } = this.props;
|
|
|
|
|
|
getTopCount && getTopCount(values.branchname);
|
2020-05-26 18:50:17 +08:00
|
|
|
|
}
|
2021-03-18 17:28:53 +08:00
|
|
|
|
let url = `/projects/${owner}/${projectsId}${values.branchname ? `/tree/${values.branchname}`: (branch ? `/tree/${branch}` : "")}`;
|
2020-07-27 18:45:18 +08:00
|
|
|
|
this.props.history.push(url);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
2020-12-21 17:59:40 +08:00
|
|
|
|
this.setState({ isSpin : false });
|
2020-07-27 18:45:18 +08:00
|
|
|
|
console.log(error);
|
|
|
|
|
|
});
|
2020-06-24 14:30:02 +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-24 14:30:02 +08:00
|
|
|
|
this.setState({ isSpin: true });
|
2020-11-27 11:59:21 +08:00
|
|
|
|
const { branch, detail, content , currentBranch } = this.props;
|
2020-08-13 11:42:44 +08:00
|
|
|
|
const { projectsId , owner } = this.props.match.params;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
const { submitType } = this.state;
|
2020-08-13 11:42:44 +08:00
|
|
|
|
const url = `/${owner}/${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,
|
2020-11-27 11:59:21 +08:00
|
|
|
|
branch: submitType === "1" ? undefined : (currentBranch || branch),
|
2020-05-27 17:07:36 +08:00
|
|
|
|
new_branch: submitType === "1" ? values.branchname : undefined,
|
|
|
|
|
|
content: content,
|
|
|
|
|
|
sha: detail.sha,
|
|
|
|
|
|
message: values.desc,
|
|
|
|
|
|
})
|
|
|
|
|
|
.then((result) => {
|
2020-06-24 14:30:02 +08:00
|
|
|
|
this.setState({ isSpin: false });
|
2020-06-05 12:02:26 +08:00
|
|
|
|
if (result.data && result.data.status === 1) {
|
2021-03-18 17:28:53 +08:00
|
|
|
|
let url = `/projects/${owner}/${projectsId}${(values.branchname ? `/tree/${values.branchname}` : ((currentBranch || branch) ? `/tree/${currentBranch || branch}`:""))}`;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
this.props.history.push(url);
|
2020-11-27 11:59:21 +08:00
|
|
|
|
this.props.showNotification("文件修改成功!");
|
2020-05-27 17:07:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
2020-06-24 14:30:02 +08:00
|
|
|
|
this.setState({ isSpin: false });
|
2020-05-27 17:07:36 +08:00
|
|
|
|
console.log(error);
|
|
|
|
|
|
});
|
2020-06-24 14:30:02 +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-24 14:30:02 +08:00
|
|
|
|
const { submitType, filename, isSpin } = this.state;
|
2020-03-16 14:12:11 +08:00
|
|
|
|
const { getFieldDecorator } = this.props.form;
|
|
|
|
|
|
|
2020-08-13 11:42:44 +08:00
|
|
|
|
const { branch, projectsId , owner } = this.props.match.params;
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
2020-10-16 10:35:51 +08:00
|
|
|
|
const { current_user, filepath, projectDetail , currentBranch } = this.props;
|
2020-05-27 17:07:36 +08:00
|
|
|
|
const { editor_type } = this.props;
|
2020-05-26 18:50:17 +08:00
|
|
|
|
return (
|
2020-05-20 18:11:32 +08:00
|
|
|
|
<div>
|
2021-03-18 17:28:53 +08:00
|
|
|
|
<span className="df" style={{ alignItems: "center" }}>
|
2020-08-18 16:56:52 +08:00
|
|
|
|
<Link to={`/users/${current_user && current_user.login}`} className="show-user-link" >
|
2020-05-26 18:50:17 +08:00
|
|
|
|
<img
|
2021-04-21 16:55:10 +08:00
|
|
|
|
src={getImageUrl(`/${current_user && current_user.image_url}`)}
|
2020-05-26 18:50:17 +08:00
|
|
|
|
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-06-24 14:30:02 +08:00
|
|
|
|
<div className="userScrew">
|
|
|
|
|
|
<div className="screwPanel">
|
|
|
|
|
|
<Form>
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
|
style={{
|
|
|
|
|
|
display: editor_type === "upload" ? "block" : "none",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{getFieldDecorator("path", {
|
|
|
|
|
|
rules: [],
|
|
|
|
|
|
})(
|
|
|
|
|
|
<div className="setInputAddon">
|
|
|
|
|
|
<Input
|
2020-08-18 16:56:52 +08:00
|
|
|
|
addonBefore={`/${ projectDetail && projectDetail.identifier }/`}
|
|
|
|
|
|
value={filename || filepath}
|
2020-06-24 14:30:02 +08:00
|
|
|
|
onChange={this.changeFileName}
|
|
|
|
|
|
placeholder="文件路径..."
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item>
|
|
|
|
|
|
{getFieldDecorator("desc", {
|
|
|
|
|
|
rules: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请添加描述信息",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
})(
|
|
|
|
|
|
<TextArea
|
|
|
|
|
|
placeholder={`必填,描述主要修改类型和内容`}
|
|
|
|
|
|
authSize={{ minRows: 3, maxRows: 5 }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
<Radio.Group
|
|
|
|
|
|
value={submitType}
|
|
|
|
|
|
onChange={this.changeSubmittype}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Radio value="0" className="mb10">
|
|
|
|
|
|
<i className="iconfont icon-banbenku font-16 mr5"></i>
|
2020-10-16 10:35:51 +08:00
|
|
|
|
直接提交至<span className="color-orange">{currentBranch || branch}</span>分支
|
2020-06-24 14:30:02 +08:00
|
|
|
|
</Radio>
|
|
|
|
|
|
<Radio value="1">
|
|
|
|
|
|
<Icon type="pull-request" className="mr5" />
|
2020-12-21 17:59:40 +08:00
|
|
|
|
为此提交创建一个<span className="font-bd">新的分支</span>并发起合并请求
|
2020-06-24 14:30:02 +08:00
|
|
|
|
</Radio>
|
|
|
|
|
|
</Radio.Group>
|
2020-07-06 14:21:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
submitType === "1" ?
|
|
|
|
|
|
<div className="mt15">
|
|
|
|
|
|
<Form.Item style={{ paddingLeft: "24px" }}>
|
|
|
|
|
|
{getFieldDecorator("branchname", {
|
|
|
|
|
|
rules: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入分支名称",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
})(
|
|
|
|
|
|
<Input
|
|
|
|
|
|
placeholder={`请输入分支名称`}
|
|
|
|
|
|
style={{ width: "220px" }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</div>:""
|
|
|
|
|
|
}
|
2020-06-24 14:30:02 +08:00
|
|
|
|
</Form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt20">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
onClick={
|
|
|
|
|
|
editor_type === "update" ? this.UpdateFile : this.subMitFrom
|
|
|
|
|
|
}
|
|
|
|
|
|
className="mr30"
|
|
|
|
|
|
>
|
|
|
|
|
|
提交变更
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="primary grey"
|
|
|
|
|
|
onClick={() => {
|
2020-08-19 18:34:52 +08:00
|
|
|
|
this.props.history.push(`/projects/${owner}/${projectsId}`);
|
2020-06-24 14:30:02 +08:00
|
|
|
|
}}
|
|
|
|
|
|
className="mr20"
|
|
|
|
|
|
>
|
|
|
|
|
|
取消
|
|
|
|
|
|
</Button>
|
2020-05-20 18:11:32 +08:00
|
|
|
|
</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;
|