From 3a16636081f0ea56d075197e7bc702f0ef8ca5b1 Mon Sep 17 00:00:00 2001
From: caicai8 <1149225589@qq.com>
Date: Mon, 24 Feb 2020 20:19:03 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8D=8F=E4=BD=9C=E8=80=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
public/react/src/forge/Main/CoderRootIndex.js | 38 +-----
public/react/src/forge/Main/Detail.js | 50 +++++--
public/react/src/forge/Main/IndexItem.js | 2 +-
.../react/src/forge/Settings/Collaborator.js | 127 ++++++++++++++----
public/react/src/forge/Settings/Setting.js | 8 +-
5 files changed, 144 insertions(+), 81 deletions(-)
diff --git a/public/react/src/forge/Main/CoderRootIndex.js b/public/react/src/forge/Main/CoderRootIndex.js
index 193af4aad..dd68921cd 100644
--- a/public/react/src/forge/Main/CoderRootIndex.js
+++ b/public/react/src/forge/Main/CoderRootIndex.js
@@ -24,43 +24,9 @@ const CoderRootBranch = Loadable({
loading: Loading,
})
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(){
- const {projectDetail} = this.props;
+ const { projectDetail } = this.props;
const { projectsId } = this.props.match.params;
const { pathname } = this.props.location;
return(
diff --git a/public/react/src/forge/Main/Detail.js b/public/react/src/forge/Main/Detail.js
index bdc31c545..7fd70ad78 100644
--- a/public/react/src/forge/Main/Detail.js
+++ b/public/react/src/forge/Main/Detail.js
@@ -86,8 +86,11 @@ class Detail extends Component{
praises_count:undefined ,
forked_count: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=()=>{
- this.getUserInfo();
+ // this.getUserInfo();
+ this.getDetail();
}
- componentDidUpdate=(provState)=>{
- if(provState.match.params.projectsId !== this.props.match.params.projectsId){
- this.getDetail();
- }
- }
+ // componentDidUpdate=(provState)=>{
+ // if(provState.match.params.projectsId !== this.props.match.params.projectsId){
+ // this.getDetail();
+ // }
+ // }
getDetail=()=>{
- // const { login } = this.props.current_user;
- const { current_user } = this.state;
+ const { current_user } = this.props;
const { projectsId } = this.props.match.params;
const url = `/${current_user&¤t_user.login}/${projectsId}.json`;
axios.get(url).then((result)=>{
@@ -135,6 +138,9 @@ class Detail extends Component{
praises_count:result.data.praises_count,
forked_count:result.data.forked_count,
})
+ if(result.data.project_id){
+ this.getBranch(result.data.project_id);
+ }
}
}).catch((error)=>{})
}
@@ -205,13 +211,35 @@ class Detail extends Component{
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(){
- 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 { isManager , isDeveloper } = this.props;
+
+ const { projectsId } = this.props.match.params;
return(
diff --git a/public/react/src/forge/Main/IndexItem.js b/public/react/src/forge/Main/IndexItem.js
index f5a02b4fb..3d80770d0 100644
--- a/public/react/src/forge/Main/IndexItem.js
+++ b/public/react/src/forge/Main/IndexItem.js
@@ -16,7 +16,7 @@ class IndexItem extends Component{
-
{item.name}
+
{item.name}
{ item.forked_count ? { item.forked_count}:"" }
{ item.praises_count }
diff --git a/public/react/src/forge/Settings/Collaborator.js b/public/react/src/forge/Settings/Collaborator.js
index 597a78e8b..d4ab6d4df 100644
--- a/public/react/src/forge/Settings/Collaborator.js
+++ b/public/react/src/forge/Settings/Collaborator.js
@@ -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)=> (