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-11-05 11:31:26 +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-12-08 17:16:07 +08:00
|
|
|
import { getBranch } from '../GetData/getData';
|
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={
|
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-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:{
|
|
|
|
|
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)=>{
|
2020-11-24 10:46:27 +08:00
|
|
|
const { projectsId , owner } = this.props.match.params;
|
|
|
|
|
this.props.history.push(`/projects/${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;
|
|
|
|
|
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;
|
2020-11-24 18:00:34 +08:00
|
|
|
let branch = branchName || defaultBranch;
|
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-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}>
|
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-11-10 18:09:38 +08:00
|
|
|
<Link to={`/projects/${owner}/${projectsId}/commits/${truncateCommitId(`${item.sha}`)}`} className="commitKey" style={{marginLeft:0}}>{truncateCommitId(`${item.sha}`)}</Link>
|
|
|
|
|
<Link to={`/projects/${owner}/${projectsId}/commits/${truncateCommitId(`${item.sha}`)}`} className="flex1 ml20 font-16 color-grey-3">{item.message}</Link>
|
2020-05-20 18:11:32 +08:00
|
|
|
</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"/>:""}
|
2020-12-09 14:19:55 +08:00
|
|
|
<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;
|