|
|
|
@ -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>
|
|
|
|
|