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

161 lines
4.9 KiB
React
Raw Normal View History

2020-07-27 18:45:18 +08:00
import React , { useState , useEffect } from 'react';
2021-01-29 14:17:49 +08:00
import { Spin , Pagination } from 'antd';
2021-01-19 18:11:38 +08:00
import { Blueback } from '../Component/layout';
2021-01-06 16:03:50 +08:00
import List from './Dispose/List';
2021-01-11 17:18:12 +08:00
import Head from './Dispose/head';
2020-07-27 18:45:18 +08:00
import axios from 'axios';
2021-01-13 15:46:17 +08:00
import PipelineName from './Dispose/PipelineName';
2020-07-10 15:42:57 +08:00
2021-01-11 17:18:12 +08:00
import styled from 'styled-components';
const Div = styled.div`{
padding:24px 30px;
}`;
2021-01-29 14:17:49 +08:00
const limit = 15;
2021-01-11 17:18:12 +08:00
function Dispose(props){
2021-01-19 18:11:38 +08:00
const [ spining , setSpining ] = useState(true);
const [ updateInfo , setUpdateInfo ] = useState(undefined);
2021-01-06 16:03:50 +08:00
const [ list , setList ] = useState(undefined);
2021-01-20 15:22:37 +08:00
const [ permission , setPermission ] = useState(undefined);
2021-01-13 15:46:17 +08:00
const [ visible , setVisible ] = useState(false);
2021-01-29 14:17:49 +08:00
const [ page , setPage ] = useState(1);
const [ totalCount , setTotalCount ] = useState(0);
const [ branchList , setBranchList ] =useState(undefined);
2021-01-11 17:18:12 +08:00
const projectDetail = props.projectDetail;
2021-01-20 15:22:37 +08:00
const current_user = props.current_user;
2021-01-11 17:18:12 +08:00
let projectsId = props.match.params.projectsId;
let owner = props.match.params.owner;
// 获取用户的身份角色
useEffect(()=>{
if(projectDetail){
setPermission(props.projectDetail.permission);
}
},[projectDetail])
2021-01-06 16:03:50 +08:00
2021-01-19 18:11:38 +08:00
function Init(){
2021-01-13 15:46:17 +08:00
const url = `/ci/pipelines/list.json`;
2021-01-19 18:11:38 +08:00
axios.get(url,{
params:{
2021-01-29 14:17:49 +08:00
identifier:projectsId,
page,limit
2021-01-19 18:11:38 +08:00
}
}).then(result=>{
2021-01-13 15:46:17 +08:00
if(result && result.data){
setList(result.data.pipelines);
2021-01-19 18:11:38 +08:00
setSpining(false);
2021-01-13 15:46:17 +08:00
}
}).catch(error=>{})
2021-01-19 18:11:38 +08:00
}
2021-01-06 16:03:50 +08:00
2021-01-19 18:11:38 +08:00
useEffect(()=>{
Init();
2021-01-29 14:17:49 +08:00
},[page])
2020-07-27 18:45:18 +08:00
2021-01-29 14:17:49 +08:00
useEffect(()=>{
if(owner && projectsId){
const url = `/${owner}/${projectsId}/branches.json`;
axios.get(url).then(result=>{
if(result && result.data){
setBranchList(result.data);
}
}).catch(error=>{})
}
},[owner,projectsId])
2020-07-27 18:45:18 +08:00
2021-01-11 17:18:12 +08:00
// 新增流水线
2021-01-29 14:17:49 +08:00
function addNew(pipeline_name,id,branch,event){
2021-01-13 15:46:17 +08:00
setVisible(true);
2021-01-19 18:11:38 +08:00
setUpdateInfo(undefined);
if(pipeline_name){
2021-02-01 11:10:51 +08:00
let eventA = event.split(",");
let l = {pipeline_name,id,branch,event:eventA}
2021-01-19 18:11:38 +08:00
setUpdateInfo(l);
}
2021-01-13 15:46:17 +08:00
}
2021-01-29 14:17:49 +08:00
function onOk(pipeline_name,updateId,branch,event){
2021-01-13 15:46:17 +08:00
if(pipeline_name){
2021-02-01 11:10:51 +08:00
let eventStr = "";
for(var i = 0;i<event.length;i++){
eventStr +=event[i]+",";
}
let s = eventStr.substring(0,eventStr.length-1);
2021-01-19 18:11:38 +08:00
if(!updateId){
// 新增
const url = `/ci/pipelines.json`;
axios.post(url,{
pipeline_name,
2021-01-20 10:12:35 +08:00
file_name:".trustie-pipeline.yml",
2021-02-01 11:10:51 +08:00
repo:projectsId,branch,event:s,owner
2021-01-19 18:11:38 +08:00
}).then(result=>{
2021-01-13 15:46:17 +08:00
setVisible(false);
2021-01-19 18:11:38 +08:00
if(result && result.data){
props.showNotification("流水线新增成功,请进行工作流配置!");
props.history.push(`/projects/${owner}/${projectsId}/devops/dispose/${result.data.id}`);
}else{
props.showNotification("流水线新增失败,请稍后再试!");
}
}).catch(error=>{})
}else{
// 修改
const url = `/ci/pipelines/${updateId}.json`;
axios.put(url,{
2021-02-01 11:10:51 +08:00
pipeline_name,repo:projectsId,branch,event:s,owner
2021-01-19 18:11:38 +08:00
}).then(result=>{
if(result && result.data){
setVisible(false);
Init();
props.showNotification("流水线名称更新成功!");
}else{
props.showNotification("流水线名称更新失败,请稍后再试!");
}
}).catch(error=>{})
}
2021-01-13 15:46:17 +08:00
}else{
props.showNotification("请输入流水线名称!");
}
2020-07-27 18:45:18 +08:00
}
2021-01-19 18:11:38 +08:00
// 删除
function deleteFunc(id){
const url = `/ci/pipelines/${id}.json`;
axios.delete(url).then(result=>{
if(result && result.data){
props.showNotification("流水线删除成功!");
Init();
}
}).catch(error=>{})
}
2021-01-29 14:17:49 +08:00
// 模板管理
function toModalManage(){
props.history.push(`/projects/cxt/DevOps-mo/devops/mould`);
}
2021-01-20 15:22:37 +08:00
const operate = current_user && (permission && permission !== "Reporter");
2020-07-27 18:45:18 +08:00
return(
2020-08-26 16:09:27 +08:00
<Spin spinning={spining}>
2021-01-29 14:17:49 +08:00
<PipelineName branchList={branchList} visible={visible} value={updateInfo} onCancel={()=>setVisible(false)} onOk={onOk}/>
2021-01-11 17:18:12 +08:00
<div className="disposePanel">
2021-01-29 14:17:49 +08:00
<Head manager={ operate ? toModalManage : undefined} />
2021-01-11 17:18:12 +08:00
<Div>
2021-01-29 14:17:49 +08:00
{ operate && <Blueback onClick={()=>addNew(undefined,undefined)}>新增流水线</Blueback> }
2021-01-11 17:18:12 +08:00
<div className="mt20 disposeList">
2021-01-20 15:22:37 +08:00
<List list={list} operate={operate} projectsId={projectsId} owner={owner} showModal={addNew} deleteFunc={deleteFunc}/>
2021-01-29 14:17:49 +08:00
{
totalCount > limit &&
<div className="mt20 pb20" style={{textAlign:'center'}}>
<Pagination simple current={page} pageSize={limit} total={totalCount} onChange={(page)=>setPage(page)}/>
</div>
}
2021-01-11 17:18:12 +08:00
</div>
</Div>
2020-07-27 18:45:18 +08:00
</div>
2020-08-26 16:09:27 +08:00
</Spin>
2020-07-27 18:45:18 +08:00
)
}
export default Dispose;