branch router

This commit is contained in:
caishi 2020-11-24 10:46:27 +08:00
parent 8cc13f77e1
commit 5827e96a53
15 changed files with 117 additions and 81 deletions

View File

@ -27,7 +27,7 @@ if (isDev) {
}
debugType = window.location.search.indexOf('debug=t') !== -1 ? 'teacher' :
window.location.search.indexOf('debug=s') !== -1 ? 'student' :
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'student'
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'admin'
}
function clearAllCookie() {
cookie.remove('_educoder_session', { path: '/' });

View File

@ -4,7 +4,7 @@ import './branch.css';
import { getBranch , getTag } from '../GetData/getData';
export default (({ projectsId , repo_id , changeBranch , branch , owner })=>{
export default (({ projectsId , branch , owner , history , changeBranch })=>{
const [ showValue , setShowValue ] = useState(branch);
const [ inputValue , setInputValue] = useState(undefined);
const [ nav , setNav ] = useState(0);
@ -17,6 +17,7 @@ export default (({ projectsId , repo_id , changeBranch , branch , owner })=>{
useEffect(()=>{
setShowValue(branch);
},[branch])
useEffect(()=>{
document.body.addEventListener('click', e => {
let name = e.target.className;
@ -63,7 +64,7 @@ export default (({ projectsId , repo_id , changeBranch , branch , owner })=>{
}
}
function chooseitem(value){
setShowValue(value);
// setShowValue(value);
changeBranch(value);
}

View File

@ -32,7 +32,7 @@ export default ((props)=>{
return(
<li key={key}>
<div>
<Link to={`/projects/${owner}/${projectsId}?branch=${item.name}`} className="color-blue font-15" style={{"maxWidth":"100px"}}>{item.name}</Link>
<Link to={`/projects/${owner}/${projectsId}/branch/${item.name}`} className="color-blue font-15" style={{"maxWidth":"100px"}}>{item.name}</Link>
<p className="f-wrap-alignCenter mt15">
<Link to={`/projects/${owner}/${projectsId}/commits/${truncateCommitId(`${item.last_commit.sha}`)}`} className="mr5 commitKey" style={{marginLeft:0}}>{item.last_commit && truncateCommitId(item.last_commit.sha)}</Link>
<span className="color-grey-3 hide-1 messages leftPoint">{item.last_commit && item.last_commit.message}</span>

View File

@ -12,7 +12,6 @@ class CoderRootCommit extends Component{
constructor(props){
super(props)
this.state={
branch:"master",
commitDatas:undefined,
dataCount:undefined,
limit:20,
@ -22,11 +21,23 @@ class CoderRootCommit extends Component{
}
componentDidMount=()=>{
const { branch , page , limit } = this.state;
this.Init();
}
componentDidUpdate=(prevProps)=>{
const { location } = this.props;
const prevlocation = prevProps && prevProps.location;
if (location !== prevlocation) {
this.Init();
}
}
Init =()=>{
const { branchName } = this.props.match.params;
const { page , limit } = this.state;
this.setState({
isSpining:true
})
this.getCommitList( branch , page , limit );
this.getCommitList( branchName , page , limit );
}
getCommitList=(branch , page , limit)=>{
@ -68,26 +79,28 @@ class CoderRootCommit extends Component{
// 切换分支 search:tag为根据标签搜索
changeBranch=(value)=>{
const { page , limit } = this.state;
const { getTopCount } = this.props;
this.setState({
isSpining:true,
branch:value,
})
this.getCommitList(value , page , limit);
getTopCount && getTopCount(value);
// const { page , limit } = this.state;
// const { getTopCount } = this.props;
// this.setState({
// isSpining:true,
// branch:value,
// })
// this.getCommitList(value , page , limit);
// getTopCount && getTopCount(value);
const { projectsId , owner } = this.props.match.params;
this.props.history.push(`/projects/${owner}/${projectsId}/commits/branch/${value}`);
}
ChangePage=(page)=>{
const { branch , limit } = this.state;
this.getCommitList(branch , page , limit);
const { branchName } = this.props.match.params;
const { limit } = this.state;
this.getCommitList(branchName , page , limit);
}
render(){
const { branch , commitDatas , dataCount , limit , page , isSpining } = this.state;
const { branchs , projectDetail, commit_class } = this.props;
const { projectsId , owner } = this.props.match.params;
const { commitDatas , dataCount , limit , page , isSpining } = this.state;
const { projectDetail, commit_class } = this.props;
const { projectsId , owner , branchName } = this.props.match.params;
let branch = branchName || "master";
return(
<React.Fragment>
<div className={commit_class}>
@ -98,6 +111,7 @@ class CoderRootCommit extends Component{
branch={branch}
changeBranch={this.changeBranch}
owner={owner}
history={this.props.history}
></SelectBranch>
</div>
<Spin spinning={isSpining}>

View File

@ -34,7 +34,7 @@ class CoderRootDirectory extends Component {
super(props);
this.state = {
address: "http",
branch: "master",
branch: props.match.params.branchName || "master",
filePath: undefined,
subFileType: undefined,
readMeContent: undefined,
@ -79,31 +79,16 @@ class CoderRootDirectory extends Component {
Init = () => {
let { search } = this.props.history.location;
let branchName = undefined;
if (search && (search.indexOf("?branch=") > -1 || search.indexOf("&branch=") > -1)) {
branchName = search.split("branch=")[1];
if(branchName && branchName.indexOf("&")){
branchName=branchName.split("&")[0];
}
this.setState({
branch: branchName,
});
}else{
branchName = undefined;
this.setState({
branch: "master",
});
}
const { branchName } = this.props.match.params;
let branch = branchName || "master";
if (search && (search.indexOf("?url=") > -1 || search.indexOf("&url=") > -1)) {
let url = search.split("url=")[1];
if(url && decodeURI(url).indexOf("&")){
url=decodeURI(url).split("&")[0];
}
this.getFileDetail(decodeURI(url),branchName);
this.getFileDetail(decodeURI(url),branch);
} else {
const { branch } = this.state;
this.getProjectRoot(branchName || branch);
this.getProjectRoot(branch);
}
};
@ -194,13 +179,13 @@ class CoderRootDirectory extends Component {
this.setState({
filePath: decodeURI(path),
});
const { projectsId ,owner } = this.props.match.params;
const { branch , chooseType } = this.state;
const { projectsId , owner , branchName } = this.props.match.params;
const { chooseType } = this.state;
const url = `/${owner}/${projectsId}/sub_entries.json`;
axios.get(url,{
params:{
filepath:path,
ref:ref || branch,
ref:ref || branchName,
type:chooseType
}
}).then((result)=>{
@ -325,24 +310,27 @@ class CoderRootDirectory extends Component {
// 选择分支
changeBranch = (value) => {
this.setState({
branch: value,
isSpin: true,
readOnly:true
});
const { getTopCount } = this.props;
getTopCount && getTopCount(value);
// this.setState({
// branch: value,
// isSpin: true,
// readOnly:true
// });
// const { getTopCount } = this.props;
// getTopCount && getTopCount(value);
// let { search } = this.props.history.location;
// if (search && search.indexOf("?url=") > -1) {
// let url = search.split("?url=")[1];
// this.setState({
// filePath: decodeURI(url),
// });
// this.getFileDetail(decodeURI(url), value);
// } else {
// this.getProjectRoot(value);
// }
const { projectsId , owner } = this.props.match.params;
this.props.history.push(`/projects/${owner}/${projectsId}/branch/${value}`);
let { search } = this.props.history.location;
if (search && search.indexOf("?url=") > -1) {
let url = search.split("?url=")[1];
this.setState({
filePath: decodeURI(url),
});
this.getFileDetail(decodeURI(url), value);
} else {
this.getProjectRoot(value);
}
}
// 子目录路径返回链接
@ -421,10 +409,11 @@ class CoderRootDirectory extends Component {
}
render(){
const { branchLastCommit , lastCommitAuthor , rootList , branch ,filePath , fileDetail , subFileType , readMeContent, isSpin , zip_url , tar_url} = this.state;
const { branchLastCommit , lastCommitAuthor , rootList ,filePath , fileDetail , subFileType , readMeContent, isSpin , zip_url , tar_url} = this.state;
const { isManager , isDeveloper , projectDetail , platform } = this.props;
const { projectsId , owner } = this.props.match.params;
const { projectsId , owner , branchName } = this.props.match.params;
let branch = branchName || "master";
const columns = [
{
dataIndex: 'name',
@ -473,6 +462,7 @@ class CoderRootDirectory extends Component {
branch={branch}
changeBranch={this.changeBranch}
owner={owner}
history={this.props.history}
></SelectBranch>
:
<span>分支<span className="color-grey-6">master</span></span>

View File

@ -55,12 +55,19 @@ class CoderRootIndex extends Component{
}
componentDidMount=()=>{
let { search } = this.props.history.location;
let branchName = undefined;
if (search && search.indexOf("?branch=") > -1) {
branchName = search.split("?branch=")[1];
this.Init();
}
componentDidUpdate=(prevProps)=>{
const { location } = this.props;
const prevlocation = prevProps && prevProps.location;
if (location !== prevlocation) {
this.Init();
}
this.getTopCount(branchName);
}
Init=()=>{
const { branchName } = this.props.match.params;
this.getTopCount(branchName || "master");
}
getTopCount=(branch)=>{
@ -99,6 +106,11 @@ class CoderRootIndex extends Component{
></Route>
{/* diff */}
<Route path="/projects/:owner/:projectsId/commits/branch/:branchName"
render={
(props) => (<CoderRootCommit {...this.props} {...props} {...this.state} commit_class="main" getTopCount={this.getTopCount} />)
}
></Route>
<Route path="/projects/:owner/:projectsId/commits/:sha"
render={
(props) => (<Diff {...this.props} {...props} {...this.state}/>)
@ -132,7 +144,12 @@ class CoderRootIndex extends Component{
() => (<CoderRootTag {...this.props} {...this.state} />)
}
></Route>
<Route path="/projects/:owner/:projectsId/branch"
<Route path="/projects/:owner/:projectsId/branch/:branchName"
render={
(props) => (<CoderRootDirectory {...this.props} {...this.state} getTopCount={this.getTopCount} />)
}
></Route>
<Route path="/projects/:owner/:projectsId/branchs"
render={
() => (<CoderRootBranch {...this.props} {...this.state} />)
}

View File

@ -708,6 +708,16 @@ class Detail extends Component {
(props) => (<ForkUsers {...this.props} {...props} {...this.state} {...common} />)
}
></Route>
<Route path="/projects/:owner/:projectsId/commits/branch/:branchName"
render={
(props) => (<CoderRootIndex {...this.props} {...props} {...this.state} {...common} />)
}
></Route>
<Route path="/projects/:owner/:projectsId/branch/:branchName"
render={
(props) => (<CoderRootIndex {...this.props} {...props} {...this.state} {...common} />)
}
></Route>
<Route path="/projects/:owner/:projectsId"
render={
(props) => (<CoderRootIndex {...this.props} {...props} {...this.state} {...common} />)

View File

@ -16,7 +16,7 @@ class DetailTop extends Component {
<i className="iconfont icon-tijiaojilu font-20 mr3 font-bd"></i>
<span>{(coderCount && coderCount.commits_count) || 0}</span>
</Link>
<Link to={`/projects/${owner}/${projectsId}/branch`} className={pathname.indexOf("/branch") > 0 ? "active" : ""}>
<Link to={`/projects/${owner}/${projectsId}/branchs`} className={pathname.indexOf("/branchs") > 0 ? "active" : ""}>
<i className="iconfont icon-fenzhi1 font-18 mr3"></i>
<span>{(coderCount && coderCount.branches_count) || 0}</span>
</Link>

View File

@ -59,7 +59,7 @@ export default ({ match , history }) => {
{commit && commit.message &&
<pre className="task-hide" style={{marginBottom:"0px",height:"28px",whiteSpace:"pre-wrap"}}>{commit.message}</pre>
}
<Button type="primary" onClick={()=>{history.push(`/projects/${owner}/${projectsId}?branch=${truncateCommitId(sha)}`)}} className="ml30">浏览代码</Button>
<Button type="primary" onClick={()=>{history.push(`/projects/${owner}/${projectsId}/branch/${truncateCommitId(sha)}`)}} className="ml30">浏览代码</Button>
</div>
</div>
<div className="f-wrap-between" style={{ alignItems: "center" }}>

View File

@ -47,7 +47,7 @@ function Files({data,history,owner,projectsId}){
<span>{item.name}</span>
</AlignCenter>
<span>
<Button className="mr20" onClick={()=>{history.push(`/projects/${owner}/${projectsId}?${item.sha ? `branch=${truncateCommitId(item.sha)}&`:""}url=${item.name}`)}}>查看文件</Button>
<Button className="mr20" onClick={()=>{history.push(`/projects/${owner}/${projectsId}${item.sha ? `/branch/${truncateCommitId(item.sha)}?`:"?"}url=${item.name}`)}}>查看文件</Button>
<span className="color-green">+{item.addition}</span>
<span className="color-red ml20">-{item.deletion}</span>
</span>

View File

@ -98,7 +98,7 @@ class MergeItem extends Component {
<span className="ml15">
<Tag className="pr-branch-tag">
<Link
to={`/projects/${item.is_original ? item.fork_project_user : owner}/${ item.is_original ? item.fork_project_identifier : projectsId }?branch=${item.pull_request_head}`}
to={`/projects/${item.is_original ? item.fork_project_user : owner}/${ item.is_original ? item.fork_project_identifier : projectsId }/branch/${item.pull_request_head}`}
className="maxW200px hide-1 ver-middle"
>
{item.is_original
@ -116,7 +116,7 @@ class MergeItem extends Component {
</span>
<Tag className="pr-branch-tag">
<Link
to={`/projects/${owner}/${projectsId}?branch=${item.pull_request_base}`}
to={`/projects/${owner}/${projectsId}/branch/${item.pull_request_base}`}
className="maxW200px hide-1 ver-middle"
>
{/* {item.is_fork ? item.pull_request_base : `${item.author_name}:${item.pull_request_base}`} */}

View File

@ -300,7 +300,7 @@ class MessageCount extends Component {
<div className="mt15">
<Tag className="pr-branch-tag">
<Link
to={`/projects/${owner}/${data.pull_request.is_original?data.pull_request.fork_project_id:projectsId}?branch=${data.pull_request.head}`}
to={`/projects/${owner}/${data.pull_request.is_original?data.pull_request.fork_project_id:projectsId}/branch/${data.pull_request.head}`}
className="ver-middle"
>
{data.pull_request.is_original ? data.pull_request.fork_project_user : data.issue.project_author_name}:{data.pull_request.head}
@ -315,7 +315,7 @@ class MessageCount extends Component {
</span>
<Tag className="pr-branch-tag">
<Link
to={`/projects/${owner}/${projectsId}?branch=${data.pull_request.base}`}
to={`/projects/${owner}/${projectsId}/branch/${data.pull_request.base}`}
className="ver-middle"
>
{/* {data.pull_request.is_fork ? data.pull_request.base : `${data.pull_request.pull_request_user}:${data.pull_request.base}`} */}

View File

@ -55,7 +55,7 @@ class UserSubmitComponent extends Component {
getTopCount && getTopCount(values.branchname);
}
let url = values.branchname
? `/projects/${owner}/${projectsId}?branch=${values.branchname}`
? `/projects/${owner}/${projectsId}/branch/${values.branchname}`
: `/projects/${owner}/${projectsId}`;
this.props.history.push(url);
}
@ -92,7 +92,7 @@ class UserSubmitComponent extends Component {
this.setState({ isSpin: false });
if (result.data && result.data.status === 1) {
let url = values.branchname
? `/projects/${owner}/${projectsId}?branch=${values.branchname}`
? `/projects/${owner}/${projectsId}/branch/${values.branchname}`
: `/projects/${owner}/${projectsId}`;
this.props.history.push(url);

View File

@ -16,6 +16,9 @@ export default ((props)=>{
function resetSetting(){
}
function settingRule(){
props.history.push(`/projects/${owner}/${projectsId}/setting/branch/new`);
}
return(
<WhiteBack>
@ -31,6 +34,7 @@ export default ((props)=>{
projectsId={projectsId}
changeBranch={setBranch}
owner={owner}
history={props.history}
/>
<a className="color-blue ml20" onClick={resetSetting()}>设为默认分支</a>
</AlignCenter>
@ -38,7 +42,7 @@ export default ((props)=>{
<div>
<FlexAJ className="pt20">
<span className="color-grey-3">保护分支规则</span>
<Blueline>+&nbsp;新建规则</Blueline>
<Blueline onClick={()=>settingRule()}>+&nbsp;新建规则</Blueline>
</FlexAJ>
<NumUl>
<li>限制分支的推送合并强制推送相关请去<GreenUnder>仓库设置</GreenUnder></li>

View File

@ -71,7 +71,7 @@ class Index extends Component {
}
>
<p>
<Link to={`/projects/${projectsId}/setting/branch`} className="w-100">
<Link to={`/projects/${owner}/${projectsId}/setting/branch`} className="w-100">
<i className="iconfont icon-fenzhi font-20 mr10"></i>
分支设置
</Link>