From d059223f89682ddfa5523507fad454af69a1f218 Mon Sep 17 00:00:00 2001 From: caicai8 <1149225589@qq.com> Date: Thu, 9 Jan 2020 19:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- public/react/src/forge/Index.js | 19 ++- .../src/forge/Main/CoderRootDirectory.js | 116 +++++++++++++++++- .../src/forge/Main/CoderRootFileDetail.js | 112 +++++------------ public/react/src/forge/Main/CoderRootIndex.js | 6 - 5 files changed, 155 insertions(+), 100 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9461e180f..eb318fb83 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -328,7 +328,7 @@ class ApplicationController < ActionController::Base def current_user # User.current - User.find_by_id 36401 + User.find_by_id 50207 end ## 默认输出json diff --git a/public/react/src/forge/Index.js b/public/react/src/forge/Index.js index 3f48c287f..eee358fbe 100644 --- a/public/react/src/forge/Index.js +++ b/public/react/src/forge/Index.js @@ -12,6 +12,7 @@ import './css/index.css'; import Loadable from 'react-loadable'; import Loading from '../Loading'; +import axios from 'axios'; const ProjectNew = Loadable({ loader: () => import('./New/Index'), @@ -35,13 +36,19 @@ class Index extends Component{ } } componentDidMount=()=>{ - let current_user={ - user_id:50207, - login:'caicc' - } + this.getUserInfo(); + } - this.setState({ - current_user + getUserInfo=()=>{ + const url = `/users/me.json`; + axios.get(url).then(result=>{ + if(result && result.data.login){ + this.setState({ + current_user:result.data + }) + } + }).catch(error=>{ + console.log(error) }) } render(){ diff --git a/public/react/src/forge/Main/CoderRootDirectory.js b/public/react/src/forge/Main/CoderRootDirectory.js index 3f65b20eb..ea9a589da 100644 --- a/public/react/src/forge/Main/CoderRootDirectory.js +++ b/public/react/src/forge/Main/CoderRootDirectory.js @@ -8,6 +8,7 @@ import './list.css'; import SelectBranch from '../Branch/SelectBranch'; import CloneAddress from '../Branch/CloneAddress'; import RootTable from './RootTable'; +import CoderRootFileDetail from './CoderRootFileDetail'; import axios from 'axios'; class CoderRootDirectory extends Component{ @@ -16,9 +17,11 @@ class CoderRootDirectory extends Component{ this.state={ address:"http", branch:"master", + filePath:[], http_url:undefined, branchList:undefined, + fileDetail:undefined, branchLastCommit:undefined } } @@ -32,7 +35,7 @@ class CoderRootDirectory extends Component{ this.getProjectRoot(); } - // 获取分支文件 + // 获取根目录 getProjectRoot=(branch)=>{ const { login } = this.props.current_user; const { projectsId } = this.props.match.params; @@ -44,11 +47,76 @@ class CoderRootDirectory extends Component{ } }).then((result)=>{ if(result && result.data && result.data.length > 0){ + this.setState({ + filePath:[], + fileDetail:undefined + }) this.renderData(result.data) } }).catch((error)=>{}) } + ChangeFile=(arr)=>{ + this.renderUrl(arr); + this.getFileDetail(arr); + } + + renderUrl=(array)=>{ + if(array && array.path){ + let { path } = array; + let list = []; + let urlList=Object.assign({},array); + let str = ""; + if(path.indexOf("/")>0){ + const wraps = path.split("/"); + wraps.map((item,key)=>{ + str += '/'+item; + urlList.path = str.substr(1); + urlList.name = item; + list.push({...urlList}); + }) + }else{ + urlList.path = ''; + urlList.name = path; + list.push({...urlList}); + } + this.setState({ + filePath:list + }) + } + } + + // 获取子目录 + getFileDetail=(arr)=>{ + const { current_user } = this.props; + const { projectsId } = this.props.match.params; + const { branch } = this.state; + const url =`/${current_user.login}/${projectsId}/sub_entries.json`; + + axios.get(url,{ + params:{ + filepath:arr.path, + ref:branch + } + }).then((result)=>{ + if(result && result.data && result.data.length > 0){ + if(arr.type==="file"){ + this.setState({ + fileDetail:result.data[0], + rootList:undefined + }) + }else{ + this.setState({ + fileDetail:undefined + }) + this.renderData(result.data) + } + } + }).catch((error)=>{ + console.log(error); + }) + } + renderData=(data)=>{ const rootList = []; data && data.map((item,key)=>{ @@ -74,7 +142,7 @@ class CoderRootDirectory extends Component{ }) } render(){ - const { rootList , branch } = this.state; + const { rootList , branch ,filePath , fileDetail } = this.state; const { branchLastCommit , http_url } = this.props; const { projectsId } = this.props.match.params; @@ -84,7 +152,7 @@ class CoderRootDirectory extends Component{ dataIndex: 'name', width:"100%", render: (text,item) => ( - + this.ChangeFile(item)}> {text} ), @@ -111,6 +179,7 @@ class CoderRootDirectory extends Component{ return undefined; } } + const downloadUrl = ()=>{ if(branchLastCommit && branchLastCommit.zip_url){ return( @@ -124,10 +193,45 @@ class CoderRootDirectory extends Component{ return(