Merge branch 'newVersion_forge' of http://gitea.trustie.net/jasder/forgeplus-react into newVersion_forge

This commit is contained in:
caishi 2020-06-24 18:14:28 +08:00
commit af5c671fcb
3 changed files with 218 additions and 172 deletions

View File

@ -1,5 +1,5 @@
import React, { Component } from "react";
import { Popconfirm, Select } from "antd";
import { Popconfirm, Select } from "antd";
import "./list.css";
import axios from "axios";
import Meditor from "../Newfile/m_editor";
@ -16,17 +16,85 @@ class CoderRootFileDetail extends Component {
super(props);
this.state = {
value: undefined,
language: undefined
language: undefined,
languages: undefined,
};
}
componentDidMount = () => {
const { detail } = this.props;
this.setState({
value: detail.content,
});
this.languages_total();
};
languages_total = () => {
const { detail } = this.props;
const file_name = detail.path.split("/").pop().split(".").pop();
let languages = [];
let default_language = "javascript";
let all_languages = {
apex: ["apex", "apxc"],
azcli: ["azcli"],
bat: ["bat"],
clojure: ["clj"],
coffee: ["coffee"],
cpp: ["cpp"],
csharp: ["cs"],
csp: ["csp"],
css: ["css"],
dockerfile: ["dockerfile", "docker", "yml"],
fsharp: ["fs"],
go: ["go"],
html: ["html", "htm", "erb"],
ini: ["ini"],
java: ["java", "class"],
javascript: ["js"],
json: ["json"],
less: ["less"],
lua: ["lua"],
markdown: ["markdown", "md", "rmd"],
msdax: ["dax"],
mysql: ["sql"],
objective: ["m", "mm", "o", "out"],
perl: ["perl"],
pgsql: ["sql"],
php: ["php"],
postiats: ["postiats"],
powerquery: [""],
powershell: ["ps1"],
pug: ["pug"],
python: ["py"],
r: ["r"],
razor: ["cshtml"],
redis: ["rdb"],
ruby: ["rb"],
rust: ["rs"],
sb: ["sb"],
scheme: ["scm", "ss"],
scss: ["scss"],
shell: ["sh"],
solidity: ["sol"],
sql: ["sql"],
st: ["st"],
swift: ["swift"],
typescript: ["ts"],
vb: ["vbp", "frm", "frx", "bas", "cls"],
xml: ["xml"],
yaml: ["yml"],
};
for (var item in all_languages) {
languages.push(item);
let item_values = all_languages[item];
if (item_values.indexOf(file_name) !== -1) {
default_language = item;
}
}
this.state.languages = languages;
this.state.language = default_language;
};
select_language = (e) => {
this.setState({
language: e,
@ -39,7 +107,6 @@ class CoderRootFileDetail extends Component {
// readOnly: false,
// });
};
// 编辑文件
@ -73,7 +140,6 @@ class CoderRootFileDetail extends Component {
});
};
updateCode = (value) => {
this.setState({
value,
@ -81,73 +147,30 @@ class CoderRootFileDetail extends Component {
};
render() {
const { readOnly , detail, current_user, isManager, isDeveloper } = this.props;
const { language } = this.state;
const {
readOnly,
detail,
current_user,
isManager,
isDeveloper,
} = this.props;
const { language, languages } = this.state;
let flag = current_user && current_user.login && (isManager || isDeveloper);
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 (
<div className="mb20">
<div className="grid-item branchTitle">
<div className="grid-item">
<span className="ml20 color-grey-6 font-16">{bytesToSize(detail && detail.size)}</span>
<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(false)} className="ml20">
<a onClick={() => this.EditFile(false)} className="ml20">
<i className="iconfont icon-bianji1 font-15 color-grey-6"></i>
</a>
) : (
@ -160,14 +183,19 @@ class CoderRootFileDetail extends Component {
onChange={this.select_language}
>
<Option value={undefined}>请选择文本语言</Option>
{languages.map((item, key) => {
return <Option value={item}>{item}</Option>;
})}
{languages &&
languages.map((item, key) => {
return (
<Option value={item} key={key}>
{item}
</Option>
);
})}
</Select>
<button
type="button"
className="ant-btn ant-btn-sm ml20"
onClick={()=>this.EditFile(true)}
onClick={() => this.EditFile(true)}
>
<span> </span>
</button>
@ -187,20 +215,22 @@ class CoderRootFileDetail extends Component {
</Popconfirm>
</div>
)}
{
detail.image_type && detail.direct_download ?
<div className="ml20">
<a href={detail.download_url} className="color-blue font-15">
下载原始文件
</a>
</div>:""
}
</p>
</div>
<div>
{detail.image_type && detail.direct_download ? (
{detail.image_type ? (
<div className="edu-txt-center pt20 pb20">
<img alt="" src={detail.download_url} style={{maxWidth:"80%"}}/>
<img
alt=""
src={detail.download_url}
style={{ maxWidth: "80%" }}
/>
</div>
) : detail.direct_download ? (
<div className="mt20 text-center">
<a href={detail.download_url} className="color-blue font-15">
下载原始文件
</a>
</div>
) : (
<Meditor

View File

@ -12,7 +12,7 @@ class UserSubmitComponent extends Component {
this.state = {
submitType: "0",
filename: "",
isSpin: false
isSpin: false,
};
}
@ -22,19 +22,19 @@ class UserSubmitComponent extends Component {
});
};
// 命名文件
changeFileName = (e) => {
this.setState({
filename: e.target.value,
});
};
// 命名文件
changeFileName = (e) => {
this.setState({
filename: e.target.value,
});
};
// 提交变更
subMitFrom = () => {
const { filepath, content,editor_type } = this.props;
const { filepath, content, editor_type } = this.props;
const { branch, projectsId } = this.props.match.params;
const { submitType, filename } = this.state;
this.setState({isSpin: true})
this.setState({ isSpin: true });
let path = editor_type === "upload" ? filepath : filepath.substr(1);
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
@ -48,28 +48,28 @@ class UserSubmitComponent extends Component {
message: values.desc,
})
.then((result) => {
this.setState({isSpin: false})
this.setState({ isSpin: false });
if (result.data && result.data.name) {
let url = values.branchname
? `/projects/${projectsId}/coders?branch=${values.branchname}`
: `/projects/${projectsId}/coders`;
? `/projects/${projectsId}/coders?branch=${values.branchname}`
: `/projects/${projectsId}/coders`;
this.props.history.push(url);
this.props.showNotification("文件新建成功!");
}
})
.catch((error) => {
this.setState({isSpin: false})
this.setState({ isSpin: false });
console.log(error);
});
}else{
this.setState({isSpin: false})
} else {
this.setState({ isSpin: false });
}
});
};
// 确认修改文件
UpdateFile = () => {
this.setState({isSpin: true})
this.setState({ isSpin: true });
const { branch, detail, content, filepath } = this.props;
const { projectsId } = this.props.match.params;
const { submitType } = this.state;
@ -86,28 +86,28 @@ class UserSubmitComponent extends Component {
message: values.desc,
})
.then((result) => {
this.setState({isSpin: false})
this.setState({ isSpin: false });
if (result.data && result.data.status === 1) {
let url = values.branchname
? `/projects/${projectsId}/coders?branch=${values.branchname}`
: `/projects/${projectsId}/coders`;
this.props.history.push(url);
this.props.showNotification("修改成功!");
}
})
.catch((error) => {
this.setState({isSpin: false})
this.setState({ isSpin: false });
console.log(error);
});
}else{
this.setState({isSpin: false})
} else {
this.setState({ isSpin: false });
}
});
};
render() {
const { submitType,filename, isSpin } = this.state;
const { submitType, filename, isSpin } = this.state;
const { getFieldDecorator } = this.props.form;
const { branch, projectsId } = this.props.match.params;
@ -160,81 +160,89 @@ class UserSubmitComponent extends Component {
<span className="color-grey-8">提交变更</span>
</span>
<Spin spinning={isSpin}>
<div className="userScrew">
<div className="screwPanel">
<Form>
<Form.Item style={{display: editor_type === "upload" ? "block" : "none"}}>
{getFieldDecorator("path", {
rules: [],
})(
// <Input
// placeholder={`/${
// projectDetail && projectDetail.identifier
// }${filepath}`}
// readOnly
// />
<div className="setInputAddon">
<Input
addonBefore={`/${
projectDetail && projectDetail.identifier
}/`}
value={filename ? filename: filepath}
onChange={this.changeFileName}
placeholder="文件路径..."
/>
</div>
)}
</Form.Item>
<Form.Item>
{getFieldDecorator("desc", {
rules: [
{
required: true,
message: "请添加描述信息",
},
],
})(
<TextArea
placeholder={`必填,描述主要修改类型和内容`}
authSize={{ minRows: 3, maxRows: 5 }}
/>
)}
</Form.Item>
<Radio.Group value={submitType} onChange={this.changeSubmittype}>
<Radio value="0" className="mb10">
<i className="iconfont icon-banbenku font-16 mr5"></i>
直接提交至<span className="color-orange">{branch}</span>
</Radio>
<Radio value="1">
<Icon type="pull-request" className="mr5" />
为此提交创建一个<span className="font-bd">新的分支</span>
并发起合并请求
</Radio>
</Radio.Group>
{changeSubmitBranch()}
</Form>
<div className="userScrew">
<div className="screwPanel">
<Form>
<Form.Item
style={{
display: editor_type === "upload" ? "block" : "none",
}}
>
{getFieldDecorator("path", {
rules: [],
})(
// <Input
// placeholder={`/${
// projectDetail && projectDetail.identifier
// }${filepath}`}
// readOnly
// />
<div className="setInputAddon">
<Input
addonBefore={`/${
projectDetail && projectDetail.identifier
}/`}
value={filename ? filename : filepath}
onChange={this.changeFileName}
placeholder="文件路径..."
/>
</div>
)}
</Form.Item>
<Form.Item>
{getFieldDecorator("desc", {
rules: [
{
required: true,
message: "请添加描述信息",
},
],
})(
<TextArea
placeholder={`必填,描述主要修改类型和内容`}
authSize={{ minRows: 3, maxRows: 5 }}
/>
)}
</Form.Item>
<Radio.Group
value={submitType}
onChange={this.changeSubmittype}
>
<Radio value="0" className="mb10">
<i className="iconfont icon-banbenku font-16 mr5"></i>
直接提交至<span className="color-orange">{branch}</span>
</Radio>
<Radio value="1">
<Icon type="pull-request" className="mr5" />
为此提交创建一个<span className="font-bd">新的分支</span>
并发起合并请求
</Radio>
</Radio.Group>
{changeSubmitBranch()}
</Form>
</div>
</div>
<div className="mt20">
<Button
type="primary"
onClick={
editor_type === "update" ? this.UpdateFile : this.subMitFrom
}
className="mr30"
>
提交变更
</Button>
<Button
type="primary grey"
onClick={() => {
this.props.history.push(`/projects/${projectsId}/coders`);
}}
className="mr20"
>
取消
</Button>
</div>
</div>
<div className="mt20">
<Button
type="primary"
onClick={editor_type === "update" ? this.UpdateFile : this.subMitFrom}
className="mr30"
>
提交变更
</Button>
<Button
type="primary grey"
onClick={() => {
this.props.history.push(`/projects/${projectsId}/coders`);
}}
className="mr20"
>
取消
</Button>
</div>
</Spin>
</div>
);
}

View File

@ -209,7 +209,7 @@ class Infos extends Component {
</li>
<li className={project_type && project_type === "common" ? "active" : ""} onClick={() => this.change_project_type("common")}>
<p>
<span className="font-16">托管项目</span>
<span className="font-16">开源托管项目</span>
<span className="color-blue">
{user && user.common_projects_count}
</span>
@ -217,12 +217,20 @@ class Infos extends Component {
</li>
<li className={project_type && project_type === "mirror" ? "active" : ""} onClick={() => this.change_project_type("mirror")}>
<p>
<span className="font-16">镜像项目</span>
<span className="font-16">开源镜像项目</span>
<span className="color-blue">
{user && user.mirror_projects_count}
</span>
</p>
</li>
<li className={project_type && project_type === "sync_mirror" ? "active" : ""} onClick={() => this.change_project_type("sync_mirror")}>
<p>
<span className="font-16">镜像托管项目</span>
<span className="color-blue">
{user && user.sync_mirror_projects_count}
</span>
</p>
</li>
</ul>
</div>
{/* <div className="bgcF">