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

145 lines
4.7 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
2020-07-03 19:26:04 +08:00
import { Spin , Pagination } 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-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
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",
2020-07-03 19:26:04 +08:00
commitDatas:undefined,
2020-03-16 14:12:11 +08:00
dataCount:undefined,
2020-07-03 18:09:47 +08:00
limit:20,
2020-03-16 14:12:11 +08:00
page:1,
2020-07-03 19:26:04 +08:00
isSpining:false
2020-03-16 14:12:11 +08:00
}
}
componentDidMount=()=>{
const { branch , page , limit } = this.state;
this.setState({
2020-07-03 19:26:04 +08:00
isSpining:true
2020-03-16 14:12:11 +08:00
})
this.getCommitList( branch , page , limit );
}
getCommitList=(branch , page , limit)=>{
2020-07-06 16:11:44 +08:00
this.setState({
isSpining:true
})
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}/commits.json`;
2020-03-16 14:12:11 +08:00
axios.get(url,{
params:{
sha:branch,
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,
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)=>{
const { page , limit } = this.state;
2020-07-03 16:32:47 +08:00
const { getTopCount } = this.props;
2020-03-16 14:12:11 +08:00
this.setState({
2020-07-03 19:26:04 +08:00
isSpining: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-07-03 16:32:47 +08:00
getTopCount && getTopCount(value);
2020-03-16 14:12:11 +08:00
}
ChangePage=(page)=>{
2020-07-06 16:11:44 +08:00
2020-03-16 14:12:11 +08:00
const { branch , limit } = this.state;
this.getCommitList(branch , page , limit);
}
2020-07-03 19:26:04 +08:00
render(){
const { branch , commitDatas , dataCount , limit , page , isSpining } = this.state;
const { branchs , projectDetail, commit_class } = this.props;
2020-08-12 18:13:18 +08:00
const { projectsId , owner } = this.props.match.params;
2020-03-16 14:12:11 +08:00
return(
2020-05-20 18:11:32 +08:00
<React.Fragment>
2020-06-12 17:58:58 +08:00
<div className={commit_class}>
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-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}>
2020-05-20 18:11:32 +08:00
<div className="commonBox">
<div className="commonBox-title">
2020-07-03 19:26:04 +08:00
<div className="f-wrap-between" style={{alignItems:"center"}}>
<span className="font-16">{dataCount}次提交代码({branch})</span>
</div>
2020-05-20 18:11:32 +08:00
</div>
<div className="commitList">
{
2020-07-03 19:26:04 +08:00
commitDatas && commitDatas.length > 0 ? commitDatas.map((item,k)=>{
2020-05-20 18:11:32 +08:00
return(
2020-07-03 19:26:04 +08:00
<div key={k}>
<p className="f-wrap-alignCenter">
2020-05-20 18:11:32 +08:00
<span className="commitKey" style={{marginLeft:0}}>{truncateCommitId(`${item.sha}`)}</span>
<span className="flex1 ml20 font-16 color-grey-3">{item.message}</span>
</p>
<p className="f-wrap-alignCenter mt15">
2020-06-05 16:24:37 +08:00
<Link to={`/users/${item.login}`} className="show-user-link">
2020-06-04 18:27:19 +08:00
{item.image_url?<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.name}:`:""}提交于 {item.time_from_now}</label>
2020-05-20 18:11:32 +08:00
</Link>
2020-07-03 19:26:04 +08:00
</p>
2020-05-20 18:11:32 +08:00
</div>
)
2020-07-03 19:26:04 +08:00
}):<Nodata _html="暂无数据"/>
2020-05-20 18:11:32 +08:00
}
</div>
</div>
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;