/* * @Description: jupyter tpi * @Author: tangjiang * @Github: * @Date: 2019-12-11 08:35:23 * @LastEditors: tangjiang * @LastEditTime: 2019-12-13 15:25:50 */ import './index.scss'; import React, { useEffect, useState } from 'react'; import SplitPane from 'react-split-pane'; import { Button, Modal,Drawer ,Pagination,Empty,Tooltip,Icon,message,Statistic,Spin} from 'antd'; import { connect } from 'react-redux'; import FloatButton from '../../page/component/FloatButton'; import UserInfo from '../../developer/components/userInfo'; import actions from '../../../redux/actions'; import RightPane from './rightPane'; import MyIcon from "../../../common/components/MyIcon"; function clearSlct() { if("getSelection" in window){ window.getSelection().removeAllRanges(); }else{ document.selection.empty(); }; } function jsCopy(s) { clearSlct(); const copyEle = document.getElementById(s); copyEle.select(); const copyStatus=document.execCommand("Copy"); // 对成功与否定进行提示 copyStatuss(copyStatus) } function copyStatuss(copyStatus){ if (copyStatus) { message.success('复制成功'); } else { message.error('复制失败'); } } function JupyterTPI (props) { // 获取 identifier 值 const { match: { params = {} }, url, loading, // 保存按钮状态 total, pagination, dataSets, // 数据集 jupyter_info, getJupyterInfo, syncJupyterCode, jupyter_tpi_url_state, getJupyterTpiDataSet, getJupyterTpiUrl, saveJupyterTpi, changeLoadingState, changeGetJupyterUrlState, jupyter_identifier, changeCurrentPage, changeshowDrawer, drawervisible, reset_with_tpi, jupytertime, active_with_tpi, spinning, updataspinning, jupyter_folder_name } = props; const emptyCtx = (
); const { Countdown } = Statistic; const {identifier} = params; const [userInfo, setUserInfo] = useState({}); const [jupyterInfo, setJupyterInfo] = useState({}); const [updateTip, setUpdateTip] = useState(true); const [myIdentifier, setMyIdentifier] = useState(''); const [renderCtx, setRenderCtx] = useState(() => (emptyCtx)); let newHandletype=false const newHandle = function (event) { if(newHandletype===false){ newHandletype=true saveJupyterTpi(event); setTimeout(()=>{newHandletype=false},500) } } // 保存代码 const addEventListeners = () => { window.addEventListener('message', (e) => { // console.log("触发了jupytermessage"); if(e){ if(e.data){ if(e.data==="jupytermessage"){ newHandle() } } } }) } const stopposttpip=(sum)=>{ var _iframe = document.getElementById("rightPaneframe"); if(_iframe == null || _iframe == undefined || _iframe == ""){ return; } if(sum===1){ _iframe.contentWindow.postMessage("stopParent", "*"); }else{ _iframe.contentWindow.postMessage("clonsParent", "*"); } } useEffect(() => { addEventListeners() }, []); useEffect(() => { /* 先调用 jupyter的 TPI 接口, * 获取 用户信息, * 实训的 identifier, 状态, 名称, 是否被修改等信息 */ getJupyterInfo(identifier); }, [identifier]); useEffect(() => { // 设置jupyter信息 setJupyterInfo(jupyter_info || {}); const {user, tpm_modified, myshixun_identifier} = jupyter_info; if (user) { setUserInfo(user); } if (myshixun_identifier) { setMyIdentifier(myshixun_identifier); } // 同步代码 if (tpm_modified && updateTip && myshixun_identifier) { setUpdateTip(false); updataspinning(true) Modal.confirm({ title: '更新通知', content: (
{stopposttpip(1)}

该实训已更新,您选择更新后之前编写的实训代码将会丢失

如有需要请先使用【jupyter中-文件-下载】保存代码,再进行更新

{/*

还未完成评测的任务代码,请自行保存

*/}
), okText: '立即更新', cancelText: '稍后再说', onOk () { syncJupyterCode(myshixun_identifier, '同步成功'); },onCancel() { updataspinning(false) stopposttpip(2) }, }) } }, [props]); // 重置实训 const handleClickResetTpi = () => { stopposttpip(1) Modal.confirm({ title: '重置实训', content: (

你在本文件中修改的内容将丢失,
是否确定重新加载初始代码?

), okText: '确定', cancelText: '取消', onOk () { console.log('调用重置代码....', myIdentifier); if (myIdentifier) { syncJupyterCode(myIdentifier, '重置成功'); } }, onCancel() { stopposttpip(2) }, }) } // 重置环境 const handleEnvironmentTpi = () => { stopposttpip(1) updataspinning(true) Modal.confirm({ title: '重置环境', content: (

