TPM添加新文件

dev_aliyun_beta
caicai8 5 years ago
parent 00ebba15a3
commit 469fa25837

@ -372,7 +372,6 @@ class App extends Component {
path="/interesse" component={Interestpage}
/>
<Route path="/shixuns/new" component={Newshixuns}>
</Route>

@ -604,7 +604,9 @@ class studentsList extends Component{
}
.drop_down_menu li {
overflow: visible;
width: 93px;
width:100%;
box-sizing:boder-box;
float:unset;
}
.drop_down_menu, .drop_down_normal {
padding-top: 10px;

@ -581,7 +581,7 @@ class TPMBanner extends Component {
return (
shixunsDetails===undefined?"":
<div>
<div className="shixunDetail">
<div className="shixunDetail_top">
{AccountProfiletype===true?<AccountProfile

@ -28,6 +28,8 @@ import TPMRanking_listComponent from './TPMRanking_listContainer'
import TPMCollaboratorsComponent from './TPMCollaboratorsContainer'
import '../page/tpiPage.css'
const $ = window.$
//任务
// const TPMChallengeComponent = Loadable({
// loader: () => import('./TPMChallengeContainer'),
@ -116,6 +118,13 @@ const TPMUpdatepropaede = Loadable({
})
// 版本库添加文件
const AddFile = Loadable({
loader: () => import('./shixunchild/Repository/RepositoryAddFile'),
loading: Loading,
})
const interceptorUrlArray = ['repository.json', 'commits.json', 'propaedeutics.json'
, 'challenges.json', 'discusses.json', 'ranking_list.json', 'collaborators.json']
const cacheInterceptorUrlMap = {}
@ -258,14 +267,17 @@ class TPMIndex extends Component {
// }
render() {
let url = window.location.href;
let flag = url.indexOf("add_file")>-1;
return (
<div className="newMain clearfix">
{
!flag &&
<TPMBanner
{...this.props}
{...this.state}
></TPMBanner>
}
<Switch {...this.props}>
@ -279,6 +291,11 @@ class TPMIndex extends Component {
/>)
}></Route>
<Route path="/shixuns/:shixunId/repository/add_file" render={
(props) => (<AddFile {...this.props} {...this.state} {...props}
/>)
}></Route>
<Route path="/shixuns/:shixunId/repository" render={
(props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props}
/>)

@ -13,7 +13,9 @@ import axios from 'axios';
import { trace, trace_collapse ,getImageUrl, toPath} from "educoder";
import RepositoryDirectories from './RepositoryDirectories'
import RepositoryAddFile from './RepositoryAddFile'
import { ActionBtn , NoneData } from 'educoder'
const $ = window.$;
// 点击按钮复制功能
@ -48,7 +50,6 @@ class Repository extends Component {
userauthority=this.props.author.login===""||this.props.author.user_id===""||this.props.author.login===null||this.props.author.user_id===null;
}
// console.log(commits)
return (
<React.Fragment>
{/* jfinalshop/WebRoot */}
@ -83,7 +84,12 @@ class Repository extends Component {
<a href="/forums/2784" target="_blank"
className=" guideBtn" >Git使用指南</a>
{/* <RepositoryAddFile {...this.props} {...this.state}></RepositoryAddFile> */}
{
this.props.current_user && this.props.current_user.admin ==true ?
<ActionBtn style="orangeLine" className="ml20" to={`/shixuns/${match.params.shixunId}/repository/add_file`}>+添加文件</ActionBtn>:""
}
<div className="fr font-12 color-grey-9 pr">
<label className="fl mt2">网址克隆</label>
<input type="text" id="copy_rep_content" className="fl url-input mt2"
@ -162,12 +168,7 @@ class Repository extends Component {
</style>
{/* 用户、最近提交时间 */}
{
trees === undefined || trees === null ? <div className="alltask">
<div className="edu-tab-con-box clearfix edu-txt-center">
<img className="edu-nodata-img mb20" src={getImageUrl("images/educoder/nodata.png")}/>
<p className="edu-nodata-p mb20">暂时还没有相关数据哦</p>
</div>
</div> :
trees === undefined || trees === null ? <NoneData></NoneData>:
<div>
<div className="edu-back-skyblue padding10-20 clearfix">
<img alt={author.name} className="radius fl mr10"

@ -1,49 +1,194 @@
import React, { Component } from 'react';
import { ActionBtn } from 'educoder'
import { Form , Modal } from 'antd'
import { Form , Modal , Input , Breadcrumb , Button } from 'antd'
import { Link } from 'react-router-dom'
import axios from 'axios'
/**
---------------------------- START
*/
function getModeByMirrorName(mirror_name) {
let mode = 'javascript'
if (mirror_name && mirror_name.length) {
for (let i = 0; i < mirror_name.length; i++) {
let modeVal = mirrorNameModeMap[mirror_name[i]];
if (modeVal) {
mode = modeVal;
break;
}
}
}
return mode;
}
const _extraKeys = {"Alt-/": "autocomplete"};
function createCMOptions(mirror_name) {
let mode = getModeByMirrorName(mirror_name)
let cmOptions = {
lineNumbers: true,
mode: mode,
theme: "railscasts",
indentUnit:4,
matchBrackets: true,
autoRefresh: true,
smartIndent: true,//智能换行
extraKeys: _extraKeys,
autofocus: true,
styleActiveLine: true,
lint: true,
gutters: ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-lint-markers"]
};
return cmOptions;
}
const mirrorNameModeMap = {
'JFinal': 'text/x-java',
'Java': 'text/x-java',
'Kotlin': 'text/x-kotlin',
'C/C++' : 'text/x-c++src',
'MachineLearning': {
name: "python",
version: 3,
singleLineStringErrors: false
},
'Python2.7': {
name: "python",
version: 3,
singleLineStringErrors: false
},
'Python3.6': {
name: "python",
version: 3,
singleLineStringErrors: false
},
}
/**
---------------------------- END
*/
class RepositoryAddFile extends Component {
constructor(props) {
super(props);
this.state={
visible:false
}
componentDidMount(){
let cmOptions = createCMOptions(this.props.mirror_name)
const extend_editor = window.CodeMirror.fromTextArea(window.$('#codemirror-file-edit')[0]
, cmOptions);
// tpi没setValue也可以
extend_editor.setValue('')
extend_editor.refresh();
// 拖拽也需要用 window.editor_CodeMirror.refresh()
window.editor_tempCodeMirror = extend_editor;
this.extend_editor = extend_editor;
}
checkPath= (rule, value, callback) =>{
if (value.indexOf("/") > -1 && value.length==1 ) {
callback('请输入正确的文件路径');
}else{
callback();
}
}
addFile = () =>{
this.setState({
visible:true
handleSubmit = () =>{
this.props.form.validateFieldsAndScroll((err, values) => {
if(!err){
let shixunId = this.props.match.params.shixunId;
let url = `/shixuns/${shixunId}/add_file.json`
axios.post(url,{
path:values.path,
message:values.message,
content:this.extend_editor.getValue()
}).then((result)=>{
if(result){
this.props.history.push(`${result.data.url}`)
}
}).catch((error)=>{
console.log(error);
})
}
cancelAdd = () =>{
this.setState({
visible:false
})
}
render(){
let { visible } = this.state
const {getFieldDecorator} = this.props.form;
let { shixunId } = this.props.match.params;
return(
<React.Fragment>
<ActionBtn style="orangeLine" className="ml20" onClick={this.addFile}>+添加文件</ActionBtn>
<Modal
className={"RepositioryModal"}
title={'添加文件'}
visible={visible}
closable={false}
footer={null}
destroyOnClose={true}
width="550px"
>
<div className="task-popup-content">
<div className="educontent">
<style>
{`
.formStyle .ant-form-item{
margin-bottom:10px!important;
}
.formStyle .ant-col.ant-form-item-label{
margin-left:-10px;
line-height:30px;
margin-bottom:10px;
}
.breadcrumb .ant-breadcrumb-separator{
margin:0px 2px;
}
/*.filecode .CodeMirror.cm-s-railscasts{
border:1px solid #E5E5E5;
}
.filecode .CodeMirror.cm-s-railscasts .CodeMirror-sizer,.filecode .CodeMirror-gutters,.filecode .CodeMirror-scroll{
background:#fff;
}
.filecode .CodeMirror-linenumber{
text-align:center
}*/
`}
</style>
<p className="mt10 mb10">
<Breadcrumb separator='>' className="breadcrumb">
<Breadcrumb.Item href='/shixuns'>实训项目</Breadcrumb.Item>
<Breadcrumb.Item href={`/shixuns/${shixunId}/repository`}>版本库</Breadcrumb.Item>
<Breadcrumb.Item>添加新文件</Breadcrumb.Item>
</Breadcrumb>
</p>
<Form onSubmit={this.handleSubmit} className="formStyle">
<div className="edu-back-white padding20-30 mb10">
<Form.Item label="文件名">
{getFieldDecorator('path', {
rules: [
{required: true, message: "文件名不能为空"},
{
validator:this.checkPath
}]
})(
<Input placeholder="输入文件路径名src/HelloWord.java" className="winput-300-35 fl"/>
)}
</Form.Item>
</div>
<div className="edu-back-white padding30">
<p className="ant-form-item-label">
<label>内容</label>
</p>
<div className="mt10 mb25 repoCMWrapper filecode">
<textarea className="" id="codemirror-file-edit" style={{display:'none'}} name="content"></textarea>
</div>
<div className="clearfix mt30 edu-txt-center mb10">
<a className="task-btn color-white mr30" onClick={this.cancelAdd}>取消</a>
<a className="task-btn task-btn-orange">提交</a>
<Form.Item label="提交信息">
{getFieldDecorator('message', {
rules: [{required: true, message: "请输入提交信息"}],
})(
<textarea className="winput-100-130 fl"></textarea>
)}
</Form.Item>
</div>
<div className="clearfix mt30 edu-txt-right mb30">
<Button type="primary" className="defalutSubmitbtn fr ml20" onClick={this.handleSubmit}>提交</Button>
<Link className="defalutCancelbtn fr" to={`/shixuns/${shixunId}/repository`}>取消</Link>
</div>
</Form>
</div>
</Modal>
</React.Fragment>
)
}
}

Loading…
Cancel
Save