forgeplus-react/src/forge/Settings/Setting.js

237 lines
6.6 KiB
JavaScript
Raw Normal View History

2020-05-22 17:00:18 +08:00
import React, { Component } from "react";
import { Form, Input, Checkbox, Select } from "antd";
2020-03-16 14:12:11 +08:00
2020-05-22 17:00:18 +08:00
import axios from "axios";
2020-05-22 17:52:41 +08:00
import "./setting.css";
2020-03-16 14:12:11 +08:00
const { TextArea } = Input;
const { Option } = Select;
2020-05-22 17:00:18 +08:00
class Setting extends Component {
constructor(props) {
2020-03-16 14:12:11 +08:00
super(props);
2020-05-22 17:00:18 +08:00
this.state = {
CategoryList: undefined,
LanguageList: undefined,
private_check: undefined,
};
2020-03-16 14:12:11 +08:00
}
2020-05-22 17:00:18 +08:00
componentDidMount = () => {
2020-03-16 14:12:11 +08:00
this.getCategory();
this.getLanguage();
this.getInfo();
2020-05-22 17:00:18 +08:00
};
getLanguage = () => {
const url = `/project_languages.json`;
axios
.get(url)
.then((result) => {
if (result) {
let LanguageList = this.setOptionsList(result.data.project_languages);
this.setState({
LanguageList,
});
}
})
.catch((error) => {});
};
2020-03-16 14:12:11 +08:00
2020-05-22 17:00:18 +08:00
getInfo = () => {
2020-03-16 14:12:11 +08:00
const { projectsId } = this.props.match.params;
2020-03-20 20:50:30 +08:00
const url = `/repositories/${projectsId}/edit.json`;
2020-05-22 17:00:18 +08:00
axios
.get(url)
.then((result) => {
if (result) {
this.props.form.setFieldsValue({
...result.data,
});
this.setState({
private_check: result.data.private,
});
}
})
.catch((error) => {
console.log(error);
});
};
2020-03-16 14:12:11 +08:00
2020-05-22 17:00:18 +08:00
getCategory = () => {
const url = `/project_categories.json`;
axios
.get(url)
.then((result) => {
if (result) {
let CategoryList = this.setOptionsList(
result.data.project_categories
);
this.setState({
CategoryList,
});
}
})
.catch((error) => {});
};
2020-03-16 14:12:11 +08:00
2020-05-22 17:00:18 +08:00
setOptionsList = (data) => {
2020-03-16 14:12:11 +08:00
let list = undefined;
2020-05-22 17:00:18 +08:00
if (data && data.length > 0) {
list = data.map((item, key) => {
return (
<Option key={item.id} value={item.id}>
{item.name}
</Option>
);
});
2020-03-16 14:12:11 +08:00
}
return list;
2020-05-22 17:00:18 +08:00
};
2020-03-16 14:12:11 +08:00
// 更新仓库设置
2020-05-22 17:00:18 +08:00
resetSetting = () => {
this.props.form.validateFields((err, values) => {
if (!err) {
2020-03-16 14:12:11 +08:00
const { project_id } = this.props;
const { private_check } = this.state;
const url = `/projects/${project_id}.json`;
2020-05-22 17:00:18 +08:00
axios
.put(url, {
name: values.project_name,
description: values.project_description,
private: private_check,
...values,
})
.then((result) => {
if (result) {
this.props.showNotification(`仓库信息修改成功!`);
const { getDetail } = this.props;
getDetail && getDetail();
}
})
.catch((error) => {
console.log(error);
});
2020-03-16 14:12:11 +08:00
}
2020-05-22 17:00:18 +08:00
});
};
2020-03-16 14:12:11 +08:00
// 删除本仓库
2020-05-22 17:00:18 +08:00
deleteProject = () => {
2020-03-16 14:12:11 +08:00
this.props.confirm({
2020-05-22 17:00:18 +08:00
content: "删除后无法恢复,是否确认删除本仓库?",
onOk: () => {
2020-03-16 14:12:11 +08:00
const { project_id } = this.props;
const url = `/projects/${project_id}.json`;
2020-05-22 17:00:18 +08:00
axios
.delete(url)
.then((result) => {
this.props.showNotification("仓库删除成功!");
this.props.history.push("/projects");
})
.catch((error) => {
console.log(error);
});
},
});
};
changePrivate = (e) => {
2020-03-16 14:12:11 +08:00
console.log(e);
this.setState({
2020-05-22 17:00:18 +08:00
private_check: e.target.checked,
});
};
2020-03-16 14:12:11 +08:00
2020-05-22 17:00:18 +08:00
render() {
2020-03-16 14:12:11 +08:00
const { getFieldDecorator } = this.props.form;
2020-05-22 17:00:18 +08:00
const { CategoryList, LanguageList, private_check } = this.state;
return (
2020-03-16 14:12:11 +08:00
<div>
2020-05-22 17:52:41 +08:00
<div className="">
<div className="flex-a-center baseForm bbr">
<span className="font-18 fwb text-black">基本设置</span>
</div>
2020-03-16 14:12:11 +08:00
<Form className="baseForm">
2020-05-22 17:00:18 +08:00
<Form.Item label="项目名称">
{getFieldDecorator("project_name", {
rules: [
{
required: true,
message: "请输入项目名称",
},
],
})(<Input placeholder="请输入项目名称" />)}
</Form.Item>
<div className="df" style={{ alignItems: "center" }}>
2020-03-16 14:12:11 +08:00
<span className="mr20 mb15 font-16">可见性</span>
2020-05-22 17:00:18 +08:00
<Form.Item label="">
{getFieldDecorator("private", {
2020-03-16 14:12:11 +08:00
rules: [],
})(
2020-05-22 17:00:18 +08:00
<Checkbox
checked={private_check}
onChange={this.changePrivate}
>
将仓库设为私有
</Checkbox>
2020-03-16 14:12:11 +08:00
)}
2020-05-22 17:00:18 +08:00
</Form.Item>
2020-03-16 14:12:11 +08:00
</div>
2020-05-22 17:00:18 +08:00
<Form.Item label="仓库描述">
{getFieldDecorator("project_description", {
rules: [],
2020-03-16 14:12:11 +08:00
})(
2020-05-22 17:00:18 +08:00
<TextArea
placeholder="请输入仓库描述"
style={{ height: "80px" }}
/>
2020-03-16 14:12:11 +08:00
)}
</Form.Item>
2020-05-22 17:00:18 +08:00
<Form.Item label="项目类别">
{getFieldDecorator("project_category_id", {
rules: [
{
required: true,
message: "请选择大类别",
},
],
})(<Select>{CategoryList}</Select>)}
</Form.Item>
<Form.Item label="项目语言">
{getFieldDecorator("project_language_id", {
rules: [
{
required: true,
message: "请选择项目语言",
},
],
})(<Select>{LanguageList}</Select>)}
2020-03-16 14:12:11 +08:00
</Form.Item>
<p className="clearfix">
2020-05-22 17:00:18 +08:00
<a className="submitBtn" onClick={this.resetSetting}>
更新仓库设置
</a>
2020-03-16 14:12:11 +08:00
</p>
</Form>
</div>
2020-05-22 17:52:41 +08:00
<div className="dangerousBox mb20">
2020-03-16 14:12:11 +08:00
<div className="dangerousTitle">危险操作区</div>
<div className="flex-a-center padding15-10">
<div>
<p className="font-bd font-16">删除本仓库</p>
2020-05-22 17:00:18 +08:00
<p className="mt10">
删除仓库是永久性的,
无法撤消且删除后与仓库关联的项目/任务/合并请求/版本发布等均会被删除
</p>
2020-03-16 14:12:11 +08:00
</div>
2020-05-22 17:00:18 +08:00
<a onClick={this.deleteProject} className="red_deleteBtn">
删除本仓库
</a>
2020-03-16 14:12:11 +08:00
</div>
</div>
</div>
2020-05-22 17:00:18 +08:00
);
2020-03-16 14:12:11 +08:00
}
}
2020-05-22 17:00:18 +08:00
const WrappedSettingIndexForm = Form.create({ name: "settingForm" })(Setting);
export default WrappedSettingIndexForm;