import React, { Component } from 'react'; import { Link } from "react-router-dom"; import { markdownToHTML, configShareForCustom} from 'educoder' import { Divider, Tooltip } 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, username:"", booljupyterurls:false, loading:false, boxoffsetHeigh:0, opentitletype:true, enlarge: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, }); } } }).catch((error) => { //console.log(error) }); } componentDidUpdate = (prevProps,prevState) => { //防止陷入无限循环 if(prevState.ChallengesDataList!=this.state.ChallengesDataList){ let boxoffsetHeigh; let box=document.getElementById("shixunchallengesid"); if(box){ boxoffsetHeigh=box.offsetHeight if(boxoffsetHeigh<260){ this.setState({ opentitletype:false, boxoffsetHeigh:boxoffsetHeigh }) }else{ this.setState({ boxoffsetHeigh:boxoffsetHeigh }) } } } } componentDidMount() { 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_port:response.data.port, booljupyterurls:true, }) }, 800) }else{ setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) } } }).catch((error) => { setTimeout(() => { this.setState({ booljupyterurls:true, }) }, 600) }); } 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_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(`应用成功`); } }).catch((error) => { }) } opentitle=()=>{ this.setState({ opentitletype:!this.state.opentitletype }) } onclki=(bool)=>{ this.setState({ enlarge:bool }) } render() { let{ChallengesDataList,booljupyterurls,enlarge}=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) { } return (

简介 编辑
{this.state.opentitletype===true?:""}

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

}

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

加载实训失败,

this.updatamakedowns()}>重新加载

:"" ) :"" }
{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)}> }
this.modifyjupyter(this.state)}>

导入

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