forgeplus-react/src/forge/Main/CoderRootIndex.js

154 lines
4.7 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
2020-05-20 18:11:32 +08:00
import { Route , Switch } from 'react-router-dom';
2020-07-03 16:32:47 +08:00
import Top from './DetailTop';
2020-03-16 14:12:11 +08:00
import Loadable from 'react-loadable';
import Loading from '../../Loading';
2020-07-03 16:32:47 +08:00
import axios from 'axios';
2020-03-16 14:12:11 +08:00
2020-07-03 16:32:47 +08:00
const FileNew = Loadable({
loader: () => import('../Newfile/Index'),
loading: Loading,
})
const UploadFile = Loadable({
loader: () => import('../Newfile/upload_file'),
loading: Loading,
})
2020-03-16 14:12:11 +08:00
const CoderRootDirectory = Loadable({
loader: () => import('./CoderRootDirectory'),
loading: Loading,
})
const CoderRootCommit = Loadable({
loader: () => import('./CoderRootCommit'),
loading: Loading,
})
const CoderRootBranch = Loadable({
loader: () => import('./CoderRootBranch'),
loading: Loading,
})
2020-05-20 18:11:32 +08:00
const CoderRootTag = Loadable({
loader: () => import('./CoderRootTag'),
loading: Loading,
})
const CoderRootVersion = Loadable({
loader: () => import('../Version/version'),
loading: Loading,
})
const CoderRootVersionNew = Loadable({
2020-05-28 11:35:57 +08:00
loader: () => import('../Version/New'),
2020-05-20 18:11:32 +08:00
loading: Loading,
})
const CoderRootVersionUpdate = Loadable({
2020-05-28 11:35:57 +08:00
loader: () => import('../Version/New'),
2020-05-20 18:11:32 +08:00
loading: Loading,
})
2020-05-29 17:00:42 +08:00
const Diff = Loadable({
loader: () => import('./Diff'),
loading: Loading,
})
2020-03-30 18:51:30 +08:00
2020-03-16 14:12:11 +08:00
class CoderRootIndex extends Component{
2020-07-03 16:32:47 +08:00
constructor(props){
super(props);
this.state={
coderCount:undefined
}
}
componentDidMount=()=>{
let { search } = this.props.history.location;
let branchName = undefined;
if (search && search.indexOf("?branch=") > -1) {
branchName = search.split("?branch=")[1];
}
this.getTopCount(branchName);
}
getTopCount=(branch)=>{
2020-08-12 18:13:18 +08:00
const { projectsId , owner } = this.props.match.params;
const url = `/${owner}/${projectsId}/top_counts.json`;
2020-07-03 16:32:47 +08:00
axios.get(url,{params:{
ref:branch
}}).then(result=>{
if(result){
this.setState({
coderCount:result.data
})
}
}).catch(error=>{console.log(error);})
}
2020-03-16 14:12:11 +08:00
render(){
return(
2020-05-20 18:11:32 +08:00
<div>
2020-07-03 16:32:47 +08:00
<Top {...this.props} {...this.state}/>
2020-03-16 14:12:11 +08:00
<Switch {...this.props}>
2020-07-03 16:32:47 +08:00
{/* 新建文件 */}
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId/coders/:branch/newfile/:path"
2020-07-03 16:32:47 +08:00
render={
(props) => (<FileNew {...this.props} {...props} {...this.state} />)
}
></Route>
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId/coders/:branch/uploadfile"
2020-07-03 16:32:47 +08:00
render={
(props) => (<UploadFile {...this.props} {...props} {...this.state} />)
}
></Route>
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId/coders/:branch/newfile"
2020-07-03 16:32:47 +08:00
render={
2020-07-03 17:26:07 +08:00
(props) => (<FileNew {...this.props} {...props} {...this.state} getTopCount={this.getTopCount} />)
2020-07-03 16:32:47 +08:00
}
></Route>
2020-08-13 15:44:02 +08:00
<Route path="/projects/:owner/:projectsId/coders/commits"
2020-03-16 14:12:11 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootCommit {...this.props} {...this.state} commit_class="main" getTopCount={this.getTopCount} />)
2020-03-16 14:12:11 +08:00
}
></Route>
2020-05-29 17:00:42 +08:00
{/* diff */}
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId/diff/:sha"
2020-05-29 17:00:42 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<Diff {...this.props} {...this.state}/>)
2020-05-29 17:00:42 +08:00
}
></Route>
2020-08-13 15:44:02 +08:00
<Route path="/projects/:owner/:projectsId/coders/releases/new"
2020-05-20 18:11:32 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootVersionNew {...this.props} {...this.state} />)
2020-05-20 18:11:32 +08:00
}
></Route>
2020-08-13 15:44:02 +08:00
<Route path="/projects/:owner/:projectsId/coders/releases/:versionId/update"
2020-05-20 18:11:32 +08:00
render={
2020-08-13 11:42:44 +08:00
(props) => (<CoderRootVersionUpdate {...this.props} {...this.state} {...props} />)
2020-05-20 18:11:32 +08:00
}
></Route>
2020-08-13 15:44:02 +08:00
<Route path="/projects/:owner/:projectsId/coders/releases"
2020-05-20 18:11:32 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootVersion {...this.props} {...this.state} />)
2020-05-20 18:11:32 +08:00
}
></Route>
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId/coders/tag"
2020-05-20 18:11:32 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootTag {...this.props} {...this.state} />)
2020-05-20 18:11:32 +08:00
}
></Route>
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId/coders/branch"
2020-03-16 14:12:11 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootBranch {...this.props} {...this.state} />)
2020-03-16 14:12:11 +08:00
}
></Route>
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId/coders"
2020-03-16 14:12:11 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootDirectory {...this.props} {...this.state} getTopCount={this.getTopCount} />)
2020-03-16 14:12:11 +08:00
}
></Route>
2020-08-12 18:13:18 +08:00
<Route path="/projects/:owner/:projectsId"
2020-03-16 14:12:11 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootDirectory {...this.props} {...this.state} getTopCount={this.getTopCount} />)
2020-03-16 14:12:11 +08:00
}
></Route>
</Switch>
</div>
)
}
}
export default CoderRootIndex;