diff --git a/public/javascripts/jupyter.js b/public/javascripts/jupyter.js index c55830c44..5ffd34dd4 100644 --- a/public/javascripts/jupyter.js +++ b/public/javascripts/jupyter.js @@ -5,23 +5,24 @@ var timebool=false; window.onload=function(){ console.log("开始发送消息了"); timebool=true; - runEvery10Sec(); + // runEvery10Sec(); } function runEvery10Sec() { // 1000 * 10 = 10 秒钟 - console.log("每隔10秒中一次"); + // console.log("每隔10秒中一次"); require(["base/js/namespace"],function(Jupyter) { Jupyter.notebook.save_checkpoint(); }); window.parent.postMessage('jupytermessage','*'); - if(timebool===true){ - setTimeout( runEvery10Sec, 1000 * 10 ); - } + // if(timebool===true){ + // setTimeout( runEvery10Sec, 1000 * 10 ); + // } } -$(function(){ +window.onload=function(){ + document.addEventListener('keydown', (e) => { if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)){ e.preventDefault(); @@ -29,6 +30,7 @@ document.addEventListener('keydown', (e) => { window.parent.postMessage('jupytermessage','*'); } }); + window.addEventListener('message', (e) => { if(e){ if(e.data){ @@ -40,12 +42,10 @@ document.addEventListener('keydown', (e) => { console.log("父窗口调用启动"); //取消启动 timebool=true; - runEvery10Sec(); + // runEvery10Sec(); } } } }); -}) - - +} diff --git a/public/react/src/modules/tpm/jupyter/index.js b/public/react/src/modules/tpm/jupyter/index.js index b5c1ff217..4a18f5ac3 100644 --- a/public/react/src/modules/tpm/jupyter/index.js +++ b/public/react/src/modules/tpm/jupyter/index.js @@ -9,7 +9,7 @@ import './index.scss'; import React, { useEffect, useState } from 'react'; import SplitPane from 'react-split-pane'; -import { Button, Modal,Drawer ,Pagination,Empty,Tooltip,Icon,message} from 'antd'; +import { Button, Modal,Drawer ,Pagination,Empty,Tooltip,Icon,message,Statistic} from 'antd'; import { connect } from 'react-redux'; @@ -18,6 +18,7 @@ import UserInfo from '../../developer/components/userInfo'; import actions from '../../../redux/actions'; import LeftPane from './leftPane'; import RightPane from './rightPane'; +const { Countdown } = Statistic; import MyIcon from "../../../common/components/MyIcon"; function jsCopy(s) { var copyEle = document.getElementById(s); @@ -62,6 +63,7 @@ function JupyterTPI (props) { changeCurrentPage, changeshowDrawer, drawervisible, + reset_with_tpi, } = props; const emptyCtx = ( @@ -89,20 +91,37 @@ function JupyterTPI (props) { } - }); + }) } + 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 接口, - * 获取 用户信息, + /* 先调用 jupyter的 TPI 接口, + * 获取 用户信息, * 实训的 identifier, 状态, 名称, 是否被修改等信息 */ - addEventListeners() getJupyterInfo(identifier); }, [identifier]); useEffect(() => { + // 设置jupyter信息 setJupyterInfo(jupyter_info || {}); const {user, tpm_modified, myshixun_identifier} = jupyter_info; @@ -116,10 +135,12 @@ function JupyterTPI (props) { // 同步代码 if (tpm_modified && updateTip && myshixun_identifier) { + setUpdateTip(false); Modal.confirm({ title: '更新通知', content: (
关卡任务的代码文件有更新啦
更新操作将保留已完成的评测记录和成绩
还未完成评测的任务代码,请自行保存
@@ -128,21 +149,17 @@ function JupyterTPI (props) { cancelText: '取消', onOk () { syncJupyterCode(myshixun_identifier, '同步成功'); - } + },onCancel() { + stopposttpip(2) + }, }) } }, [props]); + // 重置实训 const handleClickResetTpi = () => { - - var _iframe = document.getElementById("rightPaneframe"); - if(_iframe == null || _iframe == undefined || _iframe == ""){ - return; - } - _iframe.contentWindow.postMessage("stopParent", "*"); - - + stopposttpip(1) Modal.confirm({ title: '重置实训', content: ( @@ -160,7 +177,7 @@ function JupyterTPI (props) { } }, onCancel() { - _iframe.contentWindow.postMessage("clonsParent", "*"); + stopposttpip(2) }, }) } @@ -168,6 +185,7 @@ function JupyterTPI (props) { // 重置环境 const handleEnvironmentTpi = () => { + stopposttpip(1) Modal.confirm({ title: '重置环境', content: ( @@ -179,11 +197,14 @@ function JupyterTPI (props) { okText: '确定', cancelText: '取消', onOk () { - // console.log('调用重置代码....', myIdentifier); - // if (myIdentifier) { - // syncJupyterCode(myIdentifier, '重置成功'); - // } - } + console.log('调用重置代码....', myIdentifier); + if (myIdentifier) { + reset_with_tpi(myIdentifier, '重置成功'); + } + }, + onCancel() { + stopposttpip(2) + }, }) } @@ -265,14 +286,17 @@ function JupyterTPI (props) { } }, [props]); + const deadline = Date.now() + 7200 * 1000; // Moment is also OK return (
- {jupyterInfo.name}
-
+ {jupyterInfo.name}
+
+
{/* sync | poweroff */} @@ -384,6 +408,8 @@ const mapDispatchToProps = (dispatch) => ({ 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()), diff --git a/public/react/src/modules/tpm/jupyter/index.scss b/public/react/src/modules/tpm/jupyter/index.scss index 76c8bedd1..2fbb0f4fd 100644 --- a/public/react/src/modules/tpm/jupyter/index.scss +++ b/public/react/src/modules/tpm/jupyter/index.scss @@ -159,3 +159,12 @@ } } +.jupytertitle_time{ + .ant-statistic-content{ + font-size: 20px !important; + } + .ant-statistic-content-value{ + color:#fff !important; + font-size: 17px !important; + } +} \ No newline at end of file diff --git a/public/react/src/modules/tpm/shixunchild/Challenges/Challengesjupyter.js b/public/react/src/modules/tpm/shixunchild/Challenges/Challengesjupyter.js index a08825936..5fcc53bd3 100644 --- a/public/react/src/modules/tpm/shixunchild/Challenges/Challengesjupyter.js +++ b/public/react/src/modules/tpm/shixunchild/Challenges/Challengesjupyter.js @@ -146,7 +146,7 @@ class Challengesjupyter extends Component { window.addEventListener('message', (e) => { - console.log("触发了jupytermessage"); + console.log(e); if(e){ if(e.data){ diff --git a/public/react/src/redux/actions/index.js b/public/react/src/redux/actions/index.js index 23647ec4a..6b8f01fa5 100644 --- a/public/react/src/redux/actions/index.js +++ b/public/react/src/redux/actions/index.js @@ -74,6 +74,7 @@ import { saveJupyterTpi, changeCurrentPage, changeshowDrawer, + reset_with_tpi, } from './jupyter'; export default { @@ -129,6 +130,7 @@ export default { changeGetJupyterUrlState, saveJupyterTpi, changeCurrentPage, - changeshowDrawer + changeshowDrawer, + reset_with_tpi // isUpdateCodeCtx } \ No newline at end of file diff --git a/public/react/src/redux/actions/jupyter.js b/public/react/src/redux/actions/jupyter.js index 73bc30a42..22804be51 100644 --- a/public/react/src/redux/actions/jupyter.js +++ b/public/react/src/redux/actions/jupyter.js @@ -13,6 +13,7 @@ import { fetchJupyterTpiUrl, fetchJupyterInfo, fetchSyncJupyterCode, + fetchreset_with_tpi, fetchSaveJupyterTpi } from "../../services/jupyterServer"; @@ -110,6 +111,30 @@ export const syncJupyterCode = (identifier, msg) => { }) } } + +// 重置环境 +export const reset_with_tpi = (identifier, msg) => { + return (dispatch,getState) => { + const {jupyter_info }= getState().jupyterReducer; + if (!jupyter_info.myshixun_identifier) return; + const params = { + identifier: jupyter_info.myshixun_identifier, + }; + fetchreset_with_tpi(params).then(res => { + // console.log('同步代码成功: ', res); + if (res.data.status === 401) return; + if (res.status === 200) { + const {status} = res.data + if (status === 0) { + message.success(msg); + setTimeout(() => { + window.location.reload(); + }, 300); + } + } + }) + } +} // 改变状态值 export const changeGetJupyterUrlState = (status) => { return { diff --git a/public/react/src/services/jupyterServer.js b/public/react/src/services/jupyterServer.js index 059aace5e..8f512d8ef 100644 --- a/public/react/src/services/jupyterServer.js +++ b/public/react/src/services/jupyterServer.js @@ -34,8 +34,8 @@ export async function fetchSaveJupyterTpi (params) { return axios.get(url, { params }); } -// 重置jupyter 保存 -// export async function reset_with_tpi (params) { -// const url = `/jupyters/reset_with_tpi.json`; -// return axios.get(url, { params }); -// } \ No newline at end of file +//重置jupyter 环境 +export async function fetchreset_with_tpi (params) { + const url = `/jupyters/reset_with_tpi.json`; + return axios.get(url, { params }); +} \ No newline at end of file