diff --git a/src/forge/Main/CoderRootFileDetail.js b/src/forge/Main/CoderRootFileDetail.js index c296e703..9523246c 100644 --- a/src/forge/Main/CoderRootFileDetail.js +++ b/src/forge/Main/CoderRootFileDetail.js @@ -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 (
- {bytesToSize(detail && detail.size)} + + {bytesToSize(detail && detail.size)} +

{flag && (

{readOnly ? ( - this.EditFile(false)} className="ml20"> + this.EditFile(false)} className="ml20"> ) : ( @@ -160,14 +183,14 @@ class CoderRootFileDetail extends Component { onChange={this.select_language} > - {languages.map((item, key) => { - return ; + {languages && languages.map((item, key) => { + return ; })} @@ -187,20 +210,25 @@ class CoderRootFileDetail extends Component {
)} - { - detail.image_type && detail.direct_download ? + {detail.image_type && detail.direct_download ? (
下载原始文件 -
:"" - } +
+ ) : ( + "" + )}

{detail.image_type && detail.direct_download ? (
- +
) : ( { - 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 { 提交变更 -
-
-
- - {getFieldDecorator("path", { - rules: [], - })( - // -
- -
- )} -
- - {getFieldDecorator("desc", { - rules: [ - { - required: true, - message: "请添加描述信息", - }, - ], - })( -