是否确定重置环境?

), okText: '确定', cancelText: '取消', onOk () { console.log('调用重置代码....', myIdentifier); // if (myIdentifier) { // // } reset_with_tpi(myIdentifier, '重置成功'); }, onCancel() { updataspinning(false) stopposttpip(2) }, }) } // 退出实训 const handleClickQuitTpi = () => { // console.log(jupyterInfo); const { identifier } = jupyterInfo; if (!identifier) return; props.history.push(`/shixuns/${identifier}/challenges`); } // 重新获取 jupyter url const handleOnReloadUrl = (id) => { // console.log('jupyter 信息: ', jupyterInfo); // 改变加载状态值 changeGetJupyterUrlState(-1); getJupyterTpiUrl({identifier: myIdentifier}); } // 保存代码 const handleOnSave = () => { // 改变按钮状态 changeLoadingState(true); saveJupyterTpi(); } // 分页信息改变时 const handlePageChange = (current) => { // 改变当前页 changeCurrentPage(current); // 分页查找数据 getJupyterTpiDataSet(jupyter_identifier); } const swtichFirstDrawer = () => { changeshowDrawer(!drawervisible) } const firstDrawerWidth = ()=>{ return 260 }; let newPage=false // 分页处理 const handleChangePage = (e,page) => { //滑动到底判断 let newscrollTop=parseInt(e.currentTarget.scrollTop); let allclientHeight=e.currentTarget.clientHeight+newscrollTop; if(dataSets.length { if (dataSets.length > 0) { // console.log('数据集的个数: ', dataSets.length); const oList = dataSets.map((item, i) => { return (
  • {item.title} { jsCopy("file_path"+i) }}>复制地址
  • ); }); const oUl = ( ); setRenderCtx(oUl); } }, [props]); const onFinish= () =>{ Modal.confirm({ title: '倒计时截止', content: (

    服务已中断,是否确认重置实验环境?

    ), okText: '确定', cancelText: '取消', onOk () { reset_with_tpi(myIdentifier, '重置成功'); // active_with_tpi(myIdentifier, '重置成功'); } }) } return (

    {jupyterInfo.name}

    {/*sync | poweroff */}

    {/*
    */} {/* */} {/*
    */} {"数据集"}
    {/*

    */}

    {/**/} 数据集 {/* 数据集 */}

    {dataSets&&dataSets.length===0?"":

    文件路径

    } { renderCtx } {/*
    */} {/* {total<20?"":}*/} {/*
    */}
    ); } const mapStateToProps = (state) => { const { jupyter_info, jupyter_tpi_url, jupyter_data_set, jupyter_tpi_url_state, jupyter_data_set_count, jupyter_folder_name, jupyter_pagination, jupyter_identifier } = state.jupyterReducer; const { loading ,drawervisible,jupytertime,spinning} = state.commonReducer; return { loading, jupyter_info, url: jupyter_tpi_url, dataSets: jupyter_data_set, jupyter_tpi_url_state, total: jupyter_data_set_count, pagination: jupyter_pagination, jupyter_folder_name:jupyter_folder_name, jupyter_identifier, drawervisible, jupytertime, spinning }; } const mapDispatchToProps = (dispatch) => ({ changeGetJupyterUrlState: (status) => dispatch(actions.changeGetJupyterUrlState(status)), getJupyterInfo: (identifier) => dispatch(actions.getJupyterInfo(identifier)), // 重置代码 syncJupyterCode: (identifier, msg) => dispatch(actions.syncJupyterCode(identifier, msg)), // 重置代码 reset_with_tpi: (identifier, msg) => dispatch(actions.reset_with_tpi(identifier, msg)), getJupyterTpiDataSet: (identifier, current) => dispatch(actions.getJupyterTpiDataSet(identifier, current)), getJupyterTpiUrl: (identifier) => dispatch(actions.getJupyterTpiUrl(identifier)), saveJupyterTpi: () => dispatch(actions.saveJupyterTpi()), changeLoadingState: (flag) => dispatch(actions.changeLoadingState(flag)), changeCurrentPage: (current) => dispatch(actions.changeCurrentPage(current)), //展开Drawer changeshowDrawer: (type) => dispatch(actions.changeshowDrawer(type)), //倒计时增加 addjypertime: (type) => dispatch(actions.addjypertime(type)), //延时 active_with_tpi:(identifier, msg) => dispatch(actions.active_with_tpi(identifier, msg)), updataspinning:(identifier, msg) => dispatch(actions.updataspinning(identifier, msg)), }); export default connect( mapStateToProps, mapDispatchToProps )(JupyterTPI);