加载中,

tpi  this.props.shixun.code_edit_permission
dev_local_2
hjm 5 years ago
parent 0b5f75eea8
commit 335a3b4378

@ -268,12 +268,14 @@ pop_box_new(htmlvalue, 480, 182);
}); });
} }
onPathChange(index) { onPathChange(index, callback) {
let { challenge } = this.state; let { challenge } = this.state;
// challenge = Object.assign({}, challenge) // challenge = Object.assign({}, challenge)
// challenge.pathIndex = index; // challenge.pathIndex = index;
this.setState({ this.setState({
challenge: update(challenge, {pathIndex: { $set: index }}), challenge: update(challenge, {pathIndex: { $set: index }}),
}, () => {
callback && callback()
}) })
// TODO load new path content // TODO load new path content
} }

@ -207,12 +207,13 @@ class MainContentContainer extends Component {
if (newProps.game && newProps.st === 0) { if (newProps.game && newProps.st === 0) {
if (!this.props || !this.props.game if (!this.props || !this.props.game
|| ( newProps.game.identifier !== this.props.game.identifier ) ) { || ( newProps.game.identifier !== this.props.game.identifier ) ) {
setTimeout(this.fetchRepositoryCode( newProps), 1500);
} else if ( this.props.challenge.pathIndex != newProps.challenge.pathIndex
&& newProps.challenge.pathIndex !== -1) { // 切换到只读文件
// pathIndex切换
setTimeout(this.fetchRepositoryCode( newProps), 1500); setTimeout(this.fetchRepositoryCode( newProps), 1500);
} }
// else if ( this.props.challenge.pathIndex != newProps.challenge.pathIndex
// && newProps.challenge.pathIndex !== -1) { // 切换到只读文件
// pathIndex切换
// setTimeout(this.fetchRepositoryCode( newProps), 1500);
// }
} }
if (newProps.myshixun) { if (newProps.myshixun) {
var stageId = newProps.match.params.stageId; var stageId = newProps.match.params.stageId;
@ -231,7 +232,11 @@ class MainContentContainer extends Component {
// 切换关卡时,停止轮训 // 切换关卡时,停止轮训
this.oldGameIdentifier = prevProps.game.identifier; this.oldGameIdentifier = prevProps.game.identifier;
this.doFileUpdateRequestOnCodeMirrorBlur(prevProps) this.doFileUpdateRequestOnCodeMirrorBlur(prevProps)
} else if (challenge && (challenge.pathIndex || prevProps.challenge.pathIndex) && challenge.pathIndex != prevProps.challenge.pathIndex) { }
// else if (this.props.shixun && this.props.shixun.code_edit_permission && this.state.currentPath != prevState.currentPath) {
// this.doFileUpdateRequestOnCodeMirrorBlur(prevProps)
// }
else if (challenge && (challenge.pathIndex || prevProps.challenge.pathIndex) && challenge.pathIndex != prevProps.challenge.pathIndex) {
this.doFileUpdateRequestOnCodeMirrorBlur(prevProps) this.doFileUpdateRequestOnCodeMirrorBlur(prevProps)
} }
@ -253,6 +258,9 @@ class MainContentContainer extends Component {
this.setState({ codeLoading: false }); this.setState({ codeLoading: false });
return; return;
} }
if (type && arg_path) {
this.doFileUpdateRequestOnCodeMirrorBlur(this.props)
}
const stageId = game.identifier const stageId = game.identifier
let path; let path;
let isEditablePath = false; let isEditablePath = false;
@ -535,7 +543,9 @@ class MainContentContainer extends Component {
this.oldRepositoryCode = codeContent; this.oldRepositoryCode = codeContent;
let argPath; let argPath;
if (challenge.pathIndex === -1) { // 当前是只读文件 if (this.props.shixun && this.props.shixun.code_edit_permission == true) {
argPath = this.state.currentPath
} else if (challenge.pathIndex === -1) { // 当前是只读文件
argPath = challenge.multiPath === true ? challenge.path[0] : challenge.path argPath = challenge.multiPath === true ? challenge.path[0] : challenge.path
} else { } else {
argPath = challenge.multiPath === true ? challenge.path[challenge.pathIndex] : challenge.path argPath = challenge.multiPath === true ? challenge.path[challenge.pathIndex] : challenge.path
@ -624,6 +634,11 @@ class MainContentContainer extends Component {
gameBuilding: false gameBuilding: false
}) })
} }
onPathChange = (index, isDropDown) => {
this.props.onPathChange(index, () => {
isDropDown && this.fetchRepositoryCode()
})
}
onRunCodeTest() { onRunCodeTest() {
// tipContent(0, 100, 30, 360, 1) // tipContent(0, 100, 30, 360, 1)
// return; // for test // return; // for test
@ -634,7 +649,7 @@ class MainContentContainer extends Component {
showDialog({ showDialog({
contentText: '需要先切回可编辑的文件才可评测,确认要现在切换吗?', contentText: '需要先切回可编辑的文件才可评测,确认要现在切换吗?',
callback: () => { callback: () => {
onPathChange(0) this.onPathChange(0, true)
handleGdialogClose(); handleGdialogClose();
} }
}) })
@ -957,7 +972,9 @@ class MainContentContainer extends Component {
onRepositoryCodeUpdate={this.onRepositoryCodeUpdate} onRunCodeTest={this.onRunCodeTest} onRepositoryCodeUpdate={this.onRepositoryCodeUpdate} onRunCodeTest={this.onRunCodeTest}
codemirrorDidMount={this.codemirrorDidMount} fetchRepositoryCode={this.fetchRepositoryCode} codemirrorDidMount={this.codemirrorDidMount} fetchRepositoryCode={this.fetchRepositoryCode}
showResetCodeDialog={this.showResetCodeDialog} showResetPassedCodeDialog={this.showResetPassedCodeDialog} showResetCodeDialog={this.showResetCodeDialog} showResetPassedCodeDialog={this.showResetPassedCodeDialog}
doFileUpdateRequestOnCodeMirrorBlur={this.doFileUpdateRequestOnCodeMirrorBlur} ></MainContent> doFileUpdateRequestOnCodeMirrorBlur={this.doFileUpdateRequestOnCodeMirrorBlur}
onPathChange={this.onPathChange}
></MainContent>
</React.Fragment> </React.Fragment>
); );

@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import axios from 'axios' import axios from 'axios'
import { Spin } from 'antd' import { Spin, Icon } from 'antd'
import ClipboardJS from 'clipboard' import ClipboardJS from 'clipboard'
import VNCDisplay from './VNCDisplay' import VNCDisplay from './VNCDisplay'
@ -22,7 +22,9 @@ class VNCContainer extends Component {
this.state = { this.state = {
fileTreeSelectedKeys: [], fileTreeSelectedKeys: [],
repositoryCode: '', repositoryCode: '',
displayKey: 1 displayKey: 1,
vnc_reseting: false,
} }
} }
componentDidMount() { componentDidMount() {
@ -116,6 +118,7 @@ class VNCContainer extends Component {
this.setState({ bottomDrawer: true }) this.setState({ bottomDrawer: true })
} }
onResetVNC = () => { onResetVNC = () => {
if (this.state.vnc_reseting) return;
// 桌面系统将恢复到初始状态,您在系统中创建的数据可能会丢失 // 桌面系统将恢复到初始状态,您在系统中创建的数据可能会丢失
// 请确保您的数据已保存(如:版本库代码已推送到服务器) // 请确保您的数据已保存(如:版本库代码已推送到服务器)
// 是否确认重置? // 是否确认重置?
@ -127,13 +130,15 @@ class VNCContainer extends Component {
</div>, </div>,
onOk: () => { onOk: () => {
const url = `/tasks/${this.props.game.identifier}/reset_vnc_link.json` const url = `/tasks/${this.props.game.identifier}/reset_vnc_link.json`
this.setState({ vnc_reseting: true })
axios.get(url, { axios.get(url, {
}).then((response) => { }).then((response) => {
if (response.data.data && response.data.data.vnc_url) { if (response.data.data && response.data.data.vnc_url) {
// reset // reset
this.setState({ this.setState({
displayKey: this.state.displayKey + 1, displayKey: this.state.displayKey + 1,
vnc_url: response.data.data.vnc_url vnc_url: response.data.data.vnc_url,
vnc_reseting: false
}) })
} else { } else {
} }
@ -141,7 +146,7 @@ class VNCContainer extends Component {
}).catch(error =>{ }).catch(error =>{
console.log(error) console.log(error)
this.setState({ readingCodeLoading: false }); this.setState({ vnc_reseting: false });
this.props.showSnackbar(`服务端异常,请联系管理员!`); this.props.showSnackbar(`服务端异常,请联系管理员!`);
}) })
@ -270,15 +275,23 @@ class VNCContainer extends Component {
></RepoTree> ></RepoTree>
</SecondDrawer> </SecondDrawer>
<FloatButton className="resetVNC" onClick={this.onResetVNC}> <FloatButton className="resetVNC" onClick={this.onResetVNC}>
<i className="iconfont icon-zhongzhi2 font-16 "></i> {/* <i className="iconfont icon-zhongzhi2 font-16 "></i> */}
{this.state.vnc_reseting ? <Icon type="loading" style={{verticalAlign: 'sub'}} />
: <i className="iconfont icon-zhongzhi2 font-16 "></i>}
<span>重置桌面系统</span> <span>重置桌面系统</span>
</FloatButton> </FloatButton>
{/* <Spin tip="..." spinning={this.state.vnc_reseting}>
</Spin> */}
<VNCDisplay <VNCDisplay
{...this.props} {...this.props}
key={this.state.displayKey} key={this.state.displayKey}
vnc_url={this.state.vnc_url || this.props.vnc_url} vnc_url={this.state.vnc_url || this.props.vnc_url}
> >
<Spin tip="加载中..." spinning={this.state.vnc_reseting}>
</Spin>
<Drawer <Drawer
mask={true} mask={true}
title="" title=""

@ -222,7 +222,7 @@ class TPIMonaco extends Component {
// https://github.com/Microsoft/monaco-editor/issues/539 // https://github.com/Microsoft/monaco-editor/issues/539
window.monaco.editor.setModelLanguage(editor_monaco.getModel(), lang) window.monaco.editor.setModelLanguage(editor_monaco.getModel(), lang)
} else if (prevProps.isEditablePath != this.props.isEditablePath) { } else if (prevProps.isEditablePath != this.props.isEditablePath) {
if (this.props.isEditablePath) { if (this.props.isEditablePath || this.props.shixun && this.props.shixun.code_edit_permission == true) {
editor_monaco.updateOptions({readOnly: false}) editor_monaco.updateOptions({readOnly: false})
} else { } else {
editor_monaco.updateOptions({readOnly: true}) editor_monaco.updateOptions({readOnly: true})
@ -271,7 +271,7 @@ class TPIMonaco extends Component {
const lang = getLanguageByMirrorName(this.props.mirror_name); const lang = getLanguageByMirrorName(this.props.mirror_name);
const editor = window.monaco.editor.create(document.getElementById('extend-challenge-file-edit'), { const editor = window.monaco.editor.create(document.getElementById('extend-challenge-file-edit'), {
value: value, value: value,
readOnly: !this.props.isEditablePath, readOnly: !this.props.isEditablePath && this.props.shixun && this.props.shixun.code_edit_permission != true,
// 属性说明 // 属性说明
// http://testeduplus2.educoder.net/react/build/static/node_modules/_monaco-editor@0.15.6@monaco-editor/esm/vs/editor/common/config/commonEditorConfig.js // http://testeduplus2.educoder.net/react/build/static/node_modules/_monaco-editor@0.15.6@monaco-editor/esm/vs/editor/common/config/commonEditorConfig.js
// https://github.com/Microsoft/monaco-editor/issues/29 // https://github.com/Microsoft/monaco-editor/issues/29

@ -157,13 +157,13 @@ class CodeRepositoryView extends Component {
} }
onPathChange(index) { onPathChange(index, isDropDown) {
const { challenge, onPathChange, doFileUpdateRequestOnCodeMirrorBlur } = this.props; const { challenge, onPathChange, doFileUpdateRequestOnCodeMirrorBlur } = this.props;
if (challenge.pathIndex !== index) { if (challenge.pathIndex !== index) {
// 切换时保存文件 // 切换时保存文件
// doFileUpdateRequestOnCodeMirrorBlur(true) // doFileUpdateRequestOnCodeMirrorBlur(true)
onPathChange(index) onPathChange(index, isDropDown)
} }
} }
@ -174,7 +174,7 @@ class CodeRepositoryView extends Component {
const pathArray = path.forEach ? path : [path] const pathArray = path.forEach ? path : [path]
pathArray.forEach( (item, index) => { pathArray.forEach( (item, index) => {
domArray.push( domArray.push(
<p key={index} className={classNames({'blue-line': pathIndex == index})} onClick={ () => this.onPathChange(index) } > <p key={index} className={classNames({'blue-line': pathIndex == index})} onClick={ () => this.onPathChange(index, true) } >
{item} {item}
</p> ) </p> )
}) })
@ -501,7 +501,8 @@ class CodeRepositoryView extends Component {
</Tooltip> </Tooltip>
} */} } */}
<div className="codemirrorBackground" <div className="codemirrorBackground"
style={{ backgroundImage: `url('${notEditablePathImg}')`, display: (isEditablePath ? 'none' : 'block') }}></div> style={{ backgroundImage: `url('${notEditablePathImg}')`
, display: (isEditablePath || this.props.shixun && this.props.shixun.code_edit_permission ? 'none' : 'block') }}></div>
{/*<textarea className = "" id="extend-challenge-file-edit" name="content">{repositoryCode}</textarea>*/} {/*<textarea className = "" id="extend-challenge-file-edit" name="content">{repositoryCode}</textarea>*/}
{/* cm monaco 切换 */} {/* cm monaco 切换 */}
{/* <TPICodeMirror {...this.props} ></TPICodeMirror> */} {/* <TPICodeMirror {...this.props} ></TPICodeMirror> */}

@ -231,12 +231,14 @@ class CodeRepositoryViewContainer extends Component {
const { fetchRepositoryCode, onPathChange, showSnackbar, challenge } = this.props; const { fetchRepositoryCode, onPathChange, showSnackbar, challenge } = this.props;
const nodePath = info.node.props.eventKey; const nodePath = info.node.props.eventKey;
let isCurrentFile = false;
// 设置pathIndex为-1那么代码文件下拉可以切回可编辑的文件 // 设置pathIndex为-1那么代码文件下拉可以切回可编辑的文件
if (!challenge.multiPath) { // 单path任务 多path任务 path是数组 if (!challenge.multiPath) { // 单path任务 多path任务 path是数组
if (challenge.path.trim() == nodePath.trim()) { if (challenge.path.trim() == nodePath.trim()) {
if (challenge.pathIndex === 0) { if (challenge.pathIndex === 0) {
showSnackbar(`当前编辑文件已经是${nodePath}`) showSnackbar(`当前编辑文件已经是${nodePath}`)
} else { } else {
fetchRepositoryCode(null, nodePath, 1);
onPathChange(0) onPathChange(0)
} }
return; return;
@ -244,7 +246,7 @@ class CodeRepositoryViewContainer extends Component {
onPathChange(-1) onPathChange(-1)
} }
} else { } else {
let isCurrentFile = false;
let cur_index = -1; let cur_index = -1;
if (challenge.path && challenge.path.forEach) { if (challenge.path && challenge.path.forEach) {
challenge.path.forEach((item, index) => { challenge.path.forEach((item, index) => {

Loading…
Cancel
Save