forgeplus-react/src/forge/Main/CoderRootCommit.js

204 lines
7.9 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
2021-09-23 08:54:39 +08:00
import { Spin , Pagination, Timeline } from 'antd';
2020-03-16 14:12:11 +08:00
import { getImageUrl } from 'educoder';
2020-11-05 11:31:26 +08:00
import { truncateCommitId } from '../common/util';
import { AlignTop } from '../Component/layout';
2020-06-04 18:27:19 +08:00
import SelectBranch from '../Branch/Select';
2020-07-03 19:26:04 +08:00
import Nodata from '../Nodata';
2020-03-16 14:12:11 +08:00
2021-09-26 11:36:30 +08:00
import User from '../Component/User'
2021-09-23 08:54:39 +08:00
import Tree from './img/tree.png';
2020-03-16 14:12:11 +08:00
import axios from 'axios';
2020-04-23 16:26:42 +08:00
import {Link} from "react-router-dom";
2021-09-23 08:54:39 +08:00
import CopyTool from '../Component/CopyTool';
import './tree/Index.scss'
2020-03-16 14:12:11 +08:00
2021-08-03 17:37:14 +08:00
function returnbar(str){
if(str && str.length>0 && str.indexOf("%2F")>-1){
return str.replaceAll('%2F','/');
}
return str;
}
2021-09-23 08:54:39 +08:00
//代码库--提交页面
2020-03-16 14:12:11 +08:00
class CoderRootCommit extends Component{
constructor(props){
super(props)
this.state={
2020-07-03 19:26:04 +08:00
commitDatas:undefined,
2020-03-16 14:12:11 +08:00
dataCount:undefined,
2021-09-23 08:54:39 +08:00
limit:10,
2020-03-16 14:12:11 +08:00
page:1,
2020-12-08 17:16:07 +08:00
isSpining:false,
branchList:undefined
2020-03-16 14:12:11 +08:00
}
}
componentDidMount=()=>{
2020-11-24 10:46:27 +08:00
this.Init();
2020-12-08 17:16:07 +08:00
this.getBranchs();
}
// 获取分支列表
getBranchs=()=>{
const { projectsId , owner } = this.props.match.params;
axios.get(`/${owner}/${projectsId}/branches.json`).then(result=>{
this.setState({
branchList:result.data
})
}).catch((error)=>{})
2020-11-24 10:46:27 +08:00
}
componentDidUpdate=(prevProps)=>{
const { location } = this.props;
const prevlocation = prevProps && prevProps.location;
if (location !== prevlocation) {
this.Init();
}
}
Init =()=>{
const { branchName } = this.props.match.params;
const { page , limit } = this.state;
2020-03-16 14:12:11 +08:00
this.setState({
2020-07-03 19:26:04 +08:00
isSpining:true
2020-03-16 14:12:11 +08:00
})
2020-11-24 10:46:27 +08:00
this.getCommitList( branchName , page , limit );
2020-03-16 14:12:11 +08:00
}
getCommitList=(branch , page , limit)=>{
2020-07-06 16:11:44 +08:00
this.setState({
isSpining:true
})
2020-08-13 11:42:44 +08:00
const { projectsId , owner } = this.props.match.params;
const url = `/${owner}/${projectsId}/commits.json`;
2020-03-16 14:12:11 +08:00
axios.get(url,{
params:{
2021-08-03 17:37:14 +08:00
sha:returnbar(branch),
2020-03-16 14:12:11 +08:00
page,
limit
}
}).then((result)=>{
2020-07-03 19:26:04 +08:00
if(result && result.data){
this.setState({
isSpining:false
})
2020-03-16 14:12:11 +08:00
const array = [];
2020-07-03 19:26:04 +08:00
result.data.commits && result.data.commits.length > 0 && result.data.commits.map((item,key)=>{
2020-03-16 14:12:11 +08:00
array.push({
name:item.author && item.author.name,
2020-04-23 16:26:42 +08:00
login: item.author && item.author.login,
id: item.author && item.author.id,
2020-03-16 14:12:11 +08:00
image_url:item.author && item.author.image_url,
sha:item.sha,
time_from_now:item.time_from_now,
message:item.message
})
})
this.setState({
2020-07-03 19:26:04 +08:00
commitDatas:array,
2020-03-16 14:12:11 +08:00
dataCount:result.data.total_count,
2020-07-03 19:26:04 +08:00
isSpining:false
2020-03-16 14:12:11 +08:00
})
}
}).catch((error)=>{console.log(error)})
}
2020-06-03 09:56:07 +08:00
// 切换分支 search:tag为根据标签搜索
2020-03-16 14:12:11 +08:00
changeBranch=(value)=>{
2020-11-24 10:46:27 +08:00
const { projectsId , owner } = this.props.match.params;
2021-09-01 09:33:22 +08:00
this.props.history.push(`/${owner}/${projectsId}/commits/branch/${value}`);
2020-03-16 14:12:11 +08:00
}
ChangePage=(page)=>{
2020-11-24 10:46:27 +08:00
const { branchName } = this.props.match.params;
const { limit } = this.state;
2021-09-24 11:27:32 +08:00
this.setState({
page: page
})
2020-11-24 10:46:27 +08:00
this.getCommitList(branchName , page , limit);
2020-03-16 14:12:11 +08:00
}
2020-07-03 19:26:04 +08:00
render(){
2020-12-08 17:16:07 +08:00
const { commitDatas , dataCount , limit , page , isSpining , branchList } = this.state;
2020-11-24 18:00:34 +08:00
const { projectDetail, commit_class , defaultBranch } = this.props;
2020-11-24 10:46:27 +08:00
const { projectsId , owner , branchName } = this.props.match.params;
2021-08-03 17:37:14 +08:00
let branch = returnbar(branchName || defaultBranch);
2020-03-16 14:12:11 +08:00
return(
2020-05-20 18:11:32 +08:00
<React.Fragment>
2021-05-06 14:59:54 +08:00
<div className={"main"}style={{padding:"0px",border:"none"}}>
2020-05-20 18:11:32 +08:00
<div className="f-wrap-between">
2020-06-04 18:27:19 +08:00
<SelectBranch
repo_id={projectDetail && projectDetail.repo_id}
projectsId={projectsId}
branch={branch}
changeBranch={this.changeBranch}
2020-08-12 18:13:18 +08:00
owner={owner}
2020-11-24 10:46:27 +08:00
history={this.props.history}
2020-12-08 17:16:07 +08:00
branchList={branchList}
2020-06-04 18:27:19 +08:00
></SelectBranch>
2020-05-20 18:11:32 +08:00
</div>
2020-07-03 19:26:04 +08:00
<Spin spinning={isSpining}>
2021-09-23 08:54:39 +08:00
<Timeline className="commitList">
{
commitDatas && commitDatas.length > 0 && commitDatas.map((item,k)=>{
return(
2021-09-24 11:27:32 +08:00
<Timeline.Item key={k} dot={page ===1 && k===0 ?<span className="new-conmmit">最新</span>:<i className="iconfont icon-a-yuanquan2x"></i>}>
2021-09-23 08:54:39 +08:00
<div className="commitList-item f-wrap-between">
<div>
<AlignTop>
2021-09-24 11:27:32 +08:00
<Link to={`/${owner}/${projectsId}/commits/${truncateCommitId(`${item.sha}`)}/${branch}`} className="commitDesc font-14 color-grey-3 font-bd">{item.message}</Link>
2021-09-23 08:54:39 +08:00
</AlignTop>
<p className="f-wrap-alignCenter mt15">
2021-09-26 11:36:30 +08:00
<User
id = {item.id}
url={(item.image_url && getImageUrl(`/${item.image_url}`))|| "https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3025493530,1989042357&fm=26&gp=0.jpg"}
name={item.name}
/>
{item.time_from_now && <li className="ml4">提交于{item.time_from_now}</li>}
{/* {
2021-09-23 08:54:39 +08:00
item.id ?
<Link to={`/${item.login}`} className="show-user-link">
{item.image_url?<img src={getImageUrl(`/${item.image_url}`)} alt="" width="28px" height="28px" className="mr8 radius"/>:""}
2021-09-26 11:36:30 +08:00
<label className="font-14 color-grey-3" style={{verticalAlign:'middle'}}><label className="font-bd" style={{cursor:"pointer"}}>{item.name ?`${item.name} `:""}</label> {item.time_from_now}</label>
2021-09-23 08:54:39 +08:00
</Link>:
<span className="show-user-link">
{item.image_url?<img src={getImageUrl(`/${item.image_url}`)} alt="" width="28px" height="28px" className="mr8 radius"/>:""}
<label className="font-14 color-grey-3" style={{verticalAlign:'middle'}}><label className="font-bd">{item.name ?`${item.name} `:""}</label> {item.time_from_now}</label>
</span>
2021-09-26 11:36:30 +08:00
} */}
2021-09-23 08:54:39 +08:00
</p>
</div>
<div>
<div className="treecopy">
2021-09-24 11:27:32 +08:00
<div className="shadow">
2021-09-23 08:54:39 +08:00
<span className="treecopy-cont">
<img src={Tree} alt="sha" width={"16px"}/>
2021-09-24 11:27:32 +08:00
<Link to={`/${owner}/${projectsId}/commits/${truncateCommitId(`${item.sha}`)}/${branch}`}>{truncateCommitId(`${item.sha}`)}</Link>
2021-09-23 08:54:39 +08:00
<input type="text" id={`value${k}`} value={`${truncateCommitId(`${item.sha}`)}`}/>
</span>
<CopyTool beforeText="复制commit id" afterText="复制成功" inputId={`value${k}`}/>
</div>
2021-09-24 11:27:32 +08:00
<button className="btn-83" onClick={()=>{window.location.href=`/${owner}/${projectsId}/tree/${truncateCommitId(item.sha)}`}}>浏览文件</button>
2021-09-23 08:54:39 +08:00
</div>
</div>
2020-05-20 18:11:32 +08:00
</div>
2021-09-23 08:54:39 +08:00
</Timeline.Item>
)
})
}
{commitDatas && commitDatas.length === 0 && <Nodata _html="暂无数据"/>}
</Timeline>
2020-07-03 19:26:04 +08:00
{
dataCount > limit ?
<div className="edu-txt-center pt30 mb30">
<Pagination simple defaultCurrent={page} total={dataCount} pageSize={limit} onChange={this.ChangePage}></Pagination>
</div>
:""
}
2020-05-20 18:11:32 +08:00
</Spin>
2020-03-16 14:12:11 +08:00
</div>
2020-05-20 18:11:32 +08:00
</React.Fragment>
2020-03-16 14:12:11 +08:00
)
}
}
2020-03-30 10:21:22 +08:00
export default CoderRootCommit;