文件修改接口

dev_forge
caicai8 5 years ago
parent ba8244006a
commit fb1fe1e2a7

@ -18,7 +18,6 @@ import axios from 'axios';
* filePath:点击目录时当前目录的路径
* subfileType:保存当前点击目录的文件类型显示目录列表时才显示新建文件如果点击的是文件就不显示新建文件按钮
* readMeContent:根目录下面的readme文件内容
* current_path:当前文件路径
*/
class CoderRootDirectory extends Component{
constructor(props){
@ -30,7 +29,6 @@ class CoderRootDirectory extends Component{
http_url:undefined,
subFileType:"",
readMeContent:undefined,
current_path:undefined,
branchList:undefined,
fileDetail:undefined,
@ -72,8 +70,7 @@ class CoderRootDirectory extends Component{
this.renderUrl(arr.name,arr.path,arr.type);
this.getFileDetail(arr);
this.setState({
subFileType:arr.type,
current_path:arr.path
subFileType:arr.type
})
}
@ -189,7 +186,7 @@ class CoderRootDirectory extends Component{
})
}
render(){
const { rootList , branch ,filePath , fileDetail , subFileType , readMeContent , current_path } = this.state;
const { rootList , branch ,filePath , fileDetail , subFileType , readMeContent } = this.state;
const { branchLastCommit , http_url , isManager , isDeveloper } = this.props;
const { projectsId } = this.props.match.params;
@ -287,7 +284,7 @@ class CoderRootDirectory extends Component{
{
fileDetail &&
<CoderRootFileDetail detail = {fileDetail} current_path={current_path} {...this.props} {...this.state}></CoderRootFileDetail>
<CoderRootFileDetail detail = {fileDetail} {...this.props} {...this.state}></CoderRootFileDetail>
}
{/* readme.txt */}

@ -17,10 +17,19 @@ class CoderRootFileDetail extends Component{
constructor(props){
super(props);
this.state={
readOnly:true
readOnly:true,
value:undefined
}
}
componentDidMount=()=>{
const { detail } = this.props;
this.setState({
value:detail.content
})
}
EditFile=()=>{
this.setState({
readOnly:false
@ -32,19 +41,52 @@ class CoderRootFileDetail extends Component{
})
}
// 编辑文件
changeContent=(e)=>{
this.setState({
value:e
})
}
deleteFile=()=>{
const { current_path , current_user , branch}= this.props;
const { current_user , branch , detail }= this.props;
const { projectsId } = this.props.match.params;
const url = `/api/${current_user.login}/${projectsId}/contents/files/delete.json`;
const url = `/${current_user.login}/${projectsId}/contents/files/delete.json`;
axios.delete(url,{
params:{
filepath:current_path,
filepath:detail.path,
branch
}
}).then(result=>{
if(result){
this.props.showNotification("删除成功!");
this.props.history.push(`/projects/${projectsId}`);
}
}).catch(error=>{
console.log(error);
})
}
// 确认修改文件
UpdateFile=()=>{
const { current_user , branch , detail}= this.props;
const { projectsId } = this.props.match.params;
const { value } = this.state;
const url =`/${current_user.login}/${projectsId}/contents/files/update.json`;
axios.put(url,{
filepath:detail.path,
branch,
content:value,
sha:detail.sha,
}).then(result=>{
if(result){
this.props.showNotification("修改成功!");
this.setState({
readOnly:true
})
}
}).catch(error=>{
console.log(error);
@ -53,8 +95,7 @@ class CoderRootFileDetail extends Component{
render(){
const { detail } = this.props;
const { readOnly } = this.state;
const { readOnly ,value } = this.state;
return(
<div className="branchTable">
<p className="branchTitle f-wrap-alignCenter f-wrap-between">
@ -66,7 +107,7 @@ class CoderRootFileDetail extends Component{
:
<React.Fragment>
<button type="button" class="ant-btn ant-btn-sm mr10" onClick={this.CancelEdit}><span> </span></button>
<button type="button" class="ant-btn ant-btn-primary ant-btn-sm"><span> </span></button>
<button type="button" class="ant-btn ant-btn-primary ant-btn-sm" onClick={this.UpdateFile}><span> </span></button>
</React.Fragment>
}
@ -78,7 +119,8 @@ class CoderRootFileDetail extends Component{
<Editor
height="300px"
theme={"vs-dark"}
value={detail && detail.content}
value={value}
onChange={this.changeContent}
readOnly={readOnly}
/>
</div>

Loading…
Cancel
Save