2020-03-16 14:12:11 +08:00
import React , { Component } from 'react' ;
2020-04-24 18:01:09 +08:00
import { Spin , Tooltip } from 'antd' ;
2020-03-24 15:08:57 +08:00
import { Link , Route , Switch , withRouter } from 'react-router-dom' ;
2020-03-16 14:12:11 +08:00
import '../css/index.css'
import './list.css' ;
import Loadable from 'react-loadable' ;
import Loading from '../../Loading' ;
import axios from 'axios' ;
import img _1 from '../Images/1.png' ;
import img _2 from '../Images/2.png' ;
import img _3 from '../Images/3.png' ;
import img _4 from '../Images/4.png' ;
import img _6 from '../Images/6.png' ;
import img _7 from '../Images/7.png' ;
import img _parise from '../Images/parise.png' ;
import img _focus from '../Images/focus.png' ;
import img _parised from '../Images/parised.png' ;
import img _focused from '../Images/focused.png' ;
import img _fork from '../Images/fork.png' ;
2020-04-09 18:13:26 +08:00
import img _milepost from '../Images/milepost.png' ;
2020-03-16 14:12:11 +08:00
const FileNew = Loadable ( {
loader : ( ) => import ( '../Newfile/Index' ) ,
loading : Loading ,
} )
const Setting = Loadable ( {
loader : ( ) => import ( '../Settings/Index' ) ,
loading : Loading ,
} )
const TagList = Loadable ( {
loader : ( ) => import ( '../Order/Tags' ) ,
loading : Loading ,
} )
const OrderNew = Loadable ( {
loader : ( ) => import ( '../Order/New' ) ,
loading : Loading ,
} )
const OrderDetail = Loadable ( {
loader : ( ) => import ( '../Order/Detail' ) ,
loading : Loading ,
} )
const OrderIndex = Loadable ( {
loader : ( ) => import ( '../Order/order' ) ,
loading : Loading ,
} )
const CoderRootIndex = Loadable ( {
loader : ( ) => import ( './CoderRootIndex' ) ,
loading : Loading ,
} )
const OrderMilepost = Loadable ( {
loader : ( ) => import ( '../Order/Milepost' ) ,
loading : Loading ,
} )
const OrdernewMilepost = Loadable ( {
loader : ( ) => import ( '../Order/newMilepost' ) ,
loading : Loading ,
} )
const OrderupdateMilepost = Loadable ( {
loader : ( ) => import ( '../Order/UpdateMilepost' ) ,
loading : Loading ,
} )
const OrderupdateDetail = Loadable ( {
loader : ( ) => import ( '../Order/UpdateDetail' ) ,
loading : Loading ,
} )
const OrdercopyDetail = Loadable ( {
loader : ( ) => import ( '../Order/CopyDetail' ) ,
loading : Loading ,
} )
//合并请求
const MergeIndexDetail = Loadable ( {
loader : ( ) => import ( '../Merge/merge' ) ,
loading : Loading ,
} )
const CreateMerge = Loadable ( {
loader : ( ) => import ( '../Merge/NewMerge' ) ,
loading : Loading ,
} )
const MessageCount = Loadable ( {
loader : ( ) => import ( '../Merge/MessageCount' ) ,
loading : Loading ,
} )
const MergeSubmit = Loadable ( {
loader : ( ) => import ( '../Merge/MergeSubmit' ) ,
loading : Loading ,
} )
const UpdateMerge = Loadable ( {
loader : ( ) => import ( '../Merge/UpdateMerge' ) ,
loading : Loading ,
} )
//版本发布
const VersionIndex = Loadable ( {
loader : ( ) => import ( '../Version/version' ) ,
loading : Loading ,
} )
const NewVersionIndex = Loadable ( {
loader : ( ) => import ( '../Version/NewVersion' ) ,
loading : Loading ,
} )
const UpVersionIndex = Loadable ( {
loader : ( ) => import ( '../Version/UpdateVersion' ) ,
loading : Loading ,
} )
const MilepostDetail = Loadable ( {
loader : ( ) => import ( '../Order/MilepostDetail' ) ,
loading : Loading ,
} )
const TrendsIndex = Loadable ( {
loader : ( ) => import ( '../Activity/Activity' ) ,
loading : Loading ,
} )
/ * *
* permission : Manager : 管理员 , Reporter : 报告人员 ( 只有读取权限 ) , Developer : 开发人员 ( 除不能设置仓库信息外 )
* /
2020-03-24 15:08:57 +08:00
2020-03-16 14:12:11 +08:00
class Detail extends Component {
constructor ( props ) {
super ( props ) ;
this . state = {
2020-03-24 16:51:34 +08:00
isSpin : false ,
2020-03-16 14:12:11 +08:00
projectDetail : undefined ,
isManager : false ,
isReporter : false ,
isDeveloper : false ,
project _id : undefined ,
watchers _count : undefined ,
praises _count : undefined ,
forked _count : undefined ,
2020-03-27 17:30:16 +08:00
watched : false ,
praised : false ,
2020-03-16 14:12:11 +08:00
http _url : undefined ,
author : undefined ,
branchs : undefined ,
branchList : undefined ,
branchLastCommit : undefined ,
}
}
componentDidMount = ( ) => {
this . getDetail ( ) ;
}
2020-03-24 16:51:34 +08:00
componentDidUpdate = ( prevState ) => {
2020-04-22 18:45:03 +08:00
if ( ( prevState . match . params . projectsId !== this . props . match . params . projectsId ) ) {
2020-03-24 16:51:34 +08:00
this . getDetail ( ) ;
}
2020-04-23 11:13:52 +08:00
const { search } = this . props . location ;
const search _c = prevState . location && prevState . location . search ;
if ( search && search !== search _c ) {
// console.log("branches",this.props.location);
// console.log("branches_p",prevState.location);
// console.log("111",this.props.dataquerys);
const { projectsId } = this . props . match . params ;
this . getBranch ( projectsId ) ;
}
2020-03-24 16:51:34 +08:00
}
2020-03-16 14:12:11 +08:00
getDetail = ( ) => {
2020-03-20 20:50:30 +08:00
const { projectsId } = this . props . match . params ;
const url = ` /repositories/ ${ projectsId } .json ` ;
2020-03-16 14:12:11 +08:00
axios . get ( url ) . then ( ( result ) => {
if ( result ) {
this . setState ( {
projectDetail : result . data ,
project _id : result . data . project _id ,
isManager : result . data . permission && result . data . permission === "Manager" ,
isReporter : result . data . permission && result . data . permission === "Reporter" ,
isDeveloper : result . data . permission && result . data . permission === "Developer" ,
http _url : result . data . clone _url ,
author : result . data . author ,
2020-03-27 17:30:16 +08:00
praised : result . data . praised ,
watched : result . data . watched ,
2020-03-16 14:12:11 +08:00
watchers _count : result . data . watchers _count ,
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 ) => { } )
}
// 关注和取消关注
focusFunc = ( flag ) => {
const { project _id } = this . state ;
2020-03-27 17:30:16 +08:00
axios ( {
method : flag ? 'delete' : 'post' ,
url : ` /projects/ ${ project _id } /watchers/ ${ flag ? 'unfollow' : 'follow' } .json `
} )
. then ( result => {
if ( result && result . data . status === 0 ) {
this . setWatchersCount ( result . data . watchers _count , result . data . watched ) ;
}
} )
. catch ( error => {
console . log ( error ) ;
} ) ;
2020-03-16 14:12:11 +08:00
}
// 点赞和取消点赞
pariseFunc = ( flag ) => {
const { project _id } = this . state ;
2020-03-27 17:30:16 +08:00
axios ( {
method : flag ? 'delete' : 'post' ,
url : ` /projects/ ${ project _id } /praise_tread/ ${ flag ? 'unlike' : 'like' } .json `
} )
. then ( result => {
if ( result && result . data . status === 0 ) {
this . setPraisesCount ( result . data . praises _count , result . data . praised )
}
} )
. catch ( error => {
console . log ( error ) ;
} ) ;
2020-03-16 14:12:11 +08:00
}
2020-03-27 17:30:16 +08:00
setWatchersCount = ( count , is _watched ) => {
this . setState ( {
watched : is _watched ,
watchers _count : count
} )
}
setPraisesCount = ( count , is _praised ) => {
this . setState ( {
praised : is _praised ,
praises _count : count
} )
}
2020-03-16 14:12:11 +08:00
// fork项目
forkFunc = ( ) => {
2020-04-24 14:59:25 +08:00
const { checkIfLogin } = this . props ;
if ( ! checkIfLogin ) {
this . props . showLoginDialog ( ) ;
return ;
}
2020-03-24 16:51:34 +08:00
this . setState ( {
isSpin : true
} )
2020-03-16 14:12:11 +08:00
const { project _id } = this . state ;
const url = ` /projects/ ${ project _id } /forks.json ` ;
axios . post ( url ) . then ( result => {
2020-04-07 15:54:55 +08:00
if ( result && result . data . status === 0 ) {
2020-04-07 15:58:45 +08:00
this . props . history . push ( ` /projects/ ${ result . data . id } /coders ` ) ;
2020-04-07 14:03:16 +08:00
this . props . showNotification ( result . data . message ) ;
2020-03-16 14:12:11 +08:00
}
2020-04-24 14:59:25 +08:00
this . setState ( {
isSpin : false
} )
2020-03-16 14:12:11 +08:00
} ) . catch ( error => {
2020-04-01 18:23:57 +08:00
this . setState ( {
isSpin : false
} )
2020-03-16 14:12:11 +08:00
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 ] ,
} )
}
} ) . catch ( ( error ) => { } )
}
render ( ) {
2020-03-27 17:30:16 +08:00
const { projectDetail , watchers _count , praises _count , forked _count , isSpin , isManager , watched , praised } = this . state ;
2020-03-16 14:12:11 +08:00
const url = this . props . history . location . pathname ;
2020-03-20 21:20:35 +08:00
const urlArr = url . split ( "/" ) ;
2020-03-20 21:40:43 +08:00
const urlFlag = ( urlArr . length === 3 ) ;
2020-03-24 15:40:22 +08:00
2020-03-20 21:40:43 +08:00
const { projectsId } = this . props . match . params ;
2020-03-16 14:12:11 +08:00
const { state } = this . props . history . location ;
return (
< div >
2020-03-24 16:51:34 +08:00
< Spin spinning = { isSpin } >
< div className = "detailHeader-wrapper" >
< div className = "normal" >
2020-04-09 18:13:26 +08:00
< div className = "f-wrap-between mb30" style = { { position : "relative" } } >
2020-03-24 16:51:34 +08:00
< p className = "font-18 color-white df flex-1 lineH2 mt15" style = { { alignItems : "center" } } >
2020-04-23 16:26:42 +08:00
{ projectDetail && projectDetail . author &&
< Link to = { ` /users/ ${ projectDetail . author . login } /projects ` } className = "show-user-link color-white" >
{ projectDetail . author . name }
< / L i n k >
}
2020-03-24 16:51:34 +08:00
< span className = "ml5 mr5" > / < / s p a n >
2020-04-24 18:01:09 +08:00
< span className = "hide-1 flex-1 df" >
2020-03-24 16:51:34 +08:00
< Link to = { ` /projects/ ${ projectsId } /coders ` } className = "color-white" > { projectDetail && projectDetail . name } < / L i n k >
2020-04-24 18:01:09 +08:00
{
projectDetail && projectDetail . forked _from _project _id && projectDetail . fork _info ?
< Tooltip placement = { 'right' }
title = { ` forked from ${ projectDetail . fork _info . fork _project _user _name } / ${ projectDetail . fork _info . fork _form _name } ` } >
< a href = { ` /users/ ${ projectDetail . fork _info . fork _project _user _login } /projects ` }
target = "_blank"
className = "ml20" >
< i className = "iconfont icon-fork color-grey-74 font-20 fl" > < / i >
< / a >
< / T o o l t i p > : " "
}
< / s p a n >
2020-03-24 16:51:34 +08:00
< / p >
2020-04-24 18:01:09 +08:00
{ / * {
projectDetail && projectDetail . forked _from _project _id && projectDetail . fork _info ? * / }
{ / * < a h r e f = { ` / u s e r s / $ { p r o j e c t D e t a i l & & p r o j e c t D e t a i l . f o r k _ i n f o & & p r o j e c t D e t a i l . f o r k _ i n f o . f o r k _ p r o j e c t _ u s e r _ l o g i n } / p r o j e c t s ` }
className = "fl mt5"
target = "_blank"
data - tip - right = { ` forked from ${ projectDetail && projectDetail . fork _info && projectDetail . fork _info . fork _project _user _name } / ${ projectDetail && projectDetail . fork _info && projectDetail . fork _info . fork _form _name } ` } >
< i className = "iconfont icon-fork color-grey-74 font-20 fl" > < / i >
< /a> */ }
{ /* / / < div className = "fork-css font-14 color-grey-ccc df flex-1 lineH2" style = { { alignItems : "center" } } >
// <span className="mr10">
// <img src={img_fork} alt="" width="13px"/>
// </span>
// <span className="mr10">forked from</span>
// <Link to={`/users/${projectDetail.fork_info.fork_project_user_login}/projects`} className="show-user-link color-grey-ccc">
// {projectDetail.fork_info.fork_project_user_name}
// </Link>
// <span className="ml5 mr5">/</span>
// <span className="hide-1 flex-1">
// <Link to={`/projects/${projectDetail.forked_from_project_id}/coders`} className="color-grey-ccc">{ projectDetail.fork_info.fork_form_name }</Link>
// </span>
// </div> */}
{ / * :
2020-04-07 15:08:48 +08:00
""
2020-04-24 18:01:09 +08:00
} * / }
2020-04-07 14:54:30 +08:00
2020-03-24 16:51:34 +08:00
< / d i v >
< div className = "f-wrap-between" >
< ul className = "headerMenu-wrapper" >
2020-04-13 17:45:36 +08:00
< li className = { ( url . indexOf ( "coders" ) > - 1 || urlFlag ) ? "active" : "" } >
< Link to = { { pathname : ` /projects/ ${ projectsId } /coders ` , state } } > < img alt = "" src = { img _1 } width = "18" / > 代码库 < / L i n k >
< / l i >
2020-04-09 18:13:26 +08:00
< li className = { ( url . indexOf ( "orders" ) > - 1 && ! ( url . indexOf ( "Milepost" ) > 0 || url . indexOf ( "meilpost" ) > 0 || url . indexOf ( "tags" ) > 0 ) ) ? "active" : "" } > < Link to = { { pathname : ` /projects/ ${ projectsId } /orders ` , state } } > < img alt = "" src = { img _2 } width = "12" / > 任务 { projectDetail && projectDetail . issues _count === 0 ? "" : projectDetail && projectDetail . issues _count === 0 ? projectDetail . issues _count : "" } < / L i n k > < / l i >
2020-03-24 16:51:34 +08:00
< li className = { url . indexOf ( "merge" ) > - 1 ? "active" : "" } > < Link to = { { pathname : ` /projects/ ${ projectsId } /merge ` , state } } > < img alt = "" src = { img _3 } width = "13" / > 合并请求 { projectDetail && projectDetail . pull _requests _count === 0 ? "" : projectDetail && projectDetail . pull _requests _count === 0 ? projectDetail . pull _requests _count : "" } < / L i n k > < / l i >
< li className = { url . indexOf ( "version" ) > - 1 ? "active" : "" } > < Link to = { { pathname : ` /projects/ ${ projectsId } /version ` , state } } > < img alt = "" src = { img _4 } width = "16" / > 版本发布 < / L i n k > < / l i >
2020-04-21 16:30:51 +08:00
2020-04-09 18:13:26 +08:00
< li className = { ( url . indexOf ( "Milepost" ) > - 1 || url . indexOf ( "meilpost" ) > - 1 ) ? "active" : "" } > < Link to = { { pathname : ` /projects/ ${ projectsId } /orders/Milepost ` , state } } > < img alt = "" src = { img _milepost } width = "16" / > 里程碑 < / L i n k > < / l i >
2020-04-21 16:30:51 +08:00
< li className = { url . indexOf ( "trends" ) > - 1 ? "active" : "" } > < Link to = { { pathname : ` /projects/ ${ projectsId } /trends ` , state } } > < img alt = "" src = { img _6 } width = "16" / > 动态 < / L i n k > < / l i >
2020-03-24 16:51:34 +08:00
{
isManager &&
< li className = { url . indexOf ( "setting" ) > 0 ? "active" : "" } > < Link to = { ` /projects/ ${ projectsId } /setting ` } > < img alt = "" src = { img _7 } width = "19" / > 仓库设置 < / L i n k > < / l i >
}
2020-04-09 18:13:26 +08:00
2020-03-24 16:51:34 +08:00
< / u l >
< span className = "df" >
< span className = "detail_tag_btn" >
2020-03-27 17:30:16 +08:00
< a className = "detail_tag_btn_name" onClick = { ( ) => this . focusFunc ( watched ) } >
< img src = { watched ? img _focused : img _focus } alt = "" width = "14px" / >
{ watched ? '取消关注' : '关注' }
2020-03-24 16:51:34 +08:00
< / a >
< span className = "detail_tag_btn_count" > { watchers _count } < / s p a n >
< / s p a n >
< span className = "detail_tag_btn" >
2020-03-27 17:30:16 +08:00
< a className = "detail_tag_btn_name" onClick = { ( ) => this . pariseFunc ( praised ) } >
< img src = { praised ? img _parised : img _parise } width = "13px" alt = "" / >
{ praised ? '取消点赞' : '点赞' }
2020-03-24 16:51:34 +08:00
< / a >
< span className = "detail_tag_btn_count" > { praises _count } < / s p a n >
< / s p a n >
< span className = "detail_tag_btn" >
< a className = "detail_tag_btn_name" onClick = { this . forkFunc } >
< img src = { img _fork } alt = "" width = "10px" / > Fork < / a >
< span className = "detail_tag_btn_count" > { forked _count } < / s p a n >
< / s p a n >
2020-03-16 14:12:11 +08:00
< / s p a n >
2020-03-24 16:51:34 +08:00
< / d i v >
2020-03-16 14:12:11 +08:00
< / d i v >
< / d i v >
2020-03-24 16:51:34 +08:00
< Switch { ... this . props } >
{ /* 新建文件 */ }
< Route path = "/projects/:projectsId/coders/:branch/newfile/:path"
render = {
( props ) => ( < FileNew { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/coders/:branch/newfile"
render = {
( props ) => ( < FileNew { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 标签列表 */ }
< Route path = "/projects/:projectsId/orders/tags"
render = {
( props ) => ( < TagList { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 仓库设置 */ }
< Route path = "/projects/:projectsId/setting"
render = {
( props ) => ( < Setting { ... this . props } { ... props } { ... this . state } getDetail = { this . getDetail } / > )
}
> < / R o u t e >
2020-04-09 18:13:26 +08:00
{ /* 任务详情 */ }
2020-03-24 16:51:34 +08:00
< Route path = "/projects/:projectsId/orders/:orderId/detail"
render = {
( props ) => ( < OrderDetail { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 里程碑 */ }
< Route path = "/projects/:projectsId/orders/Milepost"
render = {
( props ) => ( < OrderMilepost { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 新建里程碑 */ }
< Route path = "/projects/:projectsId/orders/meilpost"
render = {
( props ) => ( < OrdernewMilepost { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /*里程碑详情*/ }
< Route path = "/projects/:projectsId/orders/:meilid/MilepostDetail"
render = {
( props ) => ( < MilepostDetail { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /*修改里程碑*/ }
< Route path = "/projects/:projectsId/orders/:meilid/meilpost"
render = {
( props ) => ( < OrderupdateMilepost { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
2020-04-09 18:13:26 +08:00
{ /* 新建任务 */ }
2020-03-24 16:51:34 +08:00
< Route path = "/projects/:projectsId/orders/new"
render = {
( props ) => ( < OrderNew { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 修改详情 */ }
< Route path = "/projects/:projectsId/orders/:orderId/updatedetail"
render = {
( props ) => ( < OrderupdateDetail { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 复制详情 */ }
< Route path = "/projects/:projectsId/orders/:orderId/copyetail"
render = {
( props ) => ( < OrdercopyDetail { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 动态 */ }
< Route path = "/projects/:projectsId/trends"
render = {
( props ) => ( < TrendsIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
{ /* 代码Index */ }
< Route path = "/projects/:projectsId/orders"
render = {
( props ) => ( < OrderIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/merge/new"
render = {
( props ) => ( < CreateMerge { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/merge/:mergeId/UpdateMerge"
render = {
( props ) => ( < UpdateMerge { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/merge/:mergeId/Messagecount"
render = {
( props ) => ( < MessageCount { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/merge/:mergeId/MergeSubmit"
render = {
2020-03-31 15:07:27 +08:00
( props ) => ( < MessageCount { ... this . props } { ... props } { ... this . state } / > )
2020-03-24 16:51:34 +08:00
}
> < / R o u t e >
< Route path = "/projects/:projectsId/version/new"
render = {
( props ) => ( < NewVersionIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/version/:versionId/upversion"
render = {
( props ) => ( < UpVersionIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/version"
render = {
( props ) => ( < VersionIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId/merge"
render = {
( props ) => ( < MergeIndexDetail { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
2020-04-17 17:35:47 +08:00
< Route path = "/projects/:projectsId/coders/filesurl"
render = {
( props ) => ( < CoderRootIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
2020-03-24 16:51:34 +08:00
< Route path = "/projects/:projectsId/coders"
render = {
( props ) => ( < CoderRootIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< Route path = "/projects/:projectsId"
render = {
( props ) => ( < CoderRootIndex { ... this . props } { ... props } { ... this . state } / > )
}
> < / R o u t e >
< / S w i t c h >
< / S p i n >
2020-03-16 14:12:11 +08:00
< / d i v >
)
}
}
2020-03-24 15:08:57 +08:00
export default withRouter ( Detail ) ;