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

@ -5,23 +5,24 @@ var timebool=false;
window.onload=function(){ window.onload=function(){
console.log("开始发送消息了"); console.log("开始发送消息了");
timebool=true; timebool=true;
runEvery10Sec(); // runEvery10Sec();
} }
function runEvery10Sec() { function runEvery10Sec() {
// 1000 * 10 = 10 秒钟 // 1000 * 10 = 10 秒钟
console.log("每隔10秒中一次"); // console.log("每隔10秒中一次");
require(["base/js/namespace"],function(Jupyter) { require(["base/js/namespace"],function(Jupyter) {
Jupyter.notebook.save_checkpoint(); Jupyter.notebook.save_checkpoint();
}); });
window.parent.postMessage('jupytermessage','*'); window.parent.postMessage('jupytermessage','*');
if(timebool===true){ // if(timebool===true){
setTimeout( runEvery10Sec, 1000 * 10 ); // setTimeout( runEvery10Sec, 1000 * 10 );
} // }
} }
$(function(){ window.onload=function(){
document.addEventListener('keydown', (e) => { document.addEventListener('keydown', (e) => {
if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)){ if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)){
e.preventDefault(); e.preventDefault();
@ -29,6 +30,7 @@ document.addEventListener('keydown', (e) => {
window.parent.postMessage('jupytermessage','*'); window.parent.postMessage('jupytermessage','*');
} }
}); });
window.addEventListener('message', (e) => { window.addEventListener('message', (e) => {
if(e){ if(e){
if(e.data){ if(e.data){
@ -40,12 +42,10 @@ document.addEventListener('keydown', (e) => {
console.log("父窗口调用启动"); console.log("父窗口调用启动");
//取消启动 //取消启动
timebool=true; timebool=true;
runEvery10Sec(); // runEvery10Sec();
} }
} }
} }
}); });
}) }

@ -9,7 +9,7 @@
import './index.scss'; import './index.scss';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import SplitPane from 'react-split-pane'; 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 { import {
connect connect
} from 'react-redux'; } from 'react-redux';
@ -18,6 +18,7 @@ import UserInfo from '../../developer/components/userInfo';
import actions from '../../../redux/actions'; import actions from '../../../redux/actions';
import LeftPane from './leftPane'; import LeftPane from './leftPane';
import RightPane from './rightPane'; import RightPane from './rightPane';
const { Countdown } = Statistic;
import MyIcon from "../../../common/components/MyIcon"; import MyIcon from "../../../common/components/MyIcon";
function jsCopy(s) { function jsCopy(s) {
var copyEle = document.getElementById(s); var copyEle = document.getElementById(s);
@ -62,6 +63,7 @@ function JupyterTPI (props) {
changeCurrentPage, changeCurrentPage,
changeshowDrawer, changeshowDrawer,
drawervisible, drawervisible,
reset_with_tpi,
} = props; } = props;
const emptyCtx = ( 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(() => { useEffect(() => {
/* jupyter TPI /* jupyter TPI
* 获取 用户信息, * 获取 用户信息,
* 实训的 identifier, 状态 名称 是否被修改等信息 * 实训的 identifier, 状态 名称 是否被修改等信息
*/ */
addEventListeners()
getJupyterInfo(identifier); getJupyterInfo(identifier);
}, [identifier]); }, [identifier]);
useEffect(() => { useEffect(() => {
// 设置jupyter信息 // 设置jupyter信息
setJupyterInfo(jupyter_info || {}); setJupyterInfo(jupyter_info || {});
const {user, tpm_modified, myshixun_identifier} = jupyter_info; const {user, tpm_modified, myshixun_identifier} = jupyter_info;
@ -116,10 +135,12 @@ function JupyterTPI (props) {
// 同步代码 // 同步代码
if (tpm_modified && updateTip && myshixun_identifier) { if (tpm_modified && updateTip && myshixun_identifier) {
setUpdateTip(false); setUpdateTip(false);
Modal.confirm({ Modal.confirm({
title: '更新通知', title: '更新通知',
content: (<div className="update_notice"> content: (<div className="update_notice">
{stopposttpip(1)}
<p className="update_txt">关卡任务的代码文件有更新啦</p> <p className="update_txt">关卡任务的代码文件有更新啦</p>
<p className="update_txt">更新操作将保留已完成的评测记录和成绩</p> <p className="update_txt">更新操作将保留已完成的评测记录和成绩</p>
<p className="update_txt">还未完成评测的任务代码请自行保存</p> <p className="update_txt">还未完成评测的任务代码请自行保存</p>
@ -128,21 +149,17 @@ function JupyterTPI (props) {
cancelText: '取消', cancelText: '取消',
onOk () { onOk () {
syncJupyterCode(myshixun_identifier, '同步成功'); syncJupyterCode(myshixun_identifier, '同步成功');
} },onCancel() {
stopposttpip(2)
},
}) })
} }
}, [props]); }, [props]);
// 重置实训 // 重置实训
const handleClickResetTpi = () => { const handleClickResetTpi = () => {
stopposttpip(1)
var _iframe = document.getElementById("rightPaneframe");
if(_iframe == null || _iframe == undefined || _iframe == ""){
return;
}
_iframe.contentWindow.postMessage("stopParent", "*");
Modal.confirm({ Modal.confirm({
title: '重置实训', title: '重置实训',
content: ( content: (
@ -160,7 +177,7 @@ function JupyterTPI (props) {
} }
}, },
onCancel() { onCancel() {
_iframe.contentWindow.postMessage("clonsParent", "*"); stopposttpip(2)
}, },
}) })
} }
@ -168,6 +185,7 @@ function JupyterTPI (props) {
// 重置环境 // 重置环境
const handleEnvironmentTpi = () => { const handleEnvironmentTpi = () => {
stopposttpip(1)
Modal.confirm({ Modal.confirm({
title: '重置环境', title: '重置环境',
content: ( content: (
@ -179,11 +197,14 @@ function JupyterTPI (props) {
okText: '确定', okText: '确定',
cancelText: '取消', cancelText: '取消',
onOk () { onOk () {
// console.log('调用重置代码....', myIdentifier); console.log('调用重置代码....', myIdentifier);
// if (myIdentifier) { if (myIdentifier) {
// syncJupyterCode(myIdentifier, '重置成功'); reset_with_tpi(myIdentifier, '重置成功');
// }
} }
},
onCancel() {
stopposttpip(2)
},
}) })
} }
@ -265,14 +286,17 @@ function JupyterTPI (props) {
} }
}, [props]); }, [props]);
const deadline = Date.now() + 7200 * 1000; // Moment is also OK
return ( return (
<div className="jupyter_area"> <div className="jupyter_area">
<div className="jupyter_header"> <div className="jupyter_header">
<UserInfo userInfo={userInfo} /> <UserInfo userInfo={userInfo} />
<p className="jupyter_title"> <p className="jupyter_title">
<span className="title_desc" style={{ marginTop: '20px' }}>{jupyterInfo.name}</span> <span className="title_desc" style={{ marginTop: '10px' }}>{jupyterInfo.name}</span>
<span className="title_time"></span> <span className="title_time jupytertitle_time">
<Countdown value={deadline} format="HH:mm:ss" />
</span>
</p> </p>
<p className="jupyter_btn"> <p className="jupyter_btn">
{/* sync | poweroff */} {/* sync | poweroff */}
@ -384,6 +408,8 @@ const mapDispatchToProps = (dispatch) => ({
getJupyterInfo: (identifier) => dispatch(actions.getJupyterInfo(identifier)), getJupyterInfo: (identifier) => dispatch(actions.getJupyterInfo(identifier)),
// 重置代码 // 重置代码
syncJupyterCode: (identifier, msg) => dispatch(actions.syncJupyterCode(identifier, msg)), 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)), getJupyterTpiDataSet: (identifier, current) => dispatch(actions.getJupyterTpiDataSet(identifier, current)),
getJupyterTpiUrl: (identifier) => dispatch(actions.getJupyterTpiUrl(identifier)), getJupyterTpiUrl: (identifier) => dispatch(actions.getJupyterTpiUrl(identifier)),
saveJupyterTpi: () => dispatch(actions.saveJupyterTpi()), 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) => { window.addEventListener('message', (e) => {
console.log("触发了jupytermessage");
console.log(e); console.log(e);
if(e){ if(e){
if(e.data){ if(e.data){

@ -74,6 +74,7 @@ import {
saveJupyterTpi, saveJupyterTpi,
changeCurrentPage, changeCurrentPage,
changeshowDrawer, changeshowDrawer,
reset_with_tpi,
} from './jupyter'; } from './jupyter';
export default { export default {
@ -129,6 +130,7 @@ export default {
changeGetJupyterUrlState, changeGetJupyterUrlState,
saveJupyterTpi, saveJupyterTpi,
changeCurrentPage, changeCurrentPage,
changeshowDrawer changeshowDrawer,
reset_with_tpi
// isUpdateCodeCtx // isUpdateCodeCtx
} }

@ -13,6 +13,7 @@ import {
fetchJupyterTpiUrl, fetchJupyterTpiUrl,
fetchJupyterInfo, fetchJupyterInfo,
fetchSyncJupyterCode, fetchSyncJupyterCode,
fetchreset_with_tpi,
fetchSaveJupyterTpi fetchSaveJupyterTpi
} from "../../services/jupyterServer"; } 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) => { export const changeGetJupyterUrlState = (status) => {
return { return {

@ -34,8 +34,8 @@ export async function fetchSaveJupyterTpi (params) {
return axios.get(url, { params }); return axios.get(url, { params });
} }
// 重置jupyter 保存 //重置jupyter 环境
// export async function reset_with_tpi (params) { export async function fetchreset_with_tpi (params) {
// const url = `/jupyters/reset_with_tpi.json`; const url = `/jupyters/reset_with_tpi.json`;
// return axios.get(url, { params }); return axios.get(url, { params });
// } }
Loading…
Cancel
Save