You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/public/react/src/forge/Merge/merge.js

292 lines
8.9 KiB

import React , { Component } from "react";
import {Link} from 'react-router-dom';
import { Input ,Dropdown , Menu , Icon , Pagination , Spin } from 'antd';
5 years ago
import './merge.css';
import NoneData from '../../modules/courses/coursesPublic/NoneData';
import Nav from '../Order/Nav';
5 years ago
import OrderItem from './MergeItem';
import axios from 'axios';
const Search = Input.Search;
/**
* issue_chosen:下拉的筛选列表,
* data:列表接口返回的所有数据,
* issues:列表数组,
* isSpin:加载中,
* search:搜索关键字,
* author_id:发布者id,
* assigned_to_id:指派给的id
* limit:每页条数,
* page:当前页,
* search_count:列表总条数
* issue_type:搜索条件
*/
class merge extends Component{
constructor(props){
super(props);
this.state={
issue_chosen:undefined,
data:undefined,
issues:undefined,
isSpin:false,
search:undefined,
author_id:undefined,
assigned_to_id:undefined,
limit:15,
page:1,
search_count:undefined,
5 years ago
issue_type:undefined,
status_type:'1',
//设置选择高亮
openselect:1,
closeselect:undefined,
}
}
componentDidMount=()=>{
this.getSelectList();
this.getIssueList();
}
getSelectList=()=>{
const { projectsId } = this.props.match.params;
const url = `/projects/${projectsId}/issues/index_chosen.json`;
axios.get(url).then((result)=>{
if(result){
this.setState({
issue_chosen:result.data.issue_chosen
})
}
}).catch((error)=>{
console.log(error);
})
}
// 获取列表数据
5 years ago
getIssueList=(page,limit,search,author_id,assigned_to_id,id,value,status_type)=>{
const { projectsId } = this.props.match.params;
5 years ago
const url = `/projects/${projectsId}/pull_requests.json`;
axios.get(url,{
params:{
5 years ago
page,limit,search,author_id,assigned_to_id,status_type,
[id]:value
}
}).then((result)=>{
if(result){
this.setState({
data:result.data,
issues:result.data.issues,
search_count:result.data.search_count,
isSpin:false
})
}
}).catch((error)=>{
console.log(error);
})
}
getOption=(e,id)=>{
this.setState({
[id]:e.key
})
const { page,limit,search,author_id,assigned_to_id } = this.state;
5 years ago
if(e.key==="all"){
this.getIssueList(page,limit,search,author_id,assigned_to_id,id);
}else{
this.getIssueList(page,limit,search,author_id,assigned_to_id,id,e.key);
}
}
renderMenu =(array,name,id)=>{
return(
<Menu>
5 years ago
<Menu.Item key={"all"} onClick={(e)=>this.getOption(e,id)}>{name}</Menu.Item>
{
array && array.length > 0 && array.map((item,key)=>{
return(
<Menu.Item key={item.id} onClick={(e)=>this.getOption(e,id)}>{item.name}</Menu.Item>
)
})
}
</Menu>
)
}
// 翻页
ChangePage=(page)=>{
this.setState({
page,
isSpin:true
})
const {limit,search} = this.state;
this.getIssueList(page,limit,search);
}
// 搜索
searchFunc=(value)=>{
this.setState({
search:value,
isSpin:true
})
const {page,limit} = this.state;
this.getIssueList(page,limit,value);
}
5 years ago
openorder=(type)=>{
if(type){
const { current_user } = this.props;
if(type===1){
this.setState({
status_type:'1',
openselect:current_user.user_id,
closeselect:undefined
})
this.getIssueList("","","","","","","",1);
}else{
this.setState({
status_type:'2',
openselect:undefined,
closeselect:current_user.user_id
})
this.getIssueList("","","","","","","",2);
}
}
}
// 筛选:全部、指派给我、由我创建
ChangeAssign=(type)=>{
const { limit, search} = this.state;
this.setState({
isSpin:true
})
if(type){
const { current_user } = this.props;
if(type===1){
this.setState({
page:1,
5 years ago
author_id:undefined,
assigned_to_id:current_user.user_id
})
5 years ago
this.getIssueList(1,limit,search,undefined,current_user.user_id);
}else{
this.setState({
page:1,
5 years ago
author_id:current_user.user_id,
assigned_to_id:undefined
})
5 years ago
this.getIssueList(1,limit,search,current_user.user_id,undefined);
}
}else{
this.setState({
page:1,
author_id:undefined,
assigned_to_id:undefined
})
this.getIssueList(1,limit,search,undefined,undefined);
}
}
render(){
const { issue_chosen , issues , limit , page , search_count , data , isSpin,openselect,closeselect } = this.state;
const { projectsId } = this.props.match.params;
const menu = (
<Menu onClick={this.arrayList}>
<Menu.Item key={'created_at'} value="desc">到期日从近到远</Menu.Item>
<Menu.Item key={'created_at'} value="asc">到期日从远到近</Menu.Item>
<Menu.Item key={'issues_count'} value="desc">完成度从低到高</Menu.Item>
<Menu.Item key={'issues_count'} value="asc">完成度从高到低</Menu.Item>
<Menu.Item key={'issues_count'} value="asc">工单从多到少</Menu.Item>
<Menu.Item key={'issues_count'} value="asc">工单从少到多</Menu.Item>
</Menu>
)
const Paginations = (
<React.Fragment>
{
search_count > limit ?
<div className="mt30 mb50 edu-txt-center">
<Pagination simple defaultCurrent={page} total={search_count} pageSize={limit} onChange={this.ChangePage}></Pagination>
</div>:""
}
</React.Fragment>
)
return(
<div className="main">
<div className="topWrapper">
<Nav {...this.props} {...this.state}/>
<Link to={`/projects/${projectsId}/merge/new`} className="topWrapper_btn">创建合并请求</Link>
</div>
<div className="topWrapper" style={{borderBottom:"none"}}>
5 years ago
<p className="topWrapper_type">
<li className={openselect ? "active":""} onClick={()=>this.openorder(1)}>{data && data.open_count}个开启中</li>
<li className={closeselect ? "active":""} onClick={()=>this.openorder(2)}>{data && data.close_count}个已关闭</li>
{/* <span onClick={this.openorder} className={author_id ? "active":""}>{data && data.open_count}</span>
<span onClick={this.closeorder} className={author_id ? "active":""}>{data && data.close_count}个已关闭</span> */}
</p>
<div>
<Search
placeholder="搜索"
enterButton
onSearch={this.searchFunc}
style={{ width: 300 }}
/>
</div>
</div>
<Spin spinning={isSpin}>
<div className="f-wrap-between mb20">
5 years ago
<ul >
<li> </li>
</ul>
<ul className="topWrapper_select">
<li>
<Dropdown className="topWrapperSelect" overlay={this.renderMenu(issue_chosen && issue_chosen.issue_tag,'标签','issue_tag_id')} trigger={['click']} placement="bottomCenter">
5 years ago
<span>标签筛选<Icon type="caret-down" className="ml5" /></span>
</Dropdown>
</li>
<li>
<Dropdown className="topWrapperSelect" overlay={this.renderMenu(issue_chosen && issue_chosen.issue_version,'里程碑','issue_version')} trigger={['click']} placement="bottomCenter">
5 years ago
<span>里程碑筛选<Icon type="caret-down" className="ml5" /></span>
</Dropdown>
</li>
<li>
<Dropdown className="topWrapperSelect" overlay={this.renderMenu(issue_chosen && issue_chosen.assign_user,'指派人','assigned_to_id')} trigger={['click']} placement="bottomCenter">
5 years ago
<span>指派人筛选<Icon type="caret-down" className="ml5" /></span>
</Dropdown>
</li>
<li>
<Dropdown className="topWrapperSelect" overlay={this.renderMenu(issue_chosen && issue_chosen.issue_type,'类型','issue_type')} trigger={['click']} placement="bottomCenter">
5 years ago
<span>类型筛选<Icon type="caret-down" className="ml5" /></span>
</Dropdown>
</li>
<li>
<Dropdown className="topWrapperSelect" overlay={menu} trigger={['click']} placement="bottomCenter">
5 years ago
<span>排序<Icon type="caret-down" className="ml5" /></span>
</Dropdown>
</li>
</ul>
</div>
{
search_count === 0 ?
<NoneData></NoneData>
:
5 years ago
<OrderItem issues={issues} search_count={search_count} page={page} limit={limit} {...this.props} {...this.state}></OrderItem>
}
{ Paginations }
</Spin>
</div>
)
}
}
export default merge;