import React, {Component} from 'react'; import MonacoEditor from 'react-monaco-editor'; import { Input, Select, Checkbox, Modal, Icon, Upload, Button, Tooltip, Form } from 'antd'; import axios from 'axios'; import TPMMDEditor from "../challengesnew/TPMMDEditor"; import Bottomsubmit from "../../modals/Bottomsubmit"; import {getUploadActionUrl} from 'educoder'; import './css/TPMsettings.css'; import '../newshixuns/css/Newshixuns.css'; const Option = Select.Option; class Shixuninformation extends Component { constructor(props) { super(props) this.contentMdRef = React.createRef(); this.state = { NAME_COUNT: 60, shixunmemoMDvalue: "", testscripttiptype: false, shixunName: '', trainee: undefined, choice_small_type: [], simichecked: false, Executivetyoe: false, Executiveordervalue: "", Compilecommandvalue: "", shixun_service_configs: undefined, fileList:[], loading:false, } } componentDidMount() { } componentDidUpdate(prevProps, prevState) { if (prevProps.data != this.props.data) { if (this.props.data&&this.props.data.shixun) { this.setState({ shixunName: this.props.data.shixun&&this.props.data.shixun.name, trainee:this.props.data.shixun&&this.props.data.shixun.trainee, choice_main_type: this.props.data.shixun&&this.props.data.shixun.choice_main_type, choice_small_type: this.props.data.shixun&&this.props.data.shixun.choice_small_type, choice_standard_scripts:this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts, shixunmemoMDvalue: this.props.data.shixun&&this.props.data.shixun.evaluate_script, simichecked: this.props.data.shixun&&this.props.data.shixun.is_secret_repository, shixun_service_configs: this.props.data.shixun&&this.props.data.shixun.shixun_service_configs, standard_scripts:this.props.data.shixun&&this.props.data.shixun.standard_scripts, shixun_service_configlist:this.props.data.shixun&&this.props.data.shixun.shixun_service_configs, }) if(this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts===null){ this.setState({ choice_standard_scripts:{id: this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id, value: ""}, choice_standard_scriptssum:this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id }) this.props.form.setFieldsValue({ selectscripts:this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id }) this.get_mirror_script(this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id) }else{ this.props.form.setFieldsValue({ selectscripts:this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts }) } let newlist = "" this.props.data.shixun&&this.props.data.shixun.choice_small_type.map((item, key) => { this.props.data.shixun.small_type.map((i,k)=>{ if (item===i.id) { newlist = newlist + `${i.description}` } }) }) this.setState({ subvalues: newlist }) this.props.data.shixun&&this.props.data.shixun.main_type.map((item,key)=>{ if(item.id===this.props.data.shixun&&this.props.data.shixun.choice_main_type){ this.setState({ mainvalues:item.description, }) } }) this.props.form.setFieldsValue({ name:this.props.data.shixun&&this.props.data.shixun.name, trainee: this.props.data.shixun&&this.props.data.shixun.trainee, selectleft: this.props.data.shixun&&this.props.data.shixun.choice_main_type, selectright:this.props.data.shixun&&this.props.data.shixun.choice_small_type, }) this.contentMdRef.current.setValue(this.props.data.shixun&&this.props.data.shixun.description); } } } getshixunmemoMDvalue = (value, e) => { this.setState({ shixunmemoMDvalue: value }) } testscripttip = (val) => { if (val === 0) { this.setState({ testscripttiptype: true }) } else if (val === 1) { this.setState({ testscripttiptype: false }) } } post_apply = () => { this.setState({ postapplyvisible: true }) } sendhideModaly = () => { this.setState({ postapplyvisible: false, }) if (this.state.file !== undefined) { // this.deleteAttachment(this.state.file); this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } else { this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } } sendsure_apply = () => { let {language, runtime, run_method} = this.state; if (!language || language === "") { // this.props.showNotification(`请填写该镜像是基于什么语言`); this.setState({ languagewritetype: true }) return } if (!runtime || runtime === "") { // this.props.showNotification(`请填写该镜像是基于什么语言系统环境`); this.setState({ systemenvironmenttype: true }) return; } if (!run_method || run_method === "") { // this.props.showNotification(`请填写该镜像中测试代码运行方式`); this.setState({ testcoderunmodetype: true }) return; } var attachment_ids = undefined; if (this.state.fileList) { attachment_ids = this.state.fileList.map(item => { return item.response ? item.response.id : item.id }) } if (attachment_ids === undefined || attachment_ids.length === 0) { this.setState({ attachmentidstype: true }) return; } var data = { language: language, runtime: runtime, run_method: run_method, attachment_id: attachment_ids[0], } var url = `/shixuns/apply_shixun_mirror.json`; axios.post(url, data ).then((response) => { try { if (response.data) { if (this.state.file !== undefined) { this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } else { this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } this.props.showNotification("提交成功") this.sendhideModaly() } } catch (e) { } }) } setlanguage = (e) => { this.setState({ language: e.target.value }) if (e.target.value) { this.setState({ languagewritetype: false }) } } setruntime = (e) => { this.setState({ runtime: e.target.value }) if (e.target.value) { this.setState({ systemenvironmenttype: false }) } } setrun_method = (e) => { this.setState({ run_method: e.target.value }) if (e.target.value) { this.setState({ testcoderunmodetype: false }) } } // 附件相关 START handleChange = (info) => { if (info.file.status === 'uploading' || info.file.status === 'done' || info.file.status === 'removed') { let {fileList} = this.state; if (info.file.status === 'uploading' || info.file.status === 'done' || info.file.status === 'removed') { console.log("handleChange1"); // if(fileList.length===0){ let fileLists = info.fileList; this.setState({ // fileList:appendFileSizeToUploadFileAll(fileList), fileList: fileLists, deleteisnot: false }); // } } } } onAttachmentRemove = (file) => { if (!file.percent || file.percent == 100) { Modal.confirm({ title: '确定要删除这个附件吗?', okText: '确定', cancelText: '取消', // content: 'Some descriptions', onOk: () => { console.log("665") this.deleteAttachment(file) }, onCancel() { console.log('Cancel'); }, }); return false; } } deleteAttachment = (file) => { console.log(file); let id = file.response == undefined ? file.id : file.response.id const url = `/attachments/${id}.json` axios.delete(url, {}) .then((response) => { if (response.data) { const {status} = response.data; if (status == 0) { // console.log('--- success') this.setState((state) => { const index = state.fileList.indexOf(file); const newFileList = state.fileList.slice(); newFileList.splice(index, 1); return { fileList: newFileList, deleteisnot: true }; }); } } }) .catch(function (error) { console.log(error); }); } bigClass = (value,e) => { this.setState({ mainvalues:e.props.name }) let list = [] list.push(this.state.choice_main_type) this.state.choice_small_type.map((item, key) => { list.push(item) }) let newshixun_service_configs = this.state.shixun_service_configs; let newshixun_service_configsagin = []; newshixun_service_configs.map((item, key) => { list.map((its, index) => { if (item.mirror_repository_id === its) { newshixun_service_configsagin.push(item) } }) }) this.props.data.shixun.main_type.some((item, key) => { if (item.id === value) { newshixun_service_configsagin[0] = { mirror_repository_id: value, name: item.type_name, cpu_limit: 1, lower_cpu_limit: 0.1, memory_limit: 1024, request_limit: 10 } return true } } ) this.props.form.setFieldsValue({ selectleft: value, }) let url = `/shixuns/get_mirror_script.json?mirror_id=` + value; axios.get(url).then((response) => { if (response.status === 200) { this.setState({ choice_standard_scripts:{id: response.data[0].id, value: ""}, choice_standard_scriptssum:response.data[0].id }) this.props.form.setFieldsValue({ selectscripts:response.data[0].id }) this.get_mirror_script(response.data[0].id) this.setState({ choice_main_type: value, standard_scripts: response.data, shixun_service_configs: newshixun_service_configsagin, shixun_service_configlist: newshixun_service_configsagin, }) } }).catch((error) => { console.log(error) }); } Deselectlittle = (value,e) => { let {shixun_service_configs, choice_small_type} = this.state; let newshixun_service_configs = shixun_service_configs; let newchoice_small_type = choice_small_type; newshixun_service_configs.some((item, key) => { if (item.mirror_repository_id === value) { newshixun_service_configs.splice(key, 1) return true } } ) newchoice_small_type.some((item, key) => { if (item === value) { newchoice_small_type.splice(key, 1) return true } } ) this.setState({ choice_small_type: newchoice_small_type, shixun_service_configs: newshixun_service_configs, shixun_service_configlist: newshixun_service_configs, }) } showlittleClass=(value,e)=>{ let newlist = "" e.map((item, key) => { if (item.props.name != "") { newlist = newlist + `${item.props.name}` } }) this.setState({ subvalues: newlist }) this.props.form.setFieldsValue({ selectright: value, }) } littleClass = (value,e) => { let newshixun_service_configs = this.state.shixun_service_configs; let newchoice_small_type = this.state.choice_small_type; let list = [] list.push(this.state.choice_main_type) newchoice_small_type.map((item, key) => { list.push(item) }) let newshixun_service_configsagin = [] newshixun_service_configs.map((item, key) => { list.map((its, index) => { if (item.mirror_repository_id === its) { newshixun_service_configsagin.push(item) } }) }) this.props.data.shixun.small_type.some((items, keys) => { if (items.id === value) { newshixun_service_configsagin.push({ mirror_repository_id: value, name: items.type_name, cpu_limit: 1, lower_cpu_limit: 0.1, memory_limit: 1024, request_limit: 10 }) return true } } ) newchoice_small_type.push(value) this.setState({ choice_small_type: newchoice_small_type, shixun_service_configs: newshixun_service_configsagin, shixun_service_configlist: newshixun_service_configsagin, }) } SelectScput = (value, e) => { this.setState({ choice_standard_scriptssum: value, language: e.props.name, choice_standard_scripts: {id: e.props.value, value: ""}, standard_scriptsModal: true }) } hidestandard_scriptsModal = () => { this.setState({ standard_scriptsModal: false, standard_scriptsModals: false }) } get_mirror_script = (ids) => { let {choice_standard_scriptssum} = this.state; let id = this.props.match.params.shixunId; let url = `/shixuns/${id}/get_script_contents.json`; axios.get((url),{params:{ script_id:ids?ids:choice_standard_scriptssum }}).then((response) => { if (response.status === 200) { // this.evaluate_scriptMD(response.data.content, "shixunmemoMD"); if(ids==undefined){ this.setState({ standard_scriptsModal: false, standard_scriptsModals: true, }) } this.setState({ shixunmemoMDvalue: response.data.content }) } }).catch((error) => { console.log(error) }) } simionChange = (e) => { this.setState({ simichecked: e.target.checked }) } showModal = () => { this.setState({ visibleTemplate: true, }); } handleCancelTemplate = (e) => { this.setState({ Executiveordervalue: "", Compilecommandvalue: "", visibleTemplate: false }) } hideModalTemplate = (e) => { let id = this.props.match.params.shixunId; let {Executiveordervalue, Compilecommandvalue} = this.state; if (Executiveordervalue === "" || Executiveordervalue === undefined) { this.setState({ Executivetyoe: true, }); return } // Executiveordervalue=String(Executiveordervalue); // Compilecommandvalue=String(Compilecommandvalue); let trl = `/shixuns/${id}/get_custom_script.json?compile=${Executiveordervalue}&excutive=${Compilecommandvalue}` axios.get(trl).then((response) => { // this.evaluate_scriptMD(response.data.shixun_script, "shixunmemoMD"); this.setState({ shixunmemoMDvalue: response.data.shixun_script }) }).catch((error) => { console.log(error) }); this.setState({ visibleTemplate: false }) } Executiveorder = (e) => { this.setState({ Executiveordervalue: e.target.value }) } Compilecommand = (e) => { this.setState({ Compilecommandvalue: e.target.value }) } setConfigsInputs=(e,keys,str)=>{ let {shixun_service_configs}=this.state; let newshixun_service_configs=shixun_service_configs; newshixun_service_configs.map((item,key)=>{ if(key===keys){ switch (str) { case 1: item.cpu_limit=e.target.value break; case 2: item.lower_cpu_limit=e.target.value break; case 3: item.memory_limit=e.target.value break; case 4: item.request_limit=e.target.value break; } } }) this.setState({ shixun_service_configs:newshixun_service_configs, shixun_service_configlist:newshixun_service_configs, }) } onSubmits=()=>{ this.setState({ loading:true }) const mdContnet = this.contentMdRef.current.getValue().trim(); let{choice_standard_scriptssum,choice_standard_scripts}=this.state; this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { console.log('Received values of form: ', values); let url = `/shixuns/${this.props.match.params.shixunId}.json`; let newshixun_service_configlist = this.state.shixun_service_configlist.map(v => { let v1 = Object.assign({},v); delete v1.name; return v1 }); let data={ main_type:this.state.choice_main_type, sub_type:this.state.choice_small_type, is_secret_repository:this.state.simichecked, shixun:{ name: values.name, trainee: this.state.trainee, is_jupyter: this.props.shixunsDetails.is_jupyter, mirror_script_id: this.props.shixunsDetails.is_jupyter===true?null:this.state.choice_standard_scriptssum===undefined?this.state.choice_standard_scripts:this.state.choice_standard_scriptssum, }, shixun_info: { description: mdContnet, evaluate_script: this.props.shixunsDetails.is_jupyter===true?"":this.state.shixunmemoMDvalue }, shixun_service_configs:newshixun_service_configlist } axios.put(url, data).then((result) => { if (result) { if (result.data) { this.props.getdatas("2") if(result.data.shixun_identifier){ this.props.showNotification("基本信息更新成功!") this.setState({ loading:false }) } } } }).catch((error) => { this.setState({ loading:false }) }); }else{ this.setState({ loading:false }) } }); this.setState({ loading: false }) } Selectthestudent = (value) => { this.setState({ trainee: value }) } render() { let operateauthority = this.props.identity === 1 ? true : this.props.identity < 5 && this.props.data.shixun.status == 0 ? true : false; // console.log(operateauthority) const {getFieldDecorator} = this.props.form; const { fileList, choice_standard_scripts, postapplyvisible, shixunmemoMDvalue} = this.state; // console.log("1222") // console.log(choice_standard_scripts) const uploadProps = { width: 600, fileList, multiple: true, // https://github.com/ant-design/ant-design/issues/15505 // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // showUploadList: false, action: `${getUploadActionUrl()}`, onChange: this.handleChange, onRemove: this.onAttachmentRemove, beforeUpload: (file, fileList) => { if (this.state.fileList.length >= 1) { return false } // console.log('beforeUpload', file.name); const isLt150M = file.size / 1024 / 1024 < 50; if (!isLt150M) { // this.props.showNotification(`文件大小必须小于50MB`); this.props.showNotification("文件大小必须小于50MB") } if (this.state.file !== undefined) { this.setState({ file: file }) } else { this.setState({ file: file }) } return isLt150M; }, } return (
{getFieldDecorator('name', { rules: [{ required: true, message: '请输入选题名称', }, { max: 60, message: '请输入名称,最大限制60个字符', }, { whitespace: true, message: '请勿输入空格' }], })( )} {getFieldDecorator('trainee', { rules: [{required: true, message: '请选择难易度'}], })(
)} (实训的难易程度)
{getFieldDecorator('selectleft', { rules: [{required: true, message: '请选择主类别'}], })(
)}
{getFieldDecorator('selectright', { rules: [{required: false, message: '请选择小类别'}], })(
)}
{this.state.mainvalues === undefined && this.state.subvalues === undefined || this.state.mainvalues === "" && this.state.subvalues === "" ? "" :
{`${this.state.mainvalues === undefined || this.state.mainvalues === "" ? "" : `已安装软件:` + this.state.mainvalues}`} {`${this.state.subvalues === undefined || this.state.subvalues === "" ? "" : this.state.mainvalues === undefined || this.state.mainvalues === "" ? `已安装软件:` + this.state.subvalues : this.state.subvalues}`} {`${this.state.mainvalues === undefined || this.state.mainvalues === "" ? "" : `说明:添加了` + this.state.mainvalues}${this.state.subvalues === undefined || this.state.subvalues === "" ? "" : this.state.mainvalues === undefined || this.state.mainvalues === "" ? `说明:添加了` + this.state.subvalues : this.state.subvalues}`}
}
没有实验环境? 申请新建
{ this.props.shixunsDetails&&this.props.shixunsDetails.is_jupyter===true?"": {getFieldDecorator('selectscripts', { rules: [{required: true, message: '请选择评测脚本'}], })(
)} this.showModal()}>使用自定义脚本 this.testscripttip(0)}>

使用自定义模板,平台无法自动更新脚本,请在关卡创建完后手动更新脚本中的必填参
数和以下2个数组元素:
challengeProgramNames
sourceClassNames

示例:有2个关卡的实训

各关卡的待编译文件为:
src/step1/HelloWorld.java
src/step2/Other.java

各关卡的编译后生成的执行文件为:
step1.HelloWorld
step2.Other

则数组元素更新如下:
challengeProgramNames=("src/step1/
HelloWorld.java" "src/step2/Other.java")
sourceClassNames=("step1.HelloWorld
" "step2.Other")

其它参数可按实际需求定制

this.testscripttip(1)}>知道了

} { this.props.shixunsDetails&&this.props.shixunsDetails.is_jupyter===true?"":
}
{ this.props.shixunsDetails&&this.props.shixunsDetails.is_jupyter===true?"": 私密版本库: {this.state.simichecked===false?"(若需要对学员隐藏部分版本库内容时,请选中;选中保存后表示启用私密版本库,请将需要对学员隐藏的文件存储在私密版本库)":"已创建的私密版本库及其内容,将在“保存”时被删除"} } {this.props.identity < 3 ?

服务配置

{this.state.shixun_service_configs && this.state.shixun_service_configs.map((item, key) => { return (
{item.name} {/*this.Deselectlittle(item.mirror_repository_id)}>*/}
this.setConfigsInputs(e, key, 1)} className="panel-box-sizing task-form-100 task-height-40" placeholder="请输入类别名称"/>
this.setConfigsInputs(e, key, 2)} className="panel-box-sizing task-form-100 task-height-40" placeholder="请输入类别名称"/>
this.setConfigsInputs(e, key, 3)} className="panel-box-sizing task-form-100 task-height-40" placeholder="请输入类别名称"/>
this.setConfigsInputs(e, key, 4)} className="panel-box-sizing task-form-100 task-height-40" placeholder="请输入类别名称"/>
) })}
: ""} {postapplyvisible === true ? : ""} {/**/} {/*
*/} {/*

已创建的私密版本库及其内容,将在“保存”时被删除

*/} {/*

是否确认取消选择?

*/} {/*
*/} {/*
*/} {/* this.hidesimichecked()} className="task-btn fl">取消*/} {/* this.getsimichecked()}>确定*/} {/*
*/} {/**/}

原有脚本将被新的脚本覆盖,无法撤销

是否确认执行覆盖操作

this.hidestandard_scriptsModal()} className="task-btn fl">取消 this.get_mirror_script()}>确定

评测脚本生成成功!

this.hidestandard_scriptsModal()}>确定
  • 执行命令不能为空

  • {this.state.languagewritetype === true ? "请填写该镜像语言" : ""}
  • {this.state.systemenvironmenttype === true ? "请填写该镜像语言系统环境" : ""}
  • {this.state.testcoderunmodetype === true ? "请填写该镜像测试代码运行方式" : ""}
  • 上传附件 (单个文件50M以内)
  • {this.state.attachmentidstype === true ? "请上传附件" : ""}
  • this.sendhideModaly()} >取消
  • {this.props.identity < 5 ? : ""}
    ); } } const TopShixuninformation = Form.create({name: 'newshixun'})(Shixuninformation); export default TopShixuninformation;