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

138 lines
4.3 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
2020-05-28 11:35:57 +08:00
import { Spin } from 'antd';
2020-03-16 14:12:11 +08:00
import { getImageUrl } from 'educoder';
2020-03-30 10:21:22 +08:00
import { truncateCommitId } from '../common/util'
2020-03-16 14:12:11 +08:00
import SelectBranch from '../Branch/SelectBranch';
import axios from 'axios';
2020-04-23 16:26:42 +08:00
import {Link} from "react-router-dom";
2020-03-16 14:12:11 +08:00
class CoderRootCommit extends Component{
constructor(props){
super(props)
this.state={
branch:"master",
data:undefined,
dataCount:undefined,
limit:50,
page:1,
isSpin:false
}
}
componentDidMount=()=>{
const { branch , page , limit } = this.state;
this.setState({
isSpin:true
})
this.getCommitList( branch , page , limit );
}
getCommitList=(branch , page , limit)=>{
const { projectsId } = this.props.match.params;
2020-03-20 20:50:30 +08:00
const url = `/repositories/${projectsId}/commits.json`;
2020-03-16 14:12:11 +08:00
axios.get(url,{
params:{
sha:branch,
page,
limit
}
}).then((result)=>{
if(result){
const array = [];
result.data && result.data.commits.length > 0 && result.data.commits.map((item,key)=>{
array.push({
name:item.author && item.author.name,
2020-04-23 16:26:42 +08:00
login: item.author && item.author.login,
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({
data:array,
dataCount:result.data.total_count,
isSpin:false
})
}
}).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)=>{
const { page , limit } = this.state;
this.setState({
isSpin:true,
2020-06-03 09:56:07 +08:00
branch:value,
2020-03-16 14:12:11 +08:00
})
2020-06-03 09:56:07 +08:00
this.getCommitList(value , page , limit);
2020-03-16 14:12:11 +08:00
}
ChangePage=(page)=>{
const { branch , limit } = this.state;
this.getCommitList(branch , page , limit);
}
render(){
const { branch , data , dataCount , limit , page , isSpin } = this.state;
2020-06-03 09:56:07 +08:00
const { branchs , projectDetail } = this.props;
2020-03-16 14:12:11 +08:00
const title =()=>{
return(
<div className="f-wrap-between" style={{alignItems:"center"}}>
<span className="font-16">{dataCount}次提交代码({branch})</span>
</div>
)
}
const Pagination =()=> {
if(dataCount > limit){
2020-03-30 10:21:22 +08:00
return(
2020-03-16 14:12:11 +08:00
<div className="edu-txt-center pt30 mb30">
<Pagination simple defaultCurrent={page} total={dataCount} pageSize={limit} onChange={this.ChangePage}></Pagination>
</div>
)
}
}
return(
2020-05-20 18:11:32 +08:00
<React.Fragment>
<div className="main">
<div className="f-wrap-between">
2020-06-03 09:56:07 +08:00
<SelectBranch repo_id={projectDetail && projectDetail.repo_id} branch={branch} branchs={branchs} changeBranch={this.changeBranch}></SelectBranch>
2020-05-20 18:11:32 +08:00
</div>
<Spin spinning={isSpin}>
<div className="commonBox">
<div className="commonBox-title">
{title()}
</div>
<div className="commitList">
{
data && data.length > 0 && data.map((item,key)=>{
return(
<div>
<p className="df">
<span className="commitKey" style={{marginLeft:0}}>{truncateCommitId(`${item.sha}`)}</span>
<span className="flex1 ml20 font-16 color-grey-3">{item.message}</span>
{/* <Link to={''} className="color-blue">浏览代码</Link> */}
</p>
<p className="f-wrap-alignCenter mt15">
<Link to={`/users/${item.login}/projects`} className="show-user-link">
<img src={getImageUrl(`images/${item.image_url}`)} alt="" width="28px" height="28px" className="mr15 radius"/>
<label className="font-14 color-grey-6" style={{'verticalAlign':'middle'}}>{item.name}:提交于 {item.time_from_now}</label>
</Link>
</p>
</div>
)
})
}
</div>
</div>
{ Pagination() }
</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;