|
|
|
@ -1,38 +1,60 @@
|
|
|
|
|
import React , { Component } from 'react';
|
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
import { Input , AutoComplete , Dropdown , Menu , Icon } from 'antd';
|
|
|
|
|
import { Input , AutoComplete , Dropdown , Menu , Icon , Spin } from 'antd';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
|
|
const { Option } = AutoComplete;
|
|
|
|
|
const MENU_LIST = ['管理员','可读权限','可写权限'];
|
|
|
|
|
const MENU_LIST = [{
|
|
|
|
|
id:"Manager",
|
|
|
|
|
name:'管理员'
|
|
|
|
|
},{
|
|
|
|
|
id:"Developer",
|
|
|
|
|
name:'开发人员'
|
|
|
|
|
},{
|
|
|
|
|
id:"Reporter",
|
|
|
|
|
name:'报告人员'
|
|
|
|
|
}];
|
|
|
|
|
const LIMIT = 15;
|
|
|
|
|
class Collaborator extends Component{
|
|
|
|
|
constructor(props){
|
|
|
|
|
super(props);
|
|
|
|
|
this.state={
|
|
|
|
|
listData:undefined,
|
|
|
|
|
user:undefined,
|
|
|
|
|
user_id:undefined,
|
|
|
|
|
userDataSource:undefined,
|
|
|
|
|
page:1
|
|
|
|
|
page:1,
|
|
|
|
|
isSpin:true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount=()=>{
|
|
|
|
|
this.getMember();
|
|
|
|
|
if(this.props.project_id){
|
|
|
|
|
this.getMember(this.props.project_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate=(prevState)=>{
|
|
|
|
|
if(this.props.project_id && this.props.project_id !== prevState.project_id){
|
|
|
|
|
this.getMember(this.props.project_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取项目协作者
|
|
|
|
|
getMember=()=>{
|
|
|
|
|
getMember=(project_id)=>{
|
|
|
|
|
const { page } = this.state;
|
|
|
|
|
const { projectsId } = this.props.match.params;
|
|
|
|
|
|
|
|
|
|
const url = `/projects/${projectsId}/members.json`;
|
|
|
|
|
const url = `/projects/${project_id}/members.json`;
|
|
|
|
|
axios.get(url,{
|
|
|
|
|
params:{
|
|
|
|
|
page,limit:LIMIT
|
|
|
|
|
}
|
|
|
|
|
}).then(result=>{
|
|
|
|
|
if(result){
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
listData:result.data.members,
|
|
|
|
|
isSpin:false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}).catch(error=>{
|
|
|
|
|
console.log(error);
|
|
|
|
@ -40,9 +62,26 @@ class Collaborator extends Component{
|
|
|
|
|
}
|
|
|
|
|
// 选择用户
|
|
|
|
|
changeInputUser=(e)=>{
|
|
|
|
|
console.log(e);
|
|
|
|
|
this.setState({
|
|
|
|
|
user:e
|
|
|
|
|
})
|
|
|
|
|
this.getUserList(e);
|
|
|
|
|
}
|
|
|
|
|
changeUser=(e)=>{
|
|
|
|
|
console.log("click",e);
|
|
|
|
|
this.setState({
|
|
|
|
|
user_id:e,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serachUser=(e)=>{
|
|
|
|
|
console.log("select",e);
|
|
|
|
|
this.setState({
|
|
|
|
|
user:e.item.props.children
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
getUserList=(e)=>{
|
|
|
|
|
const url = `/users/list.json`;
|
|
|
|
|
axios.get(url,{
|
|
|
|
|
params:{
|
|
|
|
@ -51,7 +90,7 @@ class Collaborator extends Component{
|
|
|
|
|
}).then(result=>{
|
|
|
|
|
if(result){
|
|
|
|
|
this.setState({
|
|
|
|
|
userDataSource:result.data
|
|
|
|
|
userDataSource:result.data.users
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}).catch(error=>{
|
|
|
|
@ -59,34 +98,54 @@ class Collaborator extends Component{
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 修改权限
|
|
|
|
|
changeOperaiton=(e,id)=>{
|
|
|
|
|
console.log(e,id);
|
|
|
|
|
const { project_id } = this.props;
|
|
|
|
|
this.setState({
|
|
|
|
|
isSpin:true
|
|
|
|
|
})
|
|
|
|
|
const url = `/projects/${project_id}/members/change_role.json`;
|
|
|
|
|
axios.put(url,{
|
|
|
|
|
user_id:id,
|
|
|
|
|
role:e.key
|
|
|
|
|
}).then(result=>{
|
|
|
|
|
if(result){
|
|
|
|
|
this.props.showNotification('权限修改成功!');
|
|
|
|
|
this.getMember(project_id);
|
|
|
|
|
this.setState({
|
|
|
|
|
isSpin:false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}).catch(error=>{
|
|
|
|
|
console.log(error);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加协作者
|
|
|
|
|
addCollaborator=()=>{
|
|
|
|
|
const { projectsId } = this.props.match.params;
|
|
|
|
|
const { user } = this.state;
|
|
|
|
|
const { project_id } = this.props;
|
|
|
|
|
const { user_id } = this.state;
|
|
|
|
|
const url = `/projects/${projectsId}/members.json`;
|
|
|
|
|
axios.post(url,{
|
|
|
|
|
user_id:user
|
|
|
|
|
user_id
|
|
|
|
|
}).then(result=>{
|
|
|
|
|
if(result){
|
|
|
|
|
this.changeInputUser();
|
|
|
|
|
this.getMember(project_id);
|
|
|
|
|
}
|
|
|
|
|
}).catch(error=>{
|
|
|
|
|
console.log(error);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
render(){
|
|
|
|
|
const { user , userDataSource } = this.state;
|
|
|
|
|
const { user , userDataSource , listData , isSpin } = this.state;
|
|
|
|
|
|
|
|
|
|
const menu =(id)=> (
|
|
|
|
|
<Menu>
|
|
|
|
|
{
|
|
|
|
|
MENU_LIST.map((item,key)=>{
|
|
|
|
|
return(
|
|
|
|
|
<Menu.Item key="key" onClick={(e)=>this.changeOperaiton(e,id)}>{item}</Menu.Item>
|
|
|
|
|
<Menu.Item key={item.id} value={item.id} onClick={(e)=>this.changeOperaiton(e,id)}>{item.name}</Menu.Item>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -95,7 +154,7 @@ class Collaborator extends Component{
|
|
|
|
|
|
|
|
|
|
const source = userDataSource && userDataSource.map((item,key)=>{
|
|
|
|
|
return(
|
|
|
|
|
<Option value={item.login}>{item.username}</Option>
|
|
|
|
|
<Option key={key} value={`${item.username}`} onClick={this.serachUser}>{item.username}</Option>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
return(
|
|
|
|
@ -104,19 +163,30 @@ class Collaborator extends Component{
|
|
|
|
|
<div className="normalBox-title font-16">
|
|
|
|
|
协作者
|
|
|
|
|
</div>
|
|
|
|
|
<div className="collaboratorList">
|
|
|
|
|
<div className="collaboratorItem">
|
|
|
|
|
<span><Link to={``} className="color-blue">caicai</Link></span>
|
|
|
|
|
<span>
|
|
|
|
|
<Dropdown overlay={menu(1)} placement={"bottomCenter"}>
|
|
|
|
|
<span>管理员<Icon type="down" /></span>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</span>
|
|
|
|
|
<span style={{justifyContent:"center"}}>
|
|
|
|
|
<a className="red_btn">删除</a>
|
|
|
|
|
</span>
|
|
|
|
|
<Spin spinning={isSpin}>
|
|
|
|
|
<div className="collaboratorList">
|
|
|
|
|
{
|
|
|
|
|
listData && listData.map((item,key)=>{
|
|
|
|
|
const operation = MENU_LIST.filter(i=>i.id === item.role);
|
|
|
|
|
return(
|
|
|
|
|
<div className="collaboratorItem">
|
|
|
|
|
<span><Link to={``} className="color-blue">{item.name}</Link></span>
|
|
|
|
|
<span>
|
|
|
|
|
<Dropdown overlay={menu(`${item.id}`)} placement={"bottomCenter"}>
|
|
|
|
|
<span>{operation && operation[0].name}<Icon type="down" /></span>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</span>
|
|
|
|
|
<span style={{justifyContent:"center"}}>
|
|
|
|
|
<a className="red_btn">删除</a>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Spin>
|
|
|
|
|
<div className="addPanel">
|
|
|
|
|
<AutoComplete
|
|
|
|
|
value={user}
|
|
|
|
@ -124,6 +194,7 @@ class Collaborator extends Component{
|
|
|
|
|
style={{ width: 200 }}
|
|
|
|
|
onChange={this.changeInputUser}
|
|
|
|
|
placeholder="搜索用户"
|
|
|
|
|
onSelect={this.changeUser}
|
|
|
|
|
/>
|
|
|
|
|
<a className="small_submitBtn ml20" onClick={this.addCollaborator}>增加协作者</a>
|
|
|
|
|
</div>
|
|
|
|
|