forgeplus-react/src/forge/DevOps/About.jsx

190 lines
6.5 KiB
React
Raw Normal View History

2020-07-31 20:15:28 +08:00
import React, { forwardRef, useCallback, useState , useEffect } from "react";
import activate from "../Images/activate.png";
2020-10-15 19:44:17 +08:00
import { Blueback , AlignCenter } from "../Component/layout";
2020-10-16 11:39:12 +08:00
import PasswordAuthority from "../Component/PasswordAuthority";
2020-07-31 20:15:28 +08:00
import styled from "styled-components";
2020-10-15 19:44:17 +08:00
import { Form, Input , Spin , Modal } from "antd";
2020-07-31 20:15:28 +08:00
import axios from "axios";
const P = styled.p`
{
2020-11-23 15:23:19 +08:00
width: 230px;
2020-07-31 20:15:28 +08:00
line-height: 30px;
font-size: 16px;
color: #333;
text-align: center;
margin-top: 30px;
margin-bottom: 30px !important;
}
`;
function About(props, ref) {
2020-08-26 16:09:27 +08:00
const { form: { getFieldDecorator, validateFields , setFieldsValue } } = props;
2020-08-28 11:58:32 +08:00
const [isSpining, setIsSpining] = useState(true);
2020-10-15 19:44:17 +08:00
const [ authorityValBox , setAuthorityValBox ] = useState(false);
const [ authorityVal , setAuthorityVal ] = useState(undefined);
const [ authorityValFlag , setAuthorityValFlag ] = useState(false);
2020-08-26 16:09:27 +08:00
//0: 标识未开启devops
//1: 标识用户已填写了云服务器相关信息,但并未开启认证
const [step, setStep] = useState(undefined);
// step大于1时为true不能再修改服务器信息
const owner = props.match.params.owner;
const projectsId = props.match.params.projectsId;
2020-08-28 11:58:32 +08:00
2020-08-27 15:15:03 +08:00
const AuthorLogin = props.author && props.author.login;
const CurrentLogin = props.current_user && props.current_user.login;
2020-08-26 16:09:27 +08:00
useEffect(()=>{
2020-08-31 14:07:09 +08:00
if(CurrentLogin === AuthorLogin){
auth('get');
}else{
setIsSpining(false);
}
},[AuthorLogin,CurrentLogin])
2020-08-26 16:09:27 +08:00
function auth(type){
const url = `/${owner}/${projectsId}/ci_authorize.json`;
axios({
method:`${type}`,
url
}).then(result=>{
if(result && result.data ){
2020-08-28 11:58:32 +08:00
setIsSpining(false);
setStep(result.data.step);
2020-10-15 19:44:17 +08:00
setFieldsValue({...result.data.cloud_account});
2020-08-26 16:09:27 +08:00
}
}).catch(error=>{
console.log(error);
})
}
2020-07-27 18:45:18 +08:00
2020-07-22 15:50:08 +08:00
const helper = useCallback(
(label, name, rules, widget, isRequired) => (
<React.Fragment>
2020-07-31 20:15:28 +08:00
<span className={isRequired ? "required" : ""}>{label}</span>
2020-07-22 15:50:08 +08:00
<Form.Item>
{getFieldDecorator(name, { rules, validateFirst: true })(widget)}
</Form.Item>
</React.Fragment>
),
[]
);
2020-07-31 20:15:28 +08:00
// 下一步
function goStep() {
validateFields((error, values) => {
2020-08-28 11:58:32 +08:00
if (!error) {
2020-10-15 19:44:17 +08:00
if(step > 0){
setAuthorityValBox(true);
}else{
setIsSpining(true);
const url = `/${owner}/${projectsId}/cloud_accounts.json`;
2020-10-16 11:39:12 +08:00
axios.post(url, {...values,ip_num:values.ip}).then((result) => {
2020-10-15 19:44:17 +08:00
setIsSpining(false);
if (result && result.data.redirect_url) {
props.showNotification("服务器信息配置完成!");
setStep(1);
setAuthorityValBox(true);
}
})
.catch((error) => {
console.log(error);
setIsSpining(false);
});
}
2020-07-22 15:50:08 +08:00
}
2020-08-28 11:58:32 +08:00
});
2020-07-22 15:50:08 +08:00
}
2020-08-28 11:58:32 +08:00
// 开始激活
function startActive(){
setIsSpining(true);
2020-09-28 14:51:24 +08:00
const url = `/${owner}/${projectsId}/activate.json`;
2020-08-28 11:58:32 +08:00
axios.post(url).then(result=>{
setIsSpining(false);
if(result && result.data.status === 0){
props.history.push(`/projects/${owner}/${projectsId}/devops/dispose`);
// 需要将顶部的open_devops修改
let { changeOpenDevops } = props;
changeOpenDevops && changeOpenDevops(true);
}
}).catch(error=>{
console.log(error);
setIsSpining(false);
})
2020-08-26 16:09:27 +08:00
}
2020-10-15 19:44:17 +08:00
// 取消授权-登录密码的输入
function cancelAuthority(){
setAuthorityValBox(false);
}
// 确认授权
2020-10-16 11:39:12 +08:00
function okAuthority(step){
setAuthorityValBox(false);
setStep(step);
2020-10-15 19:44:17 +08:00
}
2020-07-31 20:15:28 +08:00
return (
2020-08-26 16:09:27 +08:00
<Spin spinning={isSpining}>
2020-10-16 11:39:12 +08:00
<PasswordAuthority authorityValBox={authorityValBox} successFunc={okAuthority} cancelFunc={cancelAuthority}></PasswordAuthority>
2020-08-26 16:09:27 +08:00
<div className="activatePanel">
2020-08-27 15:15:03 +08:00
<img src={activate} alt="" width="250px" />
<P>定义DevOps工作流帮助您检测bug发布代码</P>
2020-11-23 15:23:19 +08:00
{
CurrentLogin !== AuthorLogin && (step === undefined || (step && step < 1)) &&
<div className="noOperation">DevOps开启功能暂未对项目创建者以外的角色开放可以联系项目创建者进行开启开启后便可查看构建信息</div>
}
2020-10-29 15:40:30 +08:00
<a href={"https://forum.trustie.net/forums/3080/detail"} target="_blank" style={{ color: "#5091FF"}}>
2020-08-27 15:15:03 +08:00
了解什么是DevOps
2020-08-28 11:58:32 +08:00
</a>
2020-11-23 15:23:19 +08:00
<a href={"https://forum.trustie.net/forums/3110/detail"} target="_blank" style={{ color: "#5091FF"}}>
如何使用DevOps
</a>
2020-08-27 15:15:03 +08:00
{
AuthorLogin === CurrentLogin ?
2020-07-31 20:15:28 +08:00
<React.Fragment>
2020-10-15 19:44:17 +08:00
{ step <=1 ?
2020-08-27 15:15:03 +08:00
<React.Fragment>
2020-09-02 11:29:31 +08:00
<Input.Password style={{display:'none'}} size="large" />
2020-08-31 14:07:09 +08:00
<Form style={{marginTop:"20px"}}>
2020-08-27 15:15:03 +08:00
<p className="mb20" style={{width:"370px"}}>请仔细核对您的服务器信息一旦确认提交将无法修改</p>
{helper(
"服务器IP地址",
2020-10-15 19:44:17 +08:00
"ip",
2020-08-27 15:15:03 +08:00
[{ required: true, message: "请输入服务器IP地址" }],
<Input
placeholder="请输入服务器IP地址"
style={{ width: "368px" }}
size="large"
2020-10-15 19:44:17 +08:00
disabled={step > 0}
2020-08-27 15:15:03 +08:00
/>,
true
)}
2020-08-26 16:09:27 +08:00
{helper(
2020-08-27 15:15:03 +08:00
"服务器用户名:",
"account",
[{ required: true, message: "请输入服务器用户名" }],
2020-10-15 19:44:17 +08:00
<Input placeholder="请输入服务器用户名" size="large" disabled={step > 0}/>,
2020-08-27 15:15:03 +08:00
true
)}
{helper(
"服务器密码:",
"secret",
[{ required: true, message: "请输入服务器密码" }],
2020-10-15 19:44:17 +08:00
<Input.Password placeholder="请输入服务器密码" size="large" disabled={step > 0}/>,
2020-08-26 16:09:27 +08:00
true
)}
</Form>
2020-08-27 15:15:03 +08:00
<Blueback onClick={goStep}>下一步</Blueback>
</React.Fragment>
:""}
2020-10-15 19:44:17 +08:00
{step > 1 &&
2020-08-31 14:07:09 +08:00
<div style={{textAlign:'center',marginTop:"20px"}}>
2020-08-28 11:58:32 +08:00
<Blueback onClick={startActive} className="mt20">开始激活</Blueback>
2020-08-27 15:15:03 +08:00
</div>
2020-09-28 14:51:24 +08:00
}
2020-08-27 15:15:03 +08:00
</React.Fragment>
:""
}
2020-08-26 16:09:27 +08:00
</div>
</Spin>
2020-07-31 20:15:28 +08:00
);
2020-07-22 15:50:08 +08:00
}
2020-07-31 20:15:28 +08:00
export default Form.create()(forwardRef(About));