chromesetting
杨树明 5 years ago
parent 99a49cc07f
commit 1c9491773c

@ -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();
}
}
}
});
})
}

@ -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: (<div className="update_notice">
{stopposttpip(1)}
<p className="update_txt">关卡任务的代码文件有更新啦</p>
<p className="update_txt">更新操作将保留已完成的评测记录和成绩</p>
<p className="update_txt">还未完成评测的任务代码请自行保存</p>
@ -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 (
<div className="jupyter_area">
<div className="jupyter_header">
<UserInfo userInfo={userInfo} />
<p className="jupyter_title">
<span className="title_desc" style={{ marginTop: '20px' }}>{jupyterInfo.name}</span>
<span className="title_time"></span>
<span className="title_desc" style={{ marginTop: '10px' }}>{jupyterInfo.name}</span>
<span className="title_time jupytertitle_time">
<Countdown value={deadline} format="HH:mm:ss" />
</span>
</p>
<p className="jupyter_btn">
{/* 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()),

@ -159,3 +159,12 @@
}
}
.jupytertitle_time{
.ant-statistic-content{
font-size: 20px !important;
}
.ant-statistic-content-value{
color:#fff !important;
font-size: 17px !important;
}
}

@ -146,7 +146,7 @@ class Challengesjupyter extends Component {
window.addEventListener('message', (e) => {
console.log("触发了jupytermessage");
console.log(e);
if(e){
if(e.data){

@ -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
}

@ -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 {

@ -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 });
// }
//重置jupyter 环境
export async function fetchreset_with_tpi (params) {
const url = `/jupyters/reset_with_tpi.json`;
return axios.get(url, { params });
}
Loading…
Cancel
Save