2020-05-27 17:07:36 +08:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import { Popconfirm, Select } from "antd";
|
|
|
|
|
import "./list.css";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import Meditor from "../Newfile/m_editor";
|
2020-03-27 18:29:00 +08:00
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
function bytesToSize(bytes) {
|
2020-05-27 17:07:36 +08:00
|
|
|
if (bytes === 0) return "0 B";
|
2020-03-16 14:12:11 +08:00
|
|
|
let k = 1024,
|
2020-05-27 17:07:36 +08:00
|
|
|
sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
|
|
|
|
|
i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
|
|
|
return (bytes / Math.pow(k, i)).toFixed(2) + " " + sizes[i];
|
2020-03-16 14:12:11 +08:00
|
|
|
}
|
2020-05-27 17:07:36 +08:00
|
|
|
class CoderRootFileDetail extends Component {
|
|
|
|
|
constructor(props) {
|
2020-03-16 14:12:11 +08:00
|
|
|
super(props);
|
2020-05-27 17:07:36 +08:00
|
|
|
this.state = {
|
|
|
|
|
readOnly: true,
|
|
|
|
|
value: undefined,
|
|
|
|
|
language: undefined,
|
|
|
|
|
};
|
2020-03-16 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
2020-05-27 17:07:36 +08:00
|
|
|
componentDidMount = () => {
|
2020-04-13 17:45:36 +08:00
|
|
|
const { detail, readOnly } = this.props;
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
|
|
|
this.setState({
|
2020-04-13 17:45:36 +08:00
|
|
|
value: detail.content,
|
2020-05-27 17:07:36 +08:00
|
|
|
readOnly: readOnly,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
select_language = (e) => {
|
|
|
|
|
console.log(e);
|
2020-03-16 14:12:11 +08:00
|
|
|
this.setState({
|
2020-05-27 17:07:36 +08:00
|
|
|
language: e,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
EditFile = () => {
|
2020-03-16 14:12:11 +08:00
|
|
|
this.setState({
|
2020-05-27 17:07:36 +08:00
|
|
|
readOnly: false,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
CancelEdit = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
readOnly: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
|
|
|
// 编辑文件
|
2020-03-29 18:16:58 +08:00
|
|
|
|
2020-05-27 17:07:36 +08:00
|
|
|
changeMmirror = (e, e1, value) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
this.setState({
|
2020-05-27 17:07:36 +08:00
|
|
|
value,
|
|
|
|
|
});
|
|
|
|
|
};
|
2020-03-16 14:12:11 +08:00
|
|
|
|
2020-05-27 17:07:36 +08:00
|
|
|
deleteFile = () => {
|
|
|
|
|
const { branch, detail } = this.props;
|
2020-03-16 14:12:11 +08:00
|
|
|
const { projectsId } = this.props.match.params;
|
|
|
|
|
|
2020-05-27 17:07:36 +08:00
|
|
|
const url = `/repositories/${projectsId}/delete_file.json`;
|
|
|
|
|
axios
|
|
|
|
|
.delete(url, {
|
|
|
|
|
params: {
|
|
|
|
|
filepath: detail.path,
|
|
|
|
|
branch,
|
|
|
|
|
sha: detail.sha,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then((result) => {
|
|
|
|
|
if (result) {
|
|
|
|
|
this.props.showNotification("删除成功!");
|
|
|
|
|
this.props.history.push(`/projects/${projectsId}`);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
});
|
|
|
|
|
};
|
2020-03-16 14:12:11 +08:00
|
|
|
|
2020-05-26 18:50:17 +08:00
|
|
|
// // 确认修改文件
|
|
|
|
|
// UpdateFile=()=>{
|
|
|
|
|
// const { branch , detail}= this.props;
|
|
|
|
|
// const { projectsId } = this.props.match.params;
|
|
|
|
|
// const { value } = this.state;
|
|
|
|
|
// const url =`/repositories/${projectsId}/update_file.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);
|
|
|
|
|
// })
|
|
|
|
|
// }
|
2020-05-27 17:07:36 +08:00
|
|
|
updateCode = (value) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
value,
|
|
|
|
|
});
|
|
|
|
|
};
|
2020-03-16 14:12:11 +08:00
|
|
|
|
2020-05-27 17:07:36 +08:00
|
|
|
render() {
|
|
|
|
|
const { detail, current_user, isManager, isDeveloper } = this.props;
|
|
|
|
|
const { readOnly, language } = this.state;
|
2020-03-30 15:06:30 +08:00
|
|
|
let flag = current_user && current_user.login && (isManager || isDeveloper);
|
2020-05-27 17:07:36 +08:00
|
|
|
const Option = Select.Option;
|
|
|
|
|
const languages = [
|
|
|
|
|
"apex",
|
|
|
|
|
"azcli",
|
|
|
|
|
"bat",
|
|
|
|
|
"clojure",
|
|
|
|
|
"coffee",
|
|
|
|
|
"cpp",
|
|
|
|
|
"csharp",
|
|
|
|
|
"csp",
|
|
|
|
|
"css",
|
|
|
|
|
"dockerfile",
|
|
|
|
|
"fsharp",
|
|
|
|
|
"go",
|
|
|
|
|
"handlebars",
|
|
|
|
|
"html",
|
|
|
|
|
"ini",
|
|
|
|
|
"java",
|
|
|
|
|
"javascript",
|
|
|
|
|
"json",
|
|
|
|
|
"less",
|
|
|
|
|
"lua",
|
|
|
|
|
"markdown",
|
|
|
|
|
"msdax",
|
|
|
|
|
"mysql",
|
|
|
|
|
"objective",
|
|
|
|
|
"perl",
|
|
|
|
|
"pgsql",
|
|
|
|
|
"php",
|
|
|
|
|
"postiats",
|
|
|
|
|
"powerquery",
|
|
|
|
|
"powershell",
|
|
|
|
|
"pug",
|
|
|
|
|
"python",
|
|
|
|
|
"r",
|
|
|
|
|
"razor",
|
|
|
|
|
"redis",
|
|
|
|
|
"redshift",
|
|
|
|
|
"ruby",
|
|
|
|
|
"rust",
|
|
|
|
|
"sb",
|
|
|
|
|
"scheme",
|
|
|
|
|
"scss",
|
|
|
|
|
"shell",
|
|
|
|
|
"solidity",
|
|
|
|
|
"sql",
|
|
|
|
|
"st",
|
|
|
|
|
"swift",
|
|
|
|
|
"typescript",
|
|
|
|
|
"vb",
|
|
|
|
|
"xml",
|
|
|
|
|
"yaml",
|
|
|
|
|
];
|
|
|
|
|
return (
|
2020-05-26 18:50:17 +08:00
|
|
|
<div className="mb20">
|
2020-05-27 17:07:36 +08:00
|
|
|
<div className="grid-item branchTitle">
|
|
|
|
|
<div className="grid-item">
|
|
|
|
|
<span className="ml20 color-grey-6 font-16">{bytesToSize(detail && detail.size)}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-right">
|
|
|
|
|
{flag && (
|
|
|
|
|
<div>
|
|
|
|
|
{readOnly ? (
|
|
|
|
|
<a onClick={this.EditFile} className="ml20">
|
|
|
|
|
<i className="iconfont icon-bianji1 font-15 color-grey-6"></i>
|
|
|
|
|
</a>
|
|
|
|
|
) : (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<Select
|
|
|
|
|
showSearch={true}
|
|
|
|
|
placeholder={"请选择文本语言"}
|
|
|
|
|
style={{ width: 200 }}
|
|
|
|
|
value={language}
|
|
|
|
|
onChange={this.select_language}
|
|
|
|
|
>
|
|
|
|
|
<Option value={undefined}>请选择文本语言</Option>
|
|
|
|
|
{languages.map((item, key) => {
|
|
|
|
|
return <Option value={item}>{item}</Option>;
|
|
|
|
|
})}
|
|
|
|
|
</Select>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="ant-btn ant-btn-sm ml20"
|
|
|
|
|
onClick={this.CancelEdit}
|
|
|
|
|
>
|
|
|
|
|
<span>取 消</span>
|
|
|
|
|
</button>
|
|
|
|
|
{/* <button type="button" className="ant-btn ant-btn-primary ant-btn-sm" onClick={this.UpdateFile}><span>确 定</span>
|
2020-05-26 18:50:17 +08:00
|
|
|
</button> */}
|
2020-05-27 17:07:36 +08:00
|
|
|
</React.Fragment>
|
|
|
|
|
)}
|
2020-03-25 15:14:20 +08:00
|
|
|
|
2020-05-27 17:07:36 +08:00
|
|
|
<Popconfirm
|
|
|
|
|
title="确认删除这个文件?"
|
|
|
|
|
className="ml20"
|
|
|
|
|
okText="确定"
|
|
|
|
|
cancelText="取消"
|
|
|
|
|
onConfirm={this.deleteFile}
|
|
|
|
|
>
|
|
|
|
|
<a>
|
|
|
|
|
<i className="iconfont icon-shanchu font-15 color-grey-6"></i>
|
|
|
|
|
</a>
|
2020-03-25 15:14:20 +08:00
|
|
|
</Popconfirm>
|
2020-05-27 17:07:36 +08:00
|
|
|
</div>
|
|
|
|
|
)}
|
2020-03-16 14:12:11 +08:00
|
|
|
</p>
|
|
|
|
|
</div>
|
2020-05-26 18:50:17 +08:00
|
|
|
<div>
|
2020-05-27 17:07:36 +08:00
|
|
|
{detail.direct_download ? (
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
<a href={detail.download_url} className="color-blue font-15">
|
|
|
|
|
下载原始文件
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<Meditor
|
|
|
|
|
{...this.props}
|
|
|
|
|
{...this.state}
|
|
|
|
|
language={language ? language : "javascript"}
|
|
|
|
|
filepath={`/${detail.path}`}
|
|
|
|
|
content={detail.content}
|
|
|
|
|
readOnly={readOnly}
|
|
|
|
|
editorType="update"
|
|
|
|
|
></Meditor>
|
|
|
|
|
)}
|
2020-03-16 14:12:11 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-05-27 17:07:36 +08:00
|
|
|
);
|
2020-03-16 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 18:16:58 +08:00
|
|
|
export default CoderRootFileDetail;
|