forgeplus-react/src/forge/Activity/Activity.js

321 lines
12 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
2023-01-06 10:52:57 +08:00
import { Dropdown , Menu , Icon , Pagination , Spin , Tooltip } from 'antd';
import { getImageUrl } from 'educoder';
2020-06-22 14:07:06 +08:00
import '../css/index.scss';
2021-07-22 17:44:12 +08:00
import '../Branch/branch.scss';
2020-03-16 14:12:11 +08:00
import './activity.css';
2020-03-27 18:29:00 +08:00
import NoneData from '../Nodata';
2023-02-17 16:27:14 +08:00
import IssueLine from './issueLine';
import BranchLine from './branchLine';
2023-02-02 10:29:03 +08:00
import SmoothLine from './smoothLine';
2023-02-28 16:31:03 +08:00
import SmoothLineTwo from './smoothLineTwo';
2023-03-24 16:35:08 +08:00
import Demo from './demo';
2023-02-28 14:20:07 +08:00
import ProjectScale from './ProjectScale';
2023-02-02 10:29:03 +08:00
import Pie from './pie';
2020-03-27 18:29:00 +08:00
2020-03-16 14:12:11 +08:00
import ActivityItem from './ActivityItem';
import axios from 'axios';
const LIMIT = 15;
const ARRAY = [
2021-10-14 13:59:03 +08:00
{
id:"",
name:'全部'
},
2020-03-16 14:12:11 +08:00
{
id:1,
name:'1天'
},
{
id:3,
name:'3天'
},
{
id:7,
name:'1周'
},
{
id:30,
name:'1个月'
}
]
class Activity extends Component{
constructor(props){
super(props);
this.state={
2021-10-14 13:59:03 +08:00
time:undefined,
2020-03-16 14:12:11 +08:00
type:undefined,
state:undefined,
page:1,
2021-10-15 15:20:21 +08:00
pr_count:undefined,
new_pr_count:undefined,
close_issues_count:undefined,
open_issues_count:undefined,
pr_all_count:undefined,issues_count:undefined,
2020-03-16 14:12:11 +08:00
data:undefined,
2020-04-09 17:23:40 +08:00
project_trends:undefined,
2023-01-06 10:52:57 +08:00
codeStatus:undefined,
2023-02-28 14:20:07 +08:00
isSpin:false,
ai_shang_v1_url:undefined,
ai_shang_v2_url:undefined,
2023-02-28 16:31:03 +08:00
ai_shang_v3_url:undefined,
ai_shang_v4_url:undefined
2020-03-16 14:12:11 +08:00
}
}
componentDidMount=()=>{
2022-12-08 11:01:52 +08:00
this.updateDocumentTitle();
2020-03-16 14:12:11 +08:00
const { time,type,status,page } = this.state;
2020-04-09 17:23:40 +08:00
this.setState({
isSpin:true
})
2020-03-16 14:12:11 +08:00
this.getInfo(time,type,status,page);
2023-01-06 10:52:57 +08:00
this.getCodeInfo();
}
getCodeInfo(){
const { projectsId , owner } = this.props.match.params;
const url = `/v1/${owner}/${projectsId}/code_stats.json`;
axios.get(url).then(result=>{
if(result){
this.setState({
codeStatus:result.data
})
}
}).catch(error=>{})
2020-03-16 14:12:11 +08:00
}
2022-12-08 11:01:52 +08:00
componentDidUpdate(){
this.updateDocumentTitle();
}
// 更新网页标题
updateDocumentTitle(){
const {projectDetail} = this.props;
if(projectDetail && document.title.indexOf('动态-') === -1){
const { author, name} = projectDetail;
document.title = `动态-${author.name}/${name}`;
}
}
2020-03-16 14:12:11 +08:00
getInfo =(time,type,status,page)=>{
2020-08-12 18:13:18 +08:00
const { projectsId , owner } = this.props.match.params;
const url = `/${owner}/${projectsId}/activity.json`;
2020-03-16 14:12:11 +08:00
axios.get(url,{
params:{
time,type,status,page
}
}).then(result=>{
if(result){
this.setState({
data:result.data,
2020-04-09 17:23:40 +08:00
project_trends:result.data.project_trends,
2021-10-15 15:20:21 +08:00
isSpin:false,
pr_count:result.data.pr_count,
new_pr_count:result.data.new_pr_count,
close_issues_count:result.data.close_issues_count,
open_issues_count:result.data.open_issues_count,
pr_all_count:result.data.pr_all_count,
issues_count:result.data.issues_count,
2023-02-28 14:20:07 +08:00
ai_shang_v1_url:result.data.ai_shang_v1_url,
ai_shang_v2_url:result.data.ai_shang_v2_url,
2023-02-28 16:31:03 +08:00
ai_shang_v3_url:result.data.ai_shang_v3_url,
ai_shang_v4_url:result.data.ai_shang_v4_url
2020-03-16 14:12:11 +08:00
})
2021-10-14 13:59:03 +08:00
window.scrollTo(0,0);
2020-03-16 14:12:11 +08:00
}
}).catch(error=>{
console.log(error);
})
}
// 切换周期
changeTime=(e)=>{
this.setState({
2021-10-14 13:59:03 +08:00
time:e.key ==="item_0"?undefined:e.key,
2020-04-09 17:23:40 +08:00
isSpin:true
2020-03-16 14:12:11 +08:00
})
const { type,status,page } = this.state;
2021-10-14 13:59:03 +08:00
this.getInfo(e.key ==="item_0"?undefined:e.key,type,status,page);
2020-03-16 14:12:11 +08:00
}
//筛选
changeTrends=(type,status)=>{
this.setState({
2021-10-14 13:59:03 +08:00
type,status,page:1
2020-03-16 14:12:11 +08:00
})
2021-10-14 13:59:03 +08:00
const {time}=this.state;
this.getInfo(time,type,status,1);
2020-03-16 14:12:11 +08:00
}
// 分页
ChangePage=(page)=>{
this.setState({
page
})
const { time,type,status } = this.state;
this.getInfo(time,type,status,page);
}
2020-07-06 16:11:44 +08:00
menu =()=> (
<Menu>
{
ARRAY && ARRAY.map((item,key)=>{
return(
<Menu.Item key={item.id} onClick={this.changeTime}>{item.name}</Menu.Item>
)
})
}
</Menu>
)
2020-03-16 14:12:11 +08:00
render(){
2021-11-30 18:34:41 +08:00
const { time , data , page , project_trends , isSpin ,
pr_count , new_pr_count , close_issues_count , open_issues_count , pr_all_count ,issues_count,
2023-02-28 16:31:03 +08:00
type,status , codeStatus , ai_shang_v4_url,
2023-02-28 14:20:07 +08:00
ai_shang_v1_url ,ai_shang_v2_url, ai_shang_v3_url } = this.state;
2023-02-02 10:29:03 +08:00
let name = time ? ARRAY.filter(item=>item.id === parseInt(time,0)) :[{name:"全部"}];
2021-10-15 15:20:21 +08:00
const first_per = pr_all_count > 0 ? `${parseFloat(pr_count/pr_all_count).toFixed(2)*100}%` :"50%";
const second_per =pr_all_count > 0 ? `${parseFloat(new_pr_count/pr_all_count).toFixed(2)*100}%` :"50%";
const third_per =issues_count > 0 ?`${parseFloat(close_issues_count/issues_count).toFixed(2)*100}%` :"50%";
const fourth_per =issues_count > 0 ?`${parseFloat(open_issues_count/issues_count).toFixed(2)*100}%` :"50%";
2023-01-06 10:52:57 +08:00
const {projectDetail} = this.props;
2020-03-16 14:12:11 +08:00
return(
2023-02-02 10:29:03 +08:00
<div className="contentBox mt20">
2020-03-16 14:12:11 +08:00
<div className="normalBox">
<div class="normalBox-title">概览</div>
<div className="boxpart">
<div className="orderInfo">
<div>
<div className="percentLine prPercent">
<p className="percent_purple" style={{width:first_per}}></p>
<p className="percent_green resetStyle" style={{width:`${second_per}`}}></p>
</div>
<span>{data && data.pr_all_count}合并请求</span>
2020-03-16 14:12:11 +08:00
</div>
<div>
<div className="percentLine">
<p className="percent_red" style={{width:`${third_per}`}}></p>
<p className="percent_green" style={{width:`${fourth_per}`}}></p>
</div>
<span>{data && data.issues_count}疑修</span>
2020-03-16 14:12:11 +08:00
</div>
</div>
<ul className="percentBox">
<li>
<span className="purple">{data && data.pr_count}</span>
<span className={type==="PullRequest" && status==="delay" ?`change active`:"change"} onClick={()=>this.changeTrends("PullRequest","delay")}>已处理的合并请求</span>
</li>
<li>
<span className="green">{data && data.new_pr_count}</span>
<span className={type==="PullRequest"&& status==="not_delay" ?`change active`:"change"} onClick={()=>this.changeTrends("PullRequest","not_delay")}>未处理的合并请求</span>
</li>
<li>
<span className="red">{data && data.close_issues_count}</span>
<span className={type==="Issue"&& status==="delay" ?`change active`:"change"} onClick={()=>this.changeTrends("Issue","delay")}>已关闭的疑修</span>
</li>
<li>
<span className="green">{data && data.open_issues_count}</span>
<span className={type==="Issue"&& status==="not_delay" ?`change active`:"change"} onClick={()=>this.changeTrends("Issue","not_delay")}>未处理的疑修</span>
</li>
</ul>
{
codeStatus &&
<div className="prMsg">
<div><span className="fontbold">{codeStatus.author_count}位作者</span> <span className="fontbold">{codeStatus.commit_count}</span>
{codeStatus.commit_count_in_all_branches && codeStatus.commit_count_in_all_branches>0?<span> {projectDetail && projectDetail.default_branch}分支 <span>{codeStatus.commit_count_in_all_branches}次提交</span> </span>:""} {projectDetail && projectDetail.default_branch}
{codeStatus.change_files && codeStatus.change_files >0 ? <span><span className="fontbold">{codeStatus.change_files} 个文件</span> </span>:""}
{codeStatus.additions && codeStatus.additions >0 ?<span><span className="fontbold greencount">新增 {codeStatus.additions} 行代码</span></span>:""}
{(codeStatus.additions && codeStatus.additions >0) &&(codeStatus.deletions && codeStatus.deletions >0) ?<span> </span>:""}
{codeStatus.deletions && codeStatus.deletions >0 ?<span><span className="fontbold redcount"> 删除 {codeStatus.deletions} 行代码</span></span>:""}.</div>
{/* {
codeStatus.authors && codeStatus.authors.length > 0 &&
<ul className="prAuthor">
{
codeStatus.authors.map((i,v)=>{
return(
i.author ?
!i.author.id ?
<span>
<img src={getImageUrl(i.author && i.author.image_url)} width="38px" height="38px" alt=""/>
<Tooltip title={i.author && i.author.name} placement="bottom"><span>{i.author && i.author.name}</span></Tooltip>
</span>
:
<a href={i.author.login ? `/${i.author.login}` : `mailto:${i.author.email}`}>
<img src={getImageUrl(i.author && i.author.image_url)} width="38px" height="38px" alt=""/>
<Tooltip title={i.author && i.author.name} placement="bottom"><span>{i.author && i.author.name}</span></Tooltip>
</a>
:""
)
})
}
</ul>
} */}
</div>
}
2020-03-16 14:12:11 +08:00
</div>
</div>
2023-02-03 15:08:53 +08:00
{
2023-02-28 14:20:07 +08:00
ai_shang_v1_url &&
2023-02-02 10:29:03 +08:00
<div className="normalBox mt20">
<div class="normalBox-title">项目演化分析</div>
<div className="echartBox">
2023-03-08 10:23:37 +08:00
2023-04-18 16:43:22 +08:00
<span className="echartTitle" style={{marginTop:0}}>开源项目社群激发演化拓扑熵</span>
2023-02-28 14:20:07 +08:00
<BranchLine url={ai_shang_v1_url}/>
2023-03-08 10:23:37 +08:00
<p>基于信息熵围绕疑修任务的社群群智激发演化度量</p>
2023-04-18 16:43:22 +08:00
<span className="echartTitle">开源项目代码变更演化拓扑熵</span>
2023-02-28 14:20:07 +08:00
<IssueLine url={ai_shang_v3_url}/>
2023-03-08 10:23:37 +08:00
<p>基于信息熵围绕代码提交的软件代码变更演化度量</p>
2023-04-18 16:43:22 +08:00
<span className="echartTitle">开源项目社区演化拓扑熵</span>
2023-03-08 10:23:37 +08:00
<SmoothLineTwo url={ai_shang_v4_url}/>
<p>基于信息熵围绕项目社群的社区分裂缩减合并和扩大演化行为度量</p>
2023-03-24 16:35:08 +08:00
2023-02-02 10:29:03 +08:00
</div>
2023-02-28 09:41:49 +08:00
</div>
2023-02-03 15:08:53 +08:00
}
2023-02-02 10:29:03 +08:00
<div className="commentsBox">
<div className="trendsTop">
<span className="font-16">疑修/合并请求记录</span>
2023-02-02 10:29:03 +08:00
<div className="branchDropdown f-wrap-alignCenter">
<Dropdown overlay={this.menu()} trigger={['click']} placement="bottomLeft">
<a className="ant-dropdown-link">
<span className="color-grey-9 mr3">周期:</span>
{name && name.length>0 && name[0].name} <Icon type="down" />
</a>
</Dropdown>
</div>
</div>
<Spin spinning={isSpin}>
{
project_trends && project_trends.length > 0 ?
<div className="activity_list">
{
project_trends && project_trends.map((item,key)=>{
return(
<ActivityItem item={item} {...this.props} ></ActivityItem>
)
})
}
</div>
:
<NoneData _html="暂时还没有相关数据!" />
}
</Spin>
2020-04-09 17:23:40 +08:00
{
2023-02-02 10:29:03 +08:00
data && data.project_trends_size > 0 && data.project_trends_size > LIMIT &&
<div className="pageDIV">
<Pagination showQuickJumper defaultCurrent={page} total={data && data.project_trends_size} pageSize={LIMIT} onChange={this.ChangePage}></Pagination>
2020-04-09 17:23:40 +08:00
</div>
}
2023-02-02 10:29:03 +08:00
</div>
2020-03-16 14:12:11 +08:00
</div>
)
}
}
export default Activity;