import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Drawer from 'material-ui/Drawer';
import { CircularProgress } from 'material-ui/Progress';
import Tooltip from 'material-ui/Tooltip';
import WebSSHTimer from '../component/WebSSHTimer'
import Webssh from './Webssh'
import Tree, { TreeNode } from 'rc-tree';
import 'rc-tree/assets/index.css';
import classNames from 'classnames'
// import CodeMirror from 'react-codeMirror'
import axios from 'axios'
import _ from 'lodash'
import notEditablePathImg from '../../../images/tpi/notEditablePath.png'
import TPICodeMirror from '../component/TPICodeMirror'
import TPIMonaco from '../component/monaco/TPIMonaco'
import { loadSshScript, openTerminal } from './Webssh'
const $ = window.$;
const STABLE_SSH_TAB_ID = 81
const addtionalSSHStartId = 82;
const totalAddtionalTabCount = 2;
let addtionalSSHIdMap = {
82: false,
83: false,
// 84: false,
// 85: false,
// 86: false,
};
class CodeRepositoryView extends Component {
constructor(props) {
super(props);
this.treeExpanded = false;
this.state = {
autoExpandParent: false,
expandedKeys: [],
addtionalSSHArray: [],
sshIsClosed: false
}
}
componentDidUpdate(prevProps, prevState, snapshot) {
const { game, challenge, hide_code, tabIndex, } = this.props
if ( // 初始化 或者 game切换
!this.treeExpanded && challenge.path && challenge.path.length && this.state.expandedKeys.length === 0 ||
game && (!prevProps.game
|| prevProps.game.identifier !== this.props.game.identifier) ) {
if (!this.treeExpanded) {
this.treeExpanded = true
const _path = challenge.multiPath ? challenge.path[0] : challenge.path;
let _ar = [];
const expandedKeys = [];
if (_path) {
_ar = _path.split('/')
_ar.length = _ar.length - 1
_ar.forEach( (item, index) => {
expandedKeys.push( index === 0 ? item : expandedKeys[index - 1] + '/' + item)
})
}
expandedKeys.length = 1 // 没办法做到多级初始化,而且会引起点击其他子目录,加载当前文件目录的问题
// 初始化时无法展开到根节点 https://github.com/fis-components/rc-tree/issues/3
expandedKeys.length && this.setState({
expandedKeys,
})
}
if (game && (!prevProps.game
|| prevProps.game.identifier !== this.props.game.identifier)) {
// 切换关卡时切换到第一个tab
// 如果隐藏code tab,就只有一个ssh tab了
if (hide_code == true) {
this.props.tabIndexChange(81);
} else if (hide_code == undefined || hide_code == false || tabIndex !== 0) { // 不加if会有死循环
this.props.tabIndexChange(0);
}
}
}
}
componentDidMount() {
// 隐藏code tab,则显示ssh tab(81)
if (this.props.hide_code === true) {
this.tabIndexChange(81)
}
//显示所有代码文件
$(".code-file-tab").hover(function(){
// var ulwidth=$("#blacktab_nav").width();
// $(".code-flie-list").width(ulwidth);
$(".code-flie-list").show();
$(this).find("i")
.addClass("codeRepoShow")
// .removeClass("fa-caret-right").addClass("fa-caret-down");
},function(){
$(".code-flie-list").hide();
$(".code-file-tab").find("i")
.removeClass("codeRepoShow")
// .removeClass("fa-caret-down").addClass("fa-caret-right");
})
// $('#codetab_con_1').append(``)
// $('#codetab_con_1 .codemirrorBackground').hide()
}
onTreeSelect = (selectedKeys, info) => {
if (!info.node.isLeaf()) {
const expandedKeys = this.state.expandedKeys.slice(0)
const _index = expandedKeys.indexOf(selectedKeys[0]);
if (_index == -1) {
expandedKeys.push(selectedKeys[0])
} else {
expandedKeys.splice( _index, 1)
}
this.setState({ expandedKeys })
}
this.props.onTreeSelect(selectedKeys, info)
}
buildTree() {
// TODO http://localhost:3007/tasks/xgffnuomytpj 这个实训没有文件树
const { fileTreeData, onLoadData, fileTreeSelectedKeys } = this.props;
if (!fileTreeData || fileTreeData.length === 0) {
return ""
}
const loop = (data) => {
return data.map((item) => {
if (item.children) {
return
this.onPathChange(index, true) } > {item}
) }) return (请点击文件名称切换代码显示,代表当前显示的代码文件
*/ const { tpm_cases_modified, tpm_modified, tpm_script_modified, myshixun, onShowUpdateDialog } = this.props; let needUpdateScript = (tpm_modified || tpm_script_modified) && challenge.st === 0; const showUpdateButton = (tpm_cases_modified || needUpdateScript) && myshixun.system_tip === true; const { addtionalSSHArray, sshIsClosed } = this.state; // shixun.multi_webssh = true; return (