dev_forge
caicai8 5 years ago
parent a10a4e8f0c
commit 3a16636081

@ -24,43 +24,9 @@ const CoderRootBranch = Loadable({
loading: Loading, loading: Loading,
}) })
class CoderRootIndex extends Component{ class CoderRootIndex extends Component{
constructor(props){
super(props);
this.state={
branchs:undefined,
branchList:undefined,
branchLastCommit:undefined,
// http_url:undefined
}
}
componentDidMount=()=>{
this.getBranch();
}
// 获取分支列表
getBranch=()=>{
const { projectsId } = this.props.match.params;
console.log(this.props)
const url =`/projects/${projectsId}/branches.json`;
axios.get(url).then((result)=>{
if(result && result.data.length>0){
const branchs = [];
result.data.map((item,key)=>{
branchs.push({
index:key,
name:item.name
})
})
this.setState({
branchList:result.data,
branchs,
branchLastCommit:result.data[0],
// http_url:result.data[0].http_url
})
}
}).catch((error)=>{})
}
render(){ render(){
const {projectDetail} = this.props; const { projectDetail } = this.props;
const { projectsId } = this.props.match.params; const { projectsId } = this.props.match.params;
const { pathname } = this.props.location; const { pathname } = this.props.location;
return( return(

@ -86,8 +86,11 @@ class Detail extends Component{
praises_count:undefined , praises_count:undefined ,
forked_count:undefined, forked_count:undefined,
current_user:undefined, current_user:undefined,
http_url: undefined http_url: undefined,
branchs:undefined,
branchList:undefined,
branchLastCommit:undefined,
} }
} }
@ -107,18 +110,18 @@ class Detail extends Component{
componentDidMount=()=>{ componentDidMount=()=>{
this.getUserInfo(); // this.getUserInfo();
this.getDetail();
} }
componentDidUpdate=(provState)=>{ // componentDidUpdate=(provState)=>{
if(provState.match.params.projectsId !== this.props.match.params.projectsId){ // if(provState.match.params.projectsId !== this.props.match.params.projectsId){
this.getDetail(); // this.getDetail();
} // }
} // }
getDetail=()=>{ getDetail=()=>{
// const { login } = this.props.current_user; const { current_user } = this.props;
const { current_user } = this.state;
const { projectsId } = this.props.match.params; const { projectsId } = this.props.match.params;
const url = `/${current_user&&current_user.login}/${projectsId}.json`; const url = `/${current_user&&current_user.login}/${projectsId}.json`;
axios.get(url).then((result)=>{ axios.get(url).then((result)=>{
@ -135,6 +138,9 @@ class Detail extends Component{
praises_count:result.data.praises_count, praises_count:result.data.praises_count,
forked_count:result.data.forked_count, forked_count:result.data.forked_count,
}) })
if(result.data.project_id){
this.getBranch(result.data.project_id);
}
} }
}).catch((error)=>{}) }).catch((error)=>{})
} }
@ -205,13 +211,35 @@ class Detail extends Component{
console.log(error); console.log(error);
}) })
} }
// 获取分支列表
getBranch=(id)=>{
const url =`/projects/${id}/branches.json`;
axios.get(url).then((result)=>{
if(result && result.data.length>0){
const branchs = [];
result.data.map((item,key)=>{
branchs.push({
index:key,
name:item.name
})
})
this.setState({
branchList:result.data,
branchs,
branchLastCommit:result.data[0],
// http_url:result.data[0].http_url
})
}
}).catch((error)=>{})
}
render(){ render(){
const { projectsId } = this.props.match.params;
const { projectDetail , watchers_count , praises_count , forked_count } = this.state; const { projectDetail , watchers_count , praises_count , forked_count , project_id } = this.state;
const url = this.props.history.location.pathname; const url = this.props.history.location.pathname;
const { isManager , isDeveloper } = this.props; const { isManager , isDeveloper } = this.props;
const { projectsId } = this.props.match.params;
return( return(
<div> <div>
<div className="detailHeader-wrapper"> <div className="detailHeader-wrapper">

@ -16,7 +16,7 @@ class IndexItem extends Component{
<img className="p-r-photo" alt="" src={getImageUrl(`images/${item.author && item.author.image_url}`)} ></img> <img className="p-r-photo" alt="" src={getImageUrl(`images/${item.author && item.author.image_url}`)} ></img>
<div className="p-r-Infos"> <div className="p-r-Infos">
<div className="p-r-name"> <div className="p-r-name">
<Link to={`/projects/${item.id}/coder`} className="hide-1 font-16 color-grey-3" style={{whiteSpace:"wrap"}}>{item.name}</Link> <Link to={`/projects/${item.identifier}/coder`} className="hide-1 font-16 color-grey-3" style={{whiteSpace:"wrap"}}>{item.name}</Link>
<span className="p-r-tags"> <span className="p-r-tags">
{ item.forked_count ? <span><label>Fork</label><span>{ item.forked_count}</span></span>:"" } { item.forked_count ? <span><label>Fork</label><span>{ item.forked_count}</span></span>:"" }
<span><label>Start</label><span>{ item.praises_count }</span></span> <span><label>Start</label><span>{ item.praises_count }</span></span>

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

@ -73,14 +73,12 @@ class Setting extends Component{
resetSetting=()=>{ resetSetting=()=>{
this.props.form.validateFields((err,values)=>{ this.props.form.validateFields((err,values)=>{
if(!err){ if(!err){
const { projectsId } = this.props.match.params; const { project_id } = this.props;
const url = `/projects/${projectsId}.json`; const url = `/projects/${project_id}.json`;
axios.patch(url,{ axios.put(url,{
params:{
name:values.project_name, name:values.project_name,
description:values.project_description, description:values.project_description,
...values ...values
}
}).then(result=>{ }).then(result=>{
if(result){ if(result){
this.props.showNotification(`仓库信息修改成功!`); this.props.showNotification(`仓库信息修改成功!`);

Loading…
Cancel
Save