diff --git a/src/forge/Component/FileName/index.jsx b/src/forge/Component/FileName/index.jsx index 1933cf91d..b22caec5b 100644 --- a/src/forge/Component/FileName/index.jsx +++ b/src/forge/Component/FileName/index.jsx @@ -3,7 +3,7 @@ import { Input } from 'antd'; import './index.scss'; function FileName({ -onChangeFile,addonBefore , name , empty , onEmpty +onChangeFile,addonBefore , name , empty , onEmpty , readOnly }){ const [ defaultUrl , setDefaultUrl ] = useState(undefined); const [ newUrl , setNewUrl ] = useState([]); @@ -115,6 +115,7 @@ onChangeFile,addonBefore , name , empty , onEmpty onKeyUp={keyUpFun} onChange={changeValue} style={{width:"220px",borderColor:empty===true ? "red":"grey"}} + disabled={readOnly} /> {empty &&

请输入文件名称

} diff --git a/src/forge/Component/licenseModal/dorpChooseMenus.jsx b/src/forge/Component/licenseModal/dorpChooseMenus.jsx new file mode 100644 index 000000000..5217d0540 --- /dev/null +++ b/src/forge/Component/licenseModal/dorpChooseMenus.jsx @@ -0,0 +1,54 @@ +import React,{useEffect,useState,useRef} from 'react'; +import { Input } from 'antd'; +import Drop from '../../Issues/Component/drop'; +import "./index.scss"; +import ListItem from './list'; + +/*** + * list:下拉内容列表 + * name:所用内容名字,新建页面:.gitignore、许可证、类别、语言,项目基本设置:类别、语言 + * value:选中id + * getValue:点击确定 + * idname:下拉内容定位的父元素 + */ +function DorpChooseMenus({list,name,value,getValue,idname}){ + const dropRef = useRef(null); + const [ choose , setChoose ] = useState(undefined); + const [ defaultValue , setDefaultValue ] = useState(undefined); + + useEffect(()=>{ + if(value){ + setChoose({name:value}); + setDefaultValue(value) + } + },value) + + const panel=()=>{ + return( +
+ + 确定 +
+ ) + } + function chooseFunc(value){ + setChoose(value); + } + + function sureFunc(){ + getValue(choose); + dropRef.current && dropRef.current.clearVisible(false); + } + return( + + + + ) +} +export default DorpChooseMenus; \ No newline at end of file diff --git a/src/forge/Component/licenseModal/img/license.png b/src/forge/Component/licenseModal/img/license.png new file mode 100644 index 000000000..d66dc80ad Binary files /dev/null and b/src/forge/Component/licenseModal/img/license.png differ diff --git a/src/forge/Component/licenseModal/img/search.png b/src/forge/Component/licenseModal/img/search.png new file mode 100644 index 000000000..9687212e6 Binary files /dev/null and b/src/forge/Component/licenseModal/img/search.png differ diff --git a/src/forge/Component/licenseModal/index.jsx b/src/forge/Component/licenseModal/index.jsx new file mode 100644 index 000000000..0c2440d2e --- /dev/null +++ b/src/forge/Component/licenseModal/index.jsx @@ -0,0 +1,57 @@ +import { Modal } from "antd"; +import React, { useEffect, useState } from "react"; +import LicenseImg from './img/license.png'; +import "./index.scss"; +import axios from 'axios'; +import ListItem from './list'; + +function Index({visible,onCancel,createDefaultLicense}){ + const [ list , setList ] = useState(undefined); + const [ choose , setChoose ] = useState(undefined); + useEffect(()=>{ + visible && getLicenses(); + },[visible]) + + + const getLicenses = () => { + const url = `/licenses.json`; + axios.get(url).then((result) => { + if (result) { + setList(result.data.licenses); + } + }).catch((error) => { }) + } + + function chooseFunc(value){ + setChoose(value); + } + + + return( + +
+
+

了解开源许可证

+
+ +
+

开源许可证是您软件源代码使用、修改及分发的法律约定,明确了他人使用项目的权利与限制,常见的有MIT、Apache 2.0、GPL等。

+

请从推荐列表中选择适合的协议,或根据高级项目需求自定义创建您的许可证。

+ createDefaultLicense(-1)}>创建自定义许可证 +
+ +
+ + createDefaultLicense(choose && choose.id)}>使用该许可证 +
+
+
+ ) +} +export default Index \ No newline at end of file diff --git a/src/forge/Component/licenseModal/index.scss b/src/forge/Component/licenseModal/index.scss new file mode 100644 index 000000000..ee2180f94 --- /dev/null +++ b/src/forge/Component/licenseModal/index.scss @@ -0,0 +1,126 @@ +.licenseBox{ + display: flex; + .licenseDesc{ + background: #FBFCFF; + border-radius: 11px 11px 11px 11px; + border: 1px solid rgba(70,106,255,0.33); + width: 38%; + padding:20px; + margin-right: 20px; + .licImg{ + background: #F7F9FF; + border-radius: 0px 0px 0px 0px; + border: 1px dashed rgba(70,106,255,0.3); + padding:24px 30px; + text-align: center; + margin-top: 20px; + img{ + height: 122px; + } + } + .licWord{ + color: #4C4D5A; + line-height: 26px; + } + .licCreate{ + display: block; + height: 36px; + line-height: 36px; + background: #F7F9FF; + border-radius: 7px 7px 7px 7px; + border: 1px solid #466AFF; + color: #466AFF; + text-align: center; + margin-top: 25px; + } + } +} + +.licenseData{ + flex: 1; +} +.licList{ + margin-top: 20px; + height: 394px; + overflow-y: auto; + clear: both; + width: 100%; + li{ + height: 36px; + line-height: 36px; + background: rgba(126,135,172,0.08); + border-radius: 4px 4px 4px 4px; + width: 48.5%; + margin-right: 3%; + text-align: center; + margin-bottom: 15px!important; + float: left; + cursor: pointer; + &:nth-child(2n){ + margin-right: 0px; + } + &.active{ + color: #fff; + background-color: #466AFF; + } + } + &.small{ + height: 200px; + li{ + width: 22.5%; + &:nth-child(2n){ + margin-right: 3%; + } + &:nth-child(4n){ + margin-right: 0px; + } + } + .none_panels{ + padding:0px; + min-height: 200px; + } + } +} +.licUse{ + display: block; + height: 36px; + line-height: 36px; + border-radius: 4px 4px 4px 4px; + font-size: 15px; + color: #fff!important; + text-align: center; + margin-top: 38px; + background-color: #c0c0c0; + cursor: default; + &.active{ + background: #466AFF; + cursor: pointer; + } +} +.dropspan{ + display: block; +} + +.alllists{ + background-color: #fff; + box-shadow: 2px 4px 15px rgba(0, 0, 0, 0.1); + padding:20px!important; + width: 80%; +} +.sureDrop{ + width: 200px; + height: 36px; + background: #c0c0c0; + border-radius: 4px; + line-height: 36px; + color: #fff!important; + display: block; + text-align: center; + font-size: 15px; + margin:20px auto 0px; + cursor: default; + &.active{ + background: #466AFF; + cursor: pointer; + } +} \ No newline at end of file diff --git a/src/forge/Component/licenseModal/list.jsx b/src/forge/Component/licenseModal/list.jsx new file mode 100644 index 000000000..e2469c5b8 --- /dev/null +++ b/src/forge/Component/licenseModal/list.jsx @@ -0,0 +1,52 @@ + +import React, { useEffect, useState } from "react"; +import Search from './img/search.png'; +import Nodata from "../../Nodata"; +import { Input } from 'antd'; +import "./index.scss"; + +/** + * + * @param {list} param1 列表 + * @param {onChooseFunc} param2 选中后调用父级方法 + * @param {size} param3 一行显示4个,默认显示2个 + * @param {defaultValue} param4 默认选中的---name + * @returns + */ +function List({list,onChooseFunc,size,defaultValue}){ + const [ value , setValue ] = useState(undefined); + const [ active , setActive ] = useState(undefined); + const [ copylist , setCopyList ] = useState(undefined); + + + useEffect(()=>{ + if(list && list.length>0){ + setCopyList(list); + if(defaultValue){ + let getMIT = list.filter(i=>i.name === defaultValue); + getMIT && getMIT.length > 0 && setActive(getMIT[0].id); + } + } + },[list && list.length,defaultValue]) + + + function searchFunc(search){ + let filters = list && list.filter(i=>i.name.toLowerCase().indexOf(search.toLowerCase()) > -1); + setCopyList(filters); + } + return( + + } value={value} onChange={(e)=>{setValue(e.target.value);searchFunc(e.target.value)}}/> + + + ) +} +export default List; \ No newline at end of file diff --git a/src/forge/Issues/Component/drop.jsx b/src/forge/Issues/Component/drop.jsx index f90a19d69..8bfc7e85e 100644 --- a/src/forge/Issues/Component/drop.jsx +++ b/src/forge/Issues/Component/drop.jsx @@ -1,8 +1,9 @@ import React,{useState, useEffect, useRef, useImperativeHandle,forwardRef} from 'react'; import { Dropdown } from 'antd'; import { findDOMNode } from 'react-dom'; +import "../index.scss"; -function Drop({overlay , children , placement, overlayClassName},ref){ +function Drop({overlay , children , placement, overlayClassName,idname},ref){ const [ visible , setVisible ] = useState(false); const refFa = useRef(null); const refBox = useRef(null); @@ -35,6 +36,7 @@ function Drop({overlay , children , placement, overlayClassName},ref){ placement={placement} visible={visible} overlay={
{overlay}
} + getPopupContainer={(trigger) => idname ? document.getElementById(idname) :trigger.parentNode} trigger={['click']} overlayClassName={overlayClassName} > diff --git a/src/forge/Main/CoderDepot.jsx b/src/forge/Main/CoderDepot.jsx index a394fead7..76c693f6d 100644 --- a/src/forge/Main/CoderDepot.jsx +++ b/src/forge/Main/CoderDepot.jsx @@ -5,7 +5,7 @@ import { Link } from 'react-router-dom'; import { connect } from 'react-redux'; import { truncateCommitId } from "../common/util"; import CloneAddress from '../Branch/CloneAddress'; - +import CheckProfile from '../Component/ProfileModal/Profile'; import SelectBranch from '../Branch/Select'; import User from '../Component/User'; import axios from 'axios'; @@ -21,12 +21,12 @@ import DrawerPanel from '../Component/DrawerPanel'; import UpdateDescModal from './sub/UpdateDescModal'; import Nodata from '../Nodata'; import Invite from './sub/Invite'; -import CheckProfile from '../Component/ProfileModal/Profile'; import RenderHtml from '../../components/render-html'; import Loadable from 'react-loadable'; import Loading from '../../Loading'; import ProjectPortrait from '../Component/projectPortrait'; import imNoneImg from './img/importNone.png'; +import LicenseModal from '../Component/licenseModal/index'; import moment from 'moment'; const ProjectCompass = Loadable({ @@ -77,6 +77,7 @@ function CoderDepot(props){ const [ pullsFlag , setPullsFlag ] = useState(true); const [ issuesFlag , setIssuesFlag ] = useState(true); const [ releaseVersions , setReleaseVersions] = useState(undefined); + const [ licenseVisible ,setLicenseVisible] = useState(false); const owner = props.match.params.owner; const projectsId = props.match.params.projectsId; @@ -308,6 +309,7 @@ function CoderDepot(props){ ) } + function getPathUrl(array,index){ if(array && array.length>0 && index){ let str = ""; @@ -404,6 +406,16 @@ function CoderDepot(props){ props.showLoginDialog(`/${owner}/${projectsId}/issues/new`); } } + // 创建自定义许可证 + function createDefaultLicense(id){ + if(props.checkIfLogin()===false){ + props.showLoginDialog() + return false; + } + let b = branchName || defaultBranch; + let checkvalue = turnbar(b); + props.history.push({pathname:`/${owner}/${projectsId}/${checkvalue}/newfile${treeValue === undefined ? "" : `/${treeValue}`}`,state:`${id}`}) + } // 如果项目是fork的项目,pr自动指向源仓库,否则指向本仓库默认分支 function compare() { @@ -423,6 +435,7 @@ function CoderDepot(props){ return(
{mirror_status ===0 && setOpenModal(false)} onOk={okUpdate}/> } + {setLicenseVisible(false)}} createDefaultLicense={createDefaultLicense}/> { ((dirInfo || fileInfo) && mirror_status===0 ) && @@ -663,10 +676,15 @@ function CoderDepot(props){ {projectDetail && projectDetail.size}
{ - projectDetail && projectDetail.license_name && -
+ projectDetail && projectDetail.license_id !== 0 && +
- {projectDetail.license_name} + { + projectDetail.license_name ? + {projectDetail.license_name} + : + 暂无数据,点击{setLicenseVisible(true)}}>选择并创建许可证 + }
}
diff --git a/src/forge/New/Index.js b/src/forge/New/Index.js index 392eb4c7c..b1898ffc1 100644 --- a/src/forge/New/Index.js +++ b/src/forge/New/Index.js @@ -3,6 +3,7 @@ import { Input , Form , Select , Checkbox , Button , Spin , AutoComplete, Modal import { Base64 } from 'js-base64'; import { AlignCenter } from '../Component/layout'; import { withTranslation } from 'react-i18next'; +import DorpChooseMenus from '../Component/licenseModal/dorpChooseMenus'; import '../css/index.scss'; import './new.scss' @@ -76,6 +77,8 @@ class Index extends Component { this.getOwner(); //判断是否为删除新建项目失败后返回,并执行对应逻辑 this.isDeleteProjectBack(); + // 获取开源许可证 + this.getLicenses(); } componentDidUpdate=(prevPros)=>{ this.updateDocumentTitle(); @@ -123,7 +126,7 @@ class Index extends Component { const url = `/project_categories.json` axios.get(url).then((result) => { if (result) { - this.setOptionsList(result.data.project_categories, 'project_category'); + // this.setOptionsList(result.data.project_categories, 'project_category'); this.setState({ CategoryList: result.data.project_categories }) @@ -135,7 +138,7 @@ class Index extends Component { const url = `/project_languages.json` axios.get(url).then((result) => { if (result) { - this.setOptionsList(result.data.project_languages, 'project_language') + // this.setOptionsList(result.data.project_languages, 'project_language') this.setState({ LanguageList: result.data.project_languages }) @@ -147,7 +150,7 @@ class Index extends Component { const url = `/ignores.json` axios.get(url).then((result) => { if (result) { - this.setOptionsList(result.data.ignores, 'ignore'); + // this.setOptionsList(result.data.ignores, 'ignore'); this.setState({ GitignoreList: result.data.ignores }) @@ -159,14 +162,13 @@ class Index extends Component { const url = `/licenses.json` axios.get(url).then((result) => { if (result) { - this.setOptionsList(result.data.licenses, 'license'); + let data = result.data.licenses; this.setState({ - LicensesList: result.data.licenses + LicensesList: data }) } }).catch((error) => { }) } - isDeleteProjectBack = () => { let mirror_status = this.props.history.location.mirror_status; if (mirror_status === 2 && sessionStorage.newProjectValue) { @@ -264,28 +266,6 @@ class Index extends Component { }) } - ChangePlatform = (value, e, name, list) => { - this.setOptionsList(list, name, value) - this.setState({ - [name + "_id"]: e.key, - [name + "_name"]: value, - }) - } - - blurCategory = (value, list, name) => { - let filter = list && list.filter(item => item.name === value); - if (!filter || filter.length === 0) { - this.props.form.setFieldsValue({ - [name]: undefined - }) - this.setState({ - [name + "_name"]: undefined, - [name + "_id"]: undefined - }) - this.setOptionsList(list, name); - } - } - checkId = (rule, value, callback, list, title) => { let filter = list.filter(item => item.name === value); if(!value){ @@ -358,14 +338,6 @@ class Index extends Component { this.getGitignore(); } } - showLicenseFunc =(e)=>{ - const { LicensesList } = this.state; - this.setState({licenseFlag:e.target.checked}) - if(e.target.checked && (!LicensesList || (LicensesList && LicensesList.length===0))){ - // 获取开源许可证 - this.getLicenses(); - } - } blurFunc=(rule, value, callback)=>{ @@ -430,6 +402,24 @@ class Index extends Component { } } + showLicenseFunc =(e)=>{ + const { LicensesList } = this.state; + this.setState({ + licenseFlag:e.target.checked + }) + } + + getValue=(values,typeName)=>{ + const {id,name} = values + if(id){ + this.setState({ + [typeName + "_id"]: id + }) + this.props.form.setFieldsValue({ + [`${typeName}`]:name + }) + } + } render() { const { getFieldDecorator } = this.props.form; // 项目类型:deposit-托管项目,mirror-镜像项目 @@ -465,7 +455,7 @@ class Index extends Component { } = this.state; return (
-
+
{projectsType && projectsType === "mirror" ? "导入" : "新建"}项目
@@ -655,14 +645,7 @@ class Index extends Component { validator: (rule, value, callback) => this.checkId(rule, value, callback, GitignoreList, 'gitignore') }], })( - this.ChangePlatform(value, e, 'ignore', GitignoreList)} - className="plateAutoComplete" - onBlur={(value) => this.blurCategory(value, GitignoreList, "ignore")} - > - {ignore_list} - + this.getValue(value,"ignore")}/> )} } @@ -674,7 +657,7 @@ class Index extends Component { )} { licenseFlag && - + {getFieldDecorator('license', { rules: [{ required: licenseFlag, message: '请选择开源许可证' @@ -682,14 +665,7 @@ class Index extends Component { validator: (rule, value, callback) => this.checkId(rule, value, callback, LicensesList, '开源许可证') }], })( - this.ChangePlatform(value, e, 'license', LicensesList)} - className="plateAutoComplete" - onBlur={(value) => this.blurCategory(value, LicensesList, "license")} - > - {license_list} - + this.getValue(value,"license")}/> )} } @@ -721,9 +697,7 @@ class Index extends Component { )} {categoreFlag && - + {getFieldDecorator('project_category', { rules: [{ required: categoreFlag, message: '请选择项目类别', @@ -731,20 +705,11 @@ class Index extends Component { validator: (rule, value, callback) => this.checkId(rule, value, callback, CategoryList, '项目类别') }], })( - this.ChangePlatform(value, e, 'project_category', CategoryList)} - className="plateAutoComplete" - onBlur={(value) => this.blurCategory(value, CategoryList, "project_category")} - > - {project_category_list} - + this.getValue(value,"project_category")}/> )} } - + {getFieldDecorator('languageFlag')( this.showLanguageFunc(e)}>项目语言 )} @@ -758,14 +723,7 @@ class Index extends Component { validator: (rule, value, callback) => this.checkId(rule, value, callback, LanguageList, '项目语言') }], })( - this.ChangePlatform(value, e, 'project_language', LanguageList)} - className="plateAutoComplete" - onBlur={(value) => this.blurCategory(value, LanguageList, "project_language")} - > - {project_language_list} - + this.getValue(value,"project_language")}/> )} } diff --git a/src/forge/New/new.scss b/src/forge/New/new.scss index 8432cecdf..161c1f18f 100644 --- a/src/forge/New/new.scss +++ b/src/forge/New/new.scss @@ -1,6 +1,7 @@ .newPanel{ border:1px solid #eaeaea; border-radius: 4px; + position: relative; } .newPanel_title{ height: 3rem; diff --git a/src/forge/Newfile/Index.js b/src/forge/Newfile/Index.js index 7239e75e5..1ba60d42c 100644 --- a/src/forge/Newfile/Index.js +++ b/src/forge/Newfile/Index.js @@ -2,18 +2,25 @@ import React, { useEffect , useState } from "react"; import Meditor from "./m_editor"; import "./index.css"; import { returnbar } from 'educoder'; +import { Select } from "antd"; import FileLanguage from '../Component/FileLanguage'; import FP from '../Component/FileName/index'; +import axios from 'axios'; +const { Option } = Select; function Index(props){ const [ filename , setFileName ] = useState(""); const [ language , setLanguage ] = useState(""); const [ checkName , setCheckName ] = useState(false); + const [ licenseList ,setLicenseList ] = useState([]) + const [ licenseId ,setLicenseId ] = useState([]) + const [ content ,setContent ] = useState(""); + const [ chooseName ,setChooseName ] = useState(""); const [ empty , setEmpty ] = useState(false); const {projectDetail} = props; - const { pathname } = props && props.location; + const { pathname , state } = props && props.location; const urlroot = pathname.split("newfile/")[1]; const file_path = urlroot ? `/${urlroot}/` :"/"; @@ -21,6 +28,55 @@ function Index(props){ updateDocumentTitle(); },[projectDetail]) + + useEffect(()=>{ + if(state){ + getLicenseList(); + setLicenseId(parseInt(state)) + if(parseInt(state) !== -1){ + getLinceseById(state); + } + } + },[state]) + + useEffect(()=>{ + if(licenseList && licenseList.length>0 && licenseId){ + let filters = licenseList.filter(i=>i.id === licenseId); + let name = filters && filters.length === 1 ? filters[0].name : -1 + setChooseName(name); + } + },[licenseId,licenseList.splice()]) + + // 根据license id查询详情 + const getLinceseById=(id)=>{ + let url =`/licenses/${id}.json`; + axios.get(url).then(res=>{ + if(res && res.data){ + setContent(res.data.content) + } + }).catch(error=>{}) + } + // 获取license列表 + const getLicenseList=()=>{ + let url =`/licenses.json`; + axios.get(url).then(res=>{ + if(res && res.data){ + setLicenseList(res.data.licenses) + } + }).catch(error=>{}) + } + // 选择许可证 + const selectFunc=(e,item)=>{ + const { key } = item; + setLicenseId(parseInt(key)); + props.history.push({state:key}) + if(key && parseInt(key) !== -1){ + getLinceseById(key); + }else{ + setContent(undefined) + } + } + // 更新网页标题 function updateDocumentTitle(){ @@ -57,11 +113,34 @@ function Index(props){ addonBefore={`${ projectDetail && projectDetail.identifier }${returnbar(file_path)}`} onChangeFile={onChangeFile} empty={empty} + name={(Boolean(state) ? "LICENSE" :"")} onEmpty={(e)=>setEmpty(e)} + readOnly={Boolean(state)} />
- + { + (licenseList && licenseList.length>0 && state) ? + + : + + }
@@ -69,13 +148,14 @@ function Index(props){ {...props} filepath={`${file_path}`} language = {language} - content={""} + content={content} readOnly={false} editor_type="new" descName={filename ? `Add ${filename}`:""} checkName={checkName} onEmpty={(e)=>setEmpty(e)} empty={empty} + state={state} filename={filename} >
diff --git a/src/forge/Newfile/UserSubmitComponent.js b/src/forge/Newfile/UserSubmitComponent.js index 808679ac1..c10e5de5b 100644 --- a/src/forge/Newfile/UserSubmitComponent.js +++ b/src/forge/Newfile/UserSubmitComponent.js @@ -69,7 +69,7 @@ class UserSubmitComponent extends Component { // 提交变更 subMitFrom = () => { - const { filepath, content, editor_type , checkName , onEmpty , checkContent} = this.props; + const { filepath, content, editor_type , checkName , onEmpty , checkContent , state , projectDetail} = this.props; const { branch, projectsId , owner } = this.props.match.params; const { submitType, filename , empty } = this.state; if(editor_type==="upload" && checkContent && !content){ @@ -99,13 +99,25 @@ class UserSubmitComponent extends Component { this.setState({ isSpin: false }); if (result.data && result.data.name) { this.props.showNotification("文件新建成功!"); + const { getDetail } = this.props; if(submitType === "1"){ - const { getDetail } = this.props; getDetail && getDetail(); } - window.scrollTo(0,0); - let url = `/${owner}/${projectsId}${values.branchname ? `/tree/${turnbar(values.branchname)}`: (branch ? `/tree/${turnbar(branch)}` : "")}`; - this.props.history.push(url); + // 存在state是代表创建自定义许可证 + if(state){ + const url = `/${owner}/${projectsId}.json`; + const { name , identifier } = projectDetail; + axios.put(url,{name,identifier,license_id:parseInt(state)===-1?0:state }).then(res=>{ + getDetail && getDetail(); + window.scrollTo(0,0); + let url = `/${owner}/${projectsId}${values.branchname ? `/tree/${turnbar(values.branchname)}`: (branch ? `/tree/${turnbar(branch)}` : "")}`; + this.props.history.push(url); + }).catch(error=>{}) + }else{ + window.scrollTo(0,0); + let url = `/${owner}/${projectsId}${values.branchname ? `/tree/${turnbar(values.branchname)}`: (branch ? `/tree/${turnbar(branch)}` : "")}`; + this.props.history.push(url); + } } }) .catch((error) => { diff --git a/src/forge/Newfile/m_editor.js b/src/forge/Newfile/m_editor.js index f0450b63c..e9e7b154b 100644 --- a/src/forge/Newfile/m_editor.js +++ b/src/forge/Newfile/m_editor.js @@ -6,7 +6,6 @@ import 'codemirror/mode/clike/clike'; import 'codemirror/mode/css/css'; import UserSubmitComponent from "./UserSubmitComponent"; import CloudIDE from "./cloudIDE"; -import { Base64 } from "js-base64"; import "./index.css"; import "./editor.css"; @@ -35,7 +34,7 @@ class m_editor extends Component { render() { const { editorValue, changeValue } = this.state; - const { readOnly, editorType,onEmpty,filename,empty, currentBranch, descName, checkName, detail, match: { params },filepath, ideTheme , md } = this.props; + const { readOnly, editorType,onEmpty,filename,empty, currentBranch, descName, checkName, detail, match: { params },filepath, state , projectDetail} = this.props; const editor_options = { lineNumbers: "on", lineWrapping: true, //强制换行 @@ -87,6 +86,8 @@ class m_editor extends Component { empty={empty} filename={filename} changeValueFlag={this.props.content !== changeValue} + state={state} + projectDetail={projectDetail} >
)} diff --git a/src/forge/Settings/Setting.js b/src/forge/Settings/Setting.js index be7eebe8f..59c05d0f5 100644 --- a/src/forge/Settings/Setting.js +++ b/src/forge/Settings/Setting.js @@ -7,6 +7,8 @@ import { Link } from 'react-router-dom'; import axios from "axios"; import "./setting.scss"; import { unInstallMarketBot } from "../../softbot/api"; +import DorpChooseMenus from '../Component/licenseModal/dorpChooseMenus'; + const { TextArea } = Input; const { Option } = Select; @@ -46,6 +48,7 @@ class Setting extends Component { return; } } + componentDidMount = () => { this.updateDocumentTitle(); this.getCategory(); @@ -63,18 +66,39 @@ class Setting extends Component { } getLanguage = () => { + this.getInfo(); + }; + getLanguage = (id) => { const url = `/project_languages.json`; - axios - .get(url) - .then((result) => { - if (result) { - let LanguageList = this.setOptionsList(result.data.project_languages); - this.setState({ - LanguageList, - }); + axios.get(url).then((result) => { + if (result) { + let data = result.data.project_languages; + this.setState({LanguageList:data}); + if(id){ + let filters = data.filter(i=>i.id === id); + if(filters && filters.length > 0){ + this.props.form.setFieldsValue({project_language_id:filters[0].name}) + } } - }) - .catch((error) => {}); + } + }) + .catch((error) => {}); + }; + + getCategory = (id) => { + const url = `/project_categories.json`; + axios.get(url).then((result) => { + if (result) { + let data = result.data.project_categories; + this.setState({CategoryList:data}); + if(id){ + let filters = data.filter(i=>i.id === id); + if(filters && filters.length > 0){ + this.props.form.setFieldsValue({project_category_id:filters[0].name}) + } + } + } + }).catch((error) => {}); }; getInfo = () => { @@ -85,13 +109,15 @@ class Setting extends Component { .then((result) => { if (result) { const { project_units } = this.state; + const { project_name ,project_description , project_identifier } = result.data; let units = result.data.project_units; units.push(...project_units); - this.props.form.setFieldsValue({ - ...result.data, + project_name ,project_description , private:result.data.private , project_identifier , project_units:units }); + this.getCategory(result.data.project_category_id); + this.getLanguage(result.data.project_language_id); this.setState({ projectName:result.data.project_name, private_check: result.data.private, @@ -108,23 +134,6 @@ class Setting extends Component { }); }; - getCategory = () => { - const url = `/project_categories.json`; - axios - .get(url) - .then((result) => { - if (result) { - let CategoryList = this.setOptionsList( - result.data.project_categories - ); - this.setState({ - CategoryList, - }); - } - }) - .catch((error) => {}); - }; - setOptionsList = (data) => { let list = undefined; if (data && data.length > 0) { @@ -163,17 +172,17 @@ class Setting extends Component { update=(values)=>{ const { projectsId , owner } = this.props.match.params; - const { private_check , project_units } = this.state; - const {project_language_id, project_category_id, pr_view_admin} = values; + const { private_check , project_units , project_language_id , project_category_id} = this.state; + const {pr_view_admin} = values; const url = `/${owner}/${projectsId}.json`; axios.patch(url, { name: values.project_name, description: values.project_description, private: private_check, identifier:values.project_identifier, - project_language_id, - project_category_id, - pr_view_admin + pr_view_admin, + ...values, + project_language_id , project_category_id }).then((result) => { if (result) { this.props.showNotification(`仓库信息修改成功!`); @@ -272,6 +281,17 @@ class Setting extends Component { }) } + + getValue=(values,typeName)=>{ + const {id,name} = values; + this.setState({ + [`${typeName}`]:id + }) + this.props.form.setFieldsValue({ + [`${typeName}`]:name + }) + } + render() { const { getFieldDecorator } = this.props.form; const { projectsId , owner } = this.props.match.params; @@ -295,7 +315,7 @@ class Setting extends Component { 基本设置 - + {getFieldDecorator("project_name", { rules: [ @@ -358,20 +378,22 @@ class Setting extends Component { {getFieldDecorator("project_category_id", { rules: [], })( - + // + this.getValue(value,"project_category_id")}/> )} {getFieldDecorator("project_language_id", { rules: [], })( - + // + this.getValue(value,"project_language_id")}/> )} 访问权限: