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

163 lines
4.5 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
import { Table , Spin } from 'antd';
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 Top from './DetailTop';
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)})
}
// 切换分支
changeBranch=(value)=>{
const { branchList } = this.props;
2020-03-20 16:49:41 +08:00
let branchLastCommit = branchList && branchList.filter(item=>item.name === value)[0];
2020-03-16 14:12:11 +08:00
const { page , limit } = this.state;
this.setState({
isSpin:true,
branch:branchLastCommit.name,
})
this.getCommitList(branchLastCommit.name , page , limit);
}
ChangePage=(page)=>{
const { branch , limit } = this.state;
this.getCommitList(branch , page , limit);
}
render(){
const { branch , data , dataCount , limit , page , isSpin } = this.state;
const { branchs } = this.props;
const columns=[{
title:"作者",
dataIndex: 'name',
width:"10%",
render: (text,item) => (
<span className="f-wrap-alignCenter">
2020-04-23 16:26:42 +08:00
<Link to={`/users/${item.login}/projects`} className="show-user-link">
<img src={getImageUrl(`images/${item.image_url}`)} alt="" width="28px" height="28px" className="mr3 radius"/>
<label className="hide-1" style={{maxWidth:"75px",'vertical-align':'middle'}}>{text}</label>
</Link>
2020-03-16 14:12:11 +08:00
</span>
),
},{
title:"SHA",
dataIndex: 'sha',
render: (text) => (
2020-03-30 10:21:22 +08:00
<span className="commitKey">{truncateCommitId(text)}</span>
2020-03-16 14:12:11 +08:00
)
},{
title:"备注",
dataIndex: 'message',
render: (text) => (
<span>{text}</span>
)
},{
title:"提交时间",
className:"edu-txt-right",
dataIndex: 'time_from_now',
render: (text) => (
<span>{text}</span>
)
}]
const title =()=>{
return(
<div className="f-wrap-between" style={{alignItems:"center"}}>
<span className="font-16">{dataCount}次提交代码({branch})</span>
{/* <div className="f-wrap-alignCenter">
<Input placeholder="搜索提交历史" style={{width:"300px"}}/>
<Checkbox className="ml15">所有分支</Checkbox>
<a className="btn_32 ml15">搜索</a>
</div> */}
</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(
<div>
<Top { ...this.props } {...this.state} />
<div className="f-wrap-between mt20">
<SelectBranch branch={branch} branchs={branchs} changeBranch={this.changeBranch}></SelectBranch>
</div>
<Spin spinning={isSpin}>
<Table
className="mt20 wrap-commit-table"
columns={columns}
dataSource={data}
showHeader={false}
size="small"
pagination={false}
title={() => title()}
/>
{ Pagination() }
</Spin>
</div>
)
}
}
2020-03-30 10:21:22 +08:00
export default CoderRootCommit;