import React, { Component } from 'react'; import { Link } from "react-router-dom"; import { markdownToHTML, configShareForCustom,getImageUrl,getUploadActionUrlthree,appendFileSizeToUploadFileAll} from 'educoder' import { Divider, Tooltip,Upload} from 'antd'; import LoadingSpin from '../../../../common/LoadingSpin'; import 'antd/lib/pagination/style/index.css'; import '../shixunchildCss/Challenges.css'; import axios from 'axios'; const $ = window.$; class Challengesjupyter extends Component { constructor(props) { super(props) this.state = { ChallengesDataList: undefined, operate: true, startbtns: false, iFrameHeight: '0px', jupyter_port:0, jupyter_url:null, jupyter_urls:null, username:"", booljupyterurls:false, loading:false, boxoffsetHeigh:0, opentitletype:true, isopentitletype:"Less", enlarge:false, fileList:[], shuaxin:false, } } ChallengesList = () => { let id = this.props.match.params.shixunId; let ChallengesURL = `/shixuns/` + id + `/challenges.json`; axios.get(ChallengesURL).then((response) => { if (response.status === 200) { if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { }else{ configShareForCustom(this.props.shixunsDetails.name, response.data.description) this.setState({ ChallengesDataList: response.data, sumidtype: false, }); if(response.data.description=== ""||response.data.description===null||response.data.description===undefined){ this.setState({ isopentitletype:"Less", }) } this.getjianjiesize() } } }).catch((error) => { //console.log(error) }); } getjianjiesize=()=>{ let {ChallengesDataList}=this.state; let boxoffsetHeigh; let box=document.getElementById("shixunchallengesid"); if(box){ boxoffsetHeigh=box.offsetHeight if(ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined){ }else{ if(this.state.isopentitletype==="greater"){ }else{ if(boxoffsetHeigh>=300){ this.setState({ opentitletype:true, isopentitletype:"greater", boxoffsetHeigh:boxoffsetHeigh }) }else{ this.setState({ isopentitletype:"Less", boxoffsetHeigh:boxoffsetHeigh }) } } } } } componentDidUpdate = (prevProps,prevState) => { //防止陷入无限循环 if(prevState.ChallengesDataList!=this.state.ChallengesDataList){ if(this.state.isopentitletype==="greater"){ }else{ this.getjianjiesize() } } } componentDidMount() { var that=this; setTimeout(this.ChallengesList(), 1000); let id = this.props.match.params.shixunId; let ChallengesURL = `/jupyters/get_info_with_tpm.json`; let datas={ identifier:id, } axios.get(ChallengesURL, {params: datas}).then((response) => { if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) }else{ if(response.data.status===0){ setTimeout(() => { this.setState({ jupyter_url:response.data.url, jupyter_urls:response.data.url, jupyter_port:response.data.port, booljupyterurls:true, }) }, 800) }else{ setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) } } }).catch((error) => { setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) }); setTimeout(this.getjianjiesize(), 1000); window.addEventListener('message', (e) => { console.log(e); if(e){ if(e.data){ if(e.data==="jupytermessage"){ that.modifyjupyter(); } } } }); } updatamakedowns = () => { this.setState({ loading:true, booljupyterurls:false }) let id = this.props.match.params.shixunId; let ChallengesURL = `/jupyters/get_info_with_tpm.json`; let datas={ identifier:id, } axios.get(ChallengesURL, {params: datas}).then((response) => { if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) }else{ if(response.data.status===0){ setTimeout(() => { this.setState({ jupyter_url:response.data.url, jupyter_urls:response.data.url, jupyter_port:response.data.port, booljupyterurls:true, }) }, 800) this.setState({ }) }else{ setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) } } }).catch((error) => { setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) }); } modifyjupyter=()=>{ let id=this.props.match.params.shixunId; var jupyter_port=""; try{ jupyter_port= parseInt(this.state.jupyter_port); }catch (e) { jupyter_port=this.state.jupyter_port; } const url=`/jupyters/save_with_tpm.json`; const data={ identifier:id, jupyter_port:jupyter_port, } axios.get(url, {params: data}) .then((result) => { if (result.data.status === 0) { // this.props.showNotification(`应用成功`); console.log("应用成功了"); } }).catch((error) => { }) } opentitle=()=>{ this.setState({ opentitletype:!this.state.opentitletype }) } onclki=(bool)=>{ this.setState({ enlarge:bool }) } Importingfiles=()=>{ // 导入文件 } handleChange = (info) => { if(info.file.status == "done" || info.file.status == "uploading" || info.file.status === 'removed'){ let fileList = info.fileList; this.setState({ fileList: appendFileSizeToUploadFileAll(fileList), }); if(info.file.status === 'done'){ if(info.file.response){ if(info.file.response.status===-1||info.file.response.status==="-1"){ }else{ } } } if(info.file.response){ if(info.file.response.status===-1||info.file.response.status==="-1"){ }else{ if(info.file.response.status===0){ try { this.setState({ jupyter_url : "" }) setTimeout(()=>{ this.setState({ jupyter_url : this.state.jupyter_url, }) },1000) this.props.showNotification('上传文件成功!'); }catch (e) { } } } } } } render() { let{ChallengesDataList,booljupyterurls,enlarge,fileList}=this.state; let id = this.props.match.params.shixunId; //老师 const is_teacher = this.props&&this.props.current_user&&this.props.current_user.is_teacher?this.props.current_user.is_teacher:false; //运营人员 const business = this.props&&this.props.current_user&&this.props.current_user.business?this.props.current_user.business:false; //管理员 const admin = this.props&&this.props.current_user&&this.props.current_user.admin?this.props.current_user.admin:false; let mysidentity =false; try { mysidentity =this.props.identity < 5 &&ChallengesDataList&& ChallengesDataList.shixun_status< 3?true:false; }catch (e) { } const uploadProps = { width: 600, fileList, multiple: true, data:{ identifier:id, }, //multiple 是否支持多选 查重的时候不能多选 不然弹许多框出来 // https://github.com/ant-design/ant-design/issues/15505 // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // showUploadList: false, action: `${getUploadActionUrlthree()}`, showUploadList:false, onChange: this.handleChange, beforeUpload: (file) => { //上传前的操作 // console.log('beforeUpload', file.name); if(file.name.indexOf('.ipynb') === -1){ this.props.showNotification('请上传正确格式文件!'); return false } const isLt10M = file.size / 1024 / 1024 < 10; if (!isLt10M) { this.props.showNotification('文件大小必须小于10MB!'); } return isLt10M; }, }; return (

简介 编辑
{ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined?:""} {ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined?"":this.state.isopentitletype==="greater"&&this.state.opentitletype===true? :""}

{/*{ChallengesDataList === undefined ? "" :ChallengesDataList&&ChallengesDataList.description===null?"":*/} {/*

*/} {/*}*/} {ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined?
{this.props.identity < 5?:}

暂时还没有相关数据哦!

:

{ChallengesDataList === undefined ? "" :ChallengesDataList&&ChallengesDataList.description===null?"":

}

}

{ booljupyterurls===true? ( this.state.jupyter_url === null?

加载实训失败,

this.updatamakedowns()}>重新加载

:"" ) :"" }
{this.state.isopentitletype==="Less"?"":this.state.opentitletype===true?this.opentitle()} className={"pointer Breadcrumbfont color-grey-9 "}> 阅读全文 :this.opentitle()} className={"pointer Breadcrumbfont color-grey-9 "}> 收起全文 }

{ this.state.jupyter_url === null || this.state.jupyter_url === undefined ? "" : ( admin===true||business===true||mysidentity===true?

任务详情

(请将实训题目写在下方并保存)

{ enlarge===true? this.onclki(false)}> : this.onclki(true)}> }

导入

: "" ) } { admin===true||business===true||mysidentity===true?
{ this.state.jupyter_url===null || this.state.jupyter_url===undefined? ( booljupyterurls===false? :"" ) : }
:"" }
) } } export default Challengesjupyter;