Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_hss
caicai8 5 years ago
commit 8199d3abd5

@ -30,7 +30,7 @@ class Users::QuestionBanksController < Users::BaseController
.where(commit_status: 1, exercises: { exercise_bank_id: question_bank_ids })
.group('exercises.exercise_bank_id').count
when 'poll' then
PollUser.joins(:poll).where(polls: { exercise_bank_id: question_bank_ids })
PollUser.joins(:poll).where(commit_status: 1, polls: { exercise_bank_id: question_bank_ids })
.group('polls.exercise_bank_id').count
when 'gtask' then
GraduationWork.has_committed.joins(:graduation_task)

@ -24,7 +24,7 @@ module Searchable::Course
author_name: teacher&.real_name,
author_school_name: teacher&.school_name,
visits_count: visits,
members_count: members_count,
members_count: course_members_count,
is_public: is_public == 1,
first_category_url: ApplicationController.helpers.module_url(none_hidden_course_modules.first, self)
}

@ -0,0 +1,28 @@
class MigrateBankQuotes < ActiveRecord::Migration[5.2]
def change
HomeworkBank.all.each do |bank|
task_count = bank.homework_commons.count
bank.update_column("quotes", task_count == 0 ? 1 : task_count)
end
GtopicBank.all.each do |bank|
task_count = bank.graduation_topics.count
bank.update_column("quotes", task_count == 0 ? 1 : task_count)
end
GtaskBank.all.each do |bank|
task_count = bank.graduation_tasks.count
bank.update_column("quotes", task_count == 0 ? 1 : task_count)
end
ExerciseBank.all.each do |bank|
if bank.container_type == 'Exercise'
task_count = bank.exercises.count
bank.update_column("quotes", task_count == 0 ? 1 : task_count)
elsif bank.container_type == 'Poll'
task_count = bank.polls.count
bank.update_column("quotes", task_count == 0 ? 1 : task_count)
end
end
end
end

@ -62,7 +62,7 @@ module.exports = {
// We generate sourcemaps in production. This is slow but gives good results.
// You can exclude the *.map files from the build during deployment.
// devtool: shouldUseSourceMap ? 'nosources-source-map' : false, //正式版
devtool: shouldUseSourceMap ? 'source-map' : false,//测试版
devtool: shouldUseSourceMap ? 'source-map' : 'source-map',//测试版
// In production, we only want to load the polyfills and the app code.
entry: [require.resolve('./polyfills'), paths.appIndexJs],
output: {

@ -450,6 +450,7 @@ class NewWorkForm extends Component{
className="AboutInputForm groupSetting"
>
{getFieldDecorator('personNum', {
validateTrigger: 'onNone',
rules: [{
// required: true,
// message: '人数不能为空'

@ -6,6 +6,7 @@ import axios from 'axios';
import TPMMDEditor from "../../tpm/challengesnew/TPMMDEditor";
import moment from "../new/CoursesNew";
import Fileslistitem from "../Resource/Fileslistitem";
import Modals from "../../modals/Modals";
// 公告栏
class Bullsubdirectory extends Component{
constructor(props){
@ -19,6 +20,10 @@ class Bullsubdirectory extends Component{
addonAfter:0,
eduintits:"",
informs:[],
Modalstype:false,
Modalstopval:"是否确认删除?",
ModalCancel:"",
ModalSave:"",
}
@ -47,6 +52,61 @@ class Bullsubdirectory extends Component{
}
setModeltrue=()=>{
this.setState({
Modalstype:true,
Modalstopval:"是否确认删除?",
ModalCancel:this.cancelmodel,
ModalSave:this.saveonOpen,
})
}
cancelmodel=()=>{
//取消
this.setState({
Modalstype:false,
Modalstopval:"是否确认删除?",
ModalCancel:"",
ModalSave:"",
})
}
saveonOpen=()=>{
//确认
// /
// 删除公告
var id=this.props.match.params.coursesId
const url =`/courses/${id}/delete_informs.json`;
axios.delete(url, { data: {
inform_id: this.props.id
}})
.then((response) => {
if(response){
if(response.data){
if(response.data.status===0){
this.setState({
Modalstype:false,
Modalstopval:"是否确认删除?",
ModalCancel:"",
ModalSave:"",
})
this.props.showNotification(`删除成功`);
this.props.getinputdata();
}else{
this.props.showNotification(`删除失败`);
}
}else{
this.props.showNotification(`删除失败`);
}
}
})
.catch(function (error) {
console.log(error);
this.props.showNotification(`删除失败`);
});
}
bianji = (bians)=>{
this.setState({
@ -113,7 +173,7 @@ class Bullsubdirectory extends Component{
}
var url = `/courses/${id}/update_informs.json`;
axios.post(url,{
inform_id:this.state.id,
inform_id:this.props.id,
name:titname,
description:values.description,
}).then((result) => {
@ -154,12 +214,18 @@ class Bullsubdirectory extends Component{
render(){
let{description,whethertoeditysl,addonAfter,eduintits,informs,isSpinysl} =this.state;
let{myname,mydescription}=this.props;
let{myname,mydescription,id}=this.props;
const {getFieldDecorator} = this.props.form;
return(
<React.Fragment >
<div >
{this.state.Modalstype&&this.state.Modalstype===true?<Modals
modalsType={this.state.Modalstype}
modalsTopval={this.state.Modalstopval}
modalCancel={this.state.ModalCancel}
modalSave={this.state.ModalSave}
/>:""}
<Spin size="large" spinning={isSpinysl} >
<div className="edu-back-white ">
{
@ -171,16 +237,29 @@ class Bullsubdirectory extends Component{
<span className="ysltitbt">{myname}</span>
</div>
<div>
<span className="fr pr25 yslbianji">
<span className="fr yslbianji" style={{marginRight:"17px"}}>
{
this.props.isAdmin() === true ?
this.props.isClassManagement() === true ?
(this.props.yslbool===false?
<i className="iconfont icon-bianji1 newbianji1" onClick={()=>this.bianji(true)}></i>
:
""
)
:""
}
</span>
<span className="fr yslbianji" style={{marginRight:"22px"}}>
{
this.props.isClassManagement() === true ?
(this.props.yslbool===false?
<i className="iconfont icon-shanchu newbianji1" style={{ color: "#4CACFF"}} onClick={()=>this.setModeltrue(true)}></i>
:
""
)
:""
}
</span>
</div>
<div className="yslclear"></div>

@ -82,11 +82,16 @@ class GroupPackage extends Component {
</p>
}
{
datas&&datas.group_info&&datas.group_info.base_on_project?
datas&&datas.group_info&&datas.group_info.base_on_project===1?
<p>
<span className="ysltextcolor66">基于项目实施</span>
<span className="ysltextcolor05">学生必须在本平台创建项目项目管理员可以提交作品</span>
</p>
:datas&&datas.group_info&&datas.group_info.base_on_project===0?
<p>
<span className="ysltextcolor66">基于项目实施</span>
<span className="ysltextcolor05">无需在平台创建项目任意小组成员均可以提交作品</span>
</p>
:""
}
</div>

@ -251,16 +251,19 @@ class Listofworksstudentone extends Component {
textAlign: "center"
}
}>
{record.cost_time === null? "--":record.cost_time === undefined?"--":
<a style={
{
color: '#747A7F',
textAlign: "center"
{record.cost_time === null? "--":record.cost_time === undefined?"--":record.cost_time === "--"?"--":
<Tooltip placement="bottom" title={<div>
学员在EduCoder做实训花费的时间
</div>}>
<span style={
{
color: '#747A7F',
textAlign: "center"
}
}
}
title={"学员在EduCoder做实训花费的时间"}
>{record.cost_time === null ? "--":record.cost_time === undefined ?"--":record.cost_time}
</a>
>{record.cost_time === null ? "--":record.cost_time === undefined ?"--":record.cost_time}
</span>
</Tooltip>
}
</span>
)
@ -524,16 +527,19 @@ class Listofworksstudentone extends Component {
textAlign: "center"
}
}>
{record.cost_time === null? "--":record.cost_time === undefined?"--":
{record.cost_time === null? "--":record.cost_time === undefined?"--":record.cost_time === "--"?"--":
<Tooltip placement="bottom" title={<div>
学员在EduCoder做实训花费的时间
</div>}>
<a style={
{
color: '#747A7F',
textAlign: "center"
}
}
title={"学员在EduCoder做实训花费的时间"}
>{record.cost_time === null ? "--":record.cost_time === undefined ?"--":record.cost_time}
</a>
</Tooltip>
}
</span>
// <a style={
@ -847,16 +853,19 @@ class Listofworksstudentone extends Component {
textAlign: "center"
}
}>
{record.cost_time === null ? "--":record.cost_time === undefined ?"--":
{record.cost_time === null ? "--":record.cost_time === undefined ?"--":record.cost_time === "--" ?"--":
<Tooltip placement="bottom" title={<div>
学员在EduCoder做实训花费的时间
</div>}>
<a style={
{
color: '#747A7F',
textAlign: "center"
}
}
title={"学员在EduCoder做实训花费的时间"}
>{record.cost_time === null ? "--":record.cost_time === undefined ?"--":record.cost_time}
</a>
</Tooltip>
}
</span>
)

@ -1,204 +1,206 @@
import React, { Component } from 'react';
import { Link } from 'react-router-dom'
import { withStyles } from 'material-ui/styles';
import Button from 'material-ui/Button';
import Tooltip from 'material-ui/Tooltip';
import './ActionView.css'
/*
color: #1B4061 !important;
background-color: transparent;
border: 1px solid #1B4061 !important;
*/
const styles = theme => ({
button: {
margin: theme.spacing.unit,
border: '1px solid #1B4061',
color: '#1B4061',
height: '30px',
padding: '0 16px',
'&:hover': {
color: '#4CACFF',
border: '1px solid #4CACFF'
}
},
hoverButton: {
margin: theme.spacing.unit,
height: '30px',
padding: '0 16px',
color: '#4CACFF',
border: '1px solid #4CACFF'
},
buttonText: {
color: '#1B4061 !important',
'&:hover': {
color: '#1B4061',
}
}
});
class ActionView extends Component {
constructor(props) {
super(props)
}
componentDidMount() {
// request
window._tpiWidthResize = () => {
const _w = window.$('#actionView').width();
// if (_w < 446) {
// window.$('#time-consuming').hide()
// // window.$('#time-consuming').hide()
// } else if (_w < 746) {
// // 文字放出来之前是 580
// window.$('#time-consuming').show()
// window.$('.time_limit').hide()
// } else {
// window.$('#time-consuming').show()
// window.$('.time_limit').show()
// }
}
}
showWebDisplay(challenge) {
window.open(challenge.webDisplayUrl, '_blank');
}
/*<span className="mt10 -flex c_grey ml15" id="time-consuming">耗时0 天 3 小时 11 分钟 57 秒 </span>*/
render() {
const { onRunCodeTest, onShowPrevStage, onShowNextStage, gameBuilding
, game, classes, st, shixun, record, challenge, time_limit, real_time_limit } = this.props;
return (
<div className="-flex -layout-h" id="game_operate_action">
<style>{`
#game_operate_action {
width: 100%;
}
.time_limit {
margin-right: 0px;
}
.spliter {
border-right: 1px solid;
padding-right: 8px;
margin-right: 8px;
height: 14px;
display: inline-block;
position: relative;
top: 3px;
}
#time-consuming {
flex: auto;
overflow: hidden;
white-space: nowrap;
}
#game_operate_action .act_btn {
flex: 0 0 90px;
}
`}</style>
<span className="mt10 -flex c_grey ml15" id="time-consuming">
{!!time_limit &&
<span className="time_limit">{`本关最大执行时间:${real_time_limit}`}
{!gameBuilding && record && <span className="spliter"></span>}
</span>}
{!gameBuilding && record ?
// <Tooltip title={ "本次评测耗时(编译、运行总时间)" }></Tooltip>
<span>本次评测耗时(编译运行总时间){ record } </span>
: ""}
</span>
{/*将第一个按钮改为visibility方式隐藏不然加载时测评按钮会出现没有垂直居中的情况*/}
<Tooltip title={ "倒计时为0时服务将被关闭" }>
<Button size="small" className={classes.button + ' actionViewfirstButton'} onClick={()=>this.showWebDisplay(challenge)}
style={{ visibility: challenge.showWebDisplayButton ? '': 'hidden',
minWidth: challenge.showWebDisplayButton ? '': '1px',
width: challenge.showWebDisplayButton ? '': '1px',
flex: `0 0 ${challenge.showWebDisplayButton ? '110px': '1px'}`
}}
id="showWebDisplayButton"
// style={{ display: challenge.showWebDisplayButton ? 'flex': 'none'}}
>
查看效果
</Button>
</Tooltip>
{
!gameBuilding &&
(game && !!game.prev_game) ?
<Link to={`/tasks/${game.prev_game}`} className={classes.buttonText + ' act_btn'}>
<Button size="small" className={classes.button}>
上一关
</Button>
</Link>
: ''}
{/*未发布的都能跳转*/}
{ !gameBuilding &&
((game && (game.status === 2 || shixun.status < 2) || shixun && shixun.task_pass ) && !!game.next_game) ?
<Link to={`/tasks/${game.next_game}`} className={classes.buttonText + ' act_btn'}>
<Button size="small" className={classes.button}>
下一关
</Button>
</Link>
: ''}
{(!shixun.vnc || shixun.vnc_evaluate) && <div id="code_test" className="act_btn">
{
st === 1 && game.status === 2 ?
<Tooltip title={ "已通关的选择题任务无法再次测评" }>
<a href="javascript:void(0)" className="shixun-task-btn mr15 gray "
>
<i className="fa fa-play-circle font-16"></i>
测评
</a>
</Tooltip>
:
gameBuilding ?
<a href="javascript:void(0)" className="shixun-task-btn mr15 gray "
>
<i className="fa fa-play-circle font-16"></i>
测评
</a>
:
<a href="javascript:void(0)" className="shixun-task-btn mr15 "
onClick={onRunCodeTest}>
<i className="fa fa-play-circle font-16"></i>
测评
</a>}
</div>}
</div>
);
/*
<a href="/shixuns/8arufxzl" id="exit_shixun" className="shixun-task-btn task-newbtn-grey mt8 mr15">离开</a>
<a href="javascript:void(0)" className="shixun-task-btn task-btn-blue mr15 mt8" id="prev_step"
onClick={onShowNextStage}>下一关 </a>
onclick="training_task_submmit();"
{game && !!game.prev_game ?
<div id="prev_step_area">
<Link to={`/tasks/${game.prev_game}`} className="shixun-task-btn task-btn-blue mr15 mt8">上一关</Link>
</div>
: ''}
{game && !!game.next_game ?
<div id="next_step_area">
<Link to={`/tasks/${game.next_game}`} className="shixun-task-btn task-btn-blue mr15 mt8">下一关</Link>
</div>
: ''}
*/
}
}
export default withStyles(styles)( ActionView );
import React, { Component } from 'react';
import { Link } from 'react-router-dom'
import { withStyles } from 'material-ui/styles';
import Button from 'material-ui/Button';
import Tooltip from 'material-ui/Tooltip';
import './ActionView.css'
/*
color: #1B4061 !important;
background-color: transparent;
border: 1px solid #1B4061 !important;
*/
const styles = theme => ({
button: {
margin: theme.spacing.unit,
border: '1px solid #1B4061',
color: '#1B4061',
height: '30px',
padding: '0 16px',
'&:hover': {
color: '#4CACFF',
border: '1px solid #4CACFF'
}
},
hoverButton: {
margin: theme.spacing.unit,
height: '30px',
padding: '0 16px',
color: '#4CACFF',
border: '1px solid #4CACFF'
},
buttonText: {
color: '#1B4061 !important',
'&:hover': {
color: '#1B4061',
}
}
});
class ActionView extends Component {
constructor(props) {
super(props)
}
componentDidMount() {
// request
window._tpiWidthResize = () => {
const _w = window.$('#actionView').width();
// if (_w < 446) {
// window.$('#time-consuming').hide()
// // window.$('#time-consuming').hide()
// } else if (_w < 746) {
// // 文字放出来之前是 580
// window.$('#time-consuming').show()
// window.$('.time_limit').hide()
// } else {
// window.$('#time-consuming').show()
// window.$('.time_limit').show()
// }
}
}
showWebDisplay(challenge) {
window.open(challenge.webDisplayUrl, '_blank');
}
/*<span className="mt10 -flex c_grey ml15" id="time-consuming">耗时0 天 3 小时 11 分钟 57 秒 </span>*/
render() {
const { onRunCodeTest, onShowPrevStage, onShowNextStage, gameBuilding
, game, classes, st, shixun, record, challenge, time_limit, real_time_limit } = this.props;
console.log(shixun)
return (
<div className="-flex -layout-h" id="game_operate_action">
<style>{`
#game_operate_action {
width: 100%;
}
.time_limit {
margin-right: 0px;
}
.spliter {
border-right: 1px solid;
padding-right: 8px;
margin-right: 8px;
height: 14px;
display: inline-block;
position: relative;
top: 3px;
}
#time-consuming {
flex: auto;
overflow: hidden;
white-space: nowrap;
}
#game_operate_action .act_btn {
flex: 0 0 90px;
}
`}</style>
<span className="mt10 -flex c_grey ml15" id="time-consuming">
{!!time_limit &&
<span className="time_limit">{`本关最大执行时间:${real_time_limit}`}
{!gameBuilding && record && <span className="spliter"></span>}
</span>}
{!gameBuilding && record ?
// <Tooltip title={ "本次评测耗时(编译、运行总时间)" }></Tooltip>
<span>本次评测耗时(编译运行总时间){ record } </span>
: ""}
</span>
{/*将第一个按钮改为visibility方式隐藏不然加载时测评按钮会出现没有垂直居中的情况*/}
<Tooltip title={ "倒计时为0时服务将被关闭" }>
<Button size="small" className={classes.button + ' actionViewfirstButton'} onClick={()=>this.showWebDisplay(challenge)}
style={{ visibility: challenge.showWebDisplayButton ? '': 'hidden',
minWidth: challenge.showWebDisplayButton ? '': '1px',
width: challenge.showWebDisplayButton ? '': '1px',
flex: `0 0 ${challenge.showWebDisplayButton ? '110px': '1px'}`
}}
id="showWebDisplayButton"
// style={{ display: challenge.showWebDisplayButton ? 'flex': 'none'}}
>
查看效果
</Button>
</Tooltip>
{
!gameBuilding &&
(game && !!game.prev_game) ?
<Link to={`/tasks/${game.prev_game}`} className={classes.buttonText + ' act_btn'}>
<Button size="small" className={classes.button}>
上一关
</Button>
</Link>
: ''}
{/*未发布的都能跳转*/}
{ !gameBuilding &&
((game && (game.status === 2 || shixun.status < 2) || shixun && shixun.task_pass ) && !!game.next_game) ?
<Link to={`/tasks/${game.next_game}`} className={classes.buttonText + ' act_btn'}>
<Button size="small" className={classes.button}>
下一关
</Button>
</Link>
: ''}
{(shixun&&!shixun.vnc || shixun&&shixun.vnc_evaluate) && <div id="code_test" className="act_btn">
{
st === 1 && game.status === 2 ?
<Tooltip title={ "已通关的选择题任务无法再次测评" }>
<a href="javascript:void(0)" className="shixun-task-btn mr15 gray "
>
<i className="fa fa-play-circle font-16"></i>
测评
</a>
</Tooltip>
:
gameBuilding ?
<a href="javascript:void(0)" className="shixun-task-btn mr15 gray "
>
<i className="fa fa-play-circle font-16"></i>
测评
</a>
:
<a href="javascript:void(0)" className="shixun-task-btn mr15 "
onClick={onRunCodeTest}>
<i className="fa fa-play-circle font-16"></i>
测评
</a>}
</div>}
</div>
);
/*
<a href="/shixuns/8arufxzl" id="exit_shixun" className="shixun-task-btn task-newbtn-grey mt8 mr15">离开</a>
<a href="javascript:void(0)" className="shixun-task-btn task-btn-blue mr15 mt8" id="prev_step"
onClick={onShowNextStage}>下一关 </a>
onclick="training_task_submmit();"
{game && !!game.prev_game ?
<div id="prev_step_area">
<Link to={`/tasks/${game.prev_game}`} className="shixun-task-btn task-btn-blue mr15 mt8">上一关</Link>
</div>
: ''}
{game && !!game.next_game ?
<div id="next_step_area">
<Link to={`/tasks/${game.next_game}`} className="shixun-task-btn task-btn-blue mr15 mt8">下一关</Link>
</div>
: ''}
*/
}
}
export default withStyles(styles)( ActionView );

@ -1,309 +1,312 @@
import React, { Component } from 'react';
import CodeRepositoryView from './CodeRepositoryView'
import axios from 'axios'
import './CodeRepositoryView.css'
// 自己处理path加上父节点的path, 这里是处理树节点了所以是set key
function addPrePath(treeData, parentNodePath) {
return treeData.map(item => {
return {
...item,
key: `${parentNodePath}/${item.name}`
}
})
}
function getNewTreeData(treeData, curKey, child, level) {
const loop = (data) => {
data.forEach((item) => {
// 这里不能用indexOf 同一级可能出现test目录和test.py文件
if (item.key == curKey) {
child = addPrePath(child, curKey);
item.children = child;
} else {
if (item.children) {
loop(item.children);
}
}
});
};
loop(treeData);
}
function fileData2TreeData(repoFilesData) {
const fileTreeData = [];
repoFilesData.forEach((item) => {
if (item.kind === 'file') {
fileTreeData.push({
key: item.path,
name: item.name,
isLeaf: true
})
} else {
fileTreeData.push({
key: item.path,
name: item.name,
// isLeaf: false
})
}
})
return fileTreeData;
}
class CodeRepositoryViewContainer extends Component {
constructor(props) {
super(props)
this.showFilesDrawer = this.showFilesDrawer.bind(this)
this.onRepositoryViewExpand = this.onRepositoryViewExpand.bind(this)
this.state = {
drawerOpen: false,
loadingFirstRepoFiles: false,
fileTreeData: "",
fileTreeSelectedKeys: [],
codeRepositoryViewExpanded: false,
tabIndex: 0,
settingDrawerOpen: false
}
}
showSettingDrawer = (open) => {
this.setState({settingDrawerOpen: open})
}
tabIndexChange = (index) => {
this.setState({tabIndex: index});
}
onRepositoryViewExpand() {
window.repository_extend_and_zoom();
this.setState({
evaluateViewExpanded: !this.state.evaluateViewExpanded
}, () => {
setTimeout(()=>{
window.__tpiOnResize()
}, 300)
})
}
showFilesDrawer(open) {
if (this.props.loading === true) {
return;
}
if (!this.state.fileTreeData) {
this.fetchRepoFiles();
}
this.setState({
drawerOpen: open,
})
}
loadRepoFiles = () => {
if (!this.state.fileTreeData) {
this.fetchRepoFiles();
}
}
componentWillReceiveProps(newProps, oldProps) {
}
componentDidMount() {
}
componentDidUpdate(prevProps, prevState, snapshot) {
const { game, challenge } = this.props
if (this.props.game && (!prevProps.game || prevProps.game.identifier !== this.props.game.identifier) ) {
this.setState({
fileTreeSelectedKeys: [ challenge.multiPath ? challenge.path[0] : challenge.path ]
})
// 初始化
} else if (this.state.fileTreeSelectedKeys.length === 0 && challenge && challenge.path) {
this.setState({
fileTreeSelectedKeys: [ challenge.multiPath ? challenge.path[0] : challenge.path ]
})
} else if (challenge && prevProps && prevProps.challenge
&& challenge.pathIndex != prevProps.challenge.pathIndex
&& challenge.pathIndex !== -1) {
this.setState({
fileTreeSelectedKeys: [ challenge.multiPath ? challenge.path[challenge.pathIndex] : challenge.path ]
})
}
}
handleDialogClose() {
this.setState({
dialogOpen: false
})
}
onLoadData = (treeNode) => {
if (treeNode.props.children && treeNode.props.children.length) {
return new Promise((resolve) => {
resolve();
});
}
return new Promise((resolve, reject) => {
this.fetchRepoFiles(treeNode, resolve, reject)
});
}
map2OldData = (treeData) => {
if (!treeData || treeData.length === 0) return treeData;
treeData = treeData.map(item => {
return {
kind: item.type == "blob" ? "file" : "dir", // blob->file tree->dir
path: item.name,
name: item.name
}
})
return treeData;
}
fetchRepoFiles(treeNode, resolve, reject) {
// http://localhost:3000/api/v1/games/829al3mst4fy/entries?path=src/step1&rev=master
if (!this.props.challenge || !this.props.game) {
return;
}
// var ar = this.props.challenge.path.split('/');
// ar.length = ar.length - 2;
// var _path = ar.join('/');
var _path = treeNode ? treeNode.props.eventKey : '' ;
if (_path.charAt(0) === '/') {
_path = _path.substring(1)
}
// var url = `/api/v1/games/${this.props.game.identifier}/entries?path=${_path}&rev=master&gpid=${this.props.myshixun.gpid}`
let url = `/myshixuns/${this.props.myshixun.identifier}/repository.json`
if (!this.state.fileTreeData || this.state.fileTreeData.length === 0) {
this.setState({
loadingFirstRepoFiles: true,
})
}
var that = this;
axios.post(url, {
path: _path
// withCredentials: true,
})
.then((response) => {
const repoFilesData = this.map2OldData(response.data.trees)
if (!this.state.fileTreeData || this.state.fileTreeData.length === 0) { // 还没树节点,没加载过
const fileTreeData = fileData2TreeData(repoFilesData)
this.setState({
fileTreeData,
loadingFirstRepoFiles: false,
});
} else {
var _treeNode = treeNode;
var _eventKey = _treeNode.props.eventKey;
const fileTreeData = that.state.fileTreeData;
// 新的数组放置到treenode下
const tempFileTreeData = fileData2TreeData(repoFilesData)
getNewTreeData(fileTreeData, _eventKey, tempFileTreeData, 2);
this.setState({
fileTreeData,
})
}
resolve && resolve();
})
.catch(function (error) {
console.log(error);
reject && reject();
});
}
onTreeSelect = (selectedKeys, info) => {
const isLeaf = info.node.props.isLeaf;
if (isLeaf) { // 叶子节点
selectedKeys.length && this.setState({
fileTreeSelectedKeys: selectedKeys
})
const { fetchRepositoryCode, onPathChange, showSnackbar, challenge } = this.props;
const nodePath = info.node.props.eventKey;
// 设置pathIndex为-1那么代码文件下拉可以切回可编辑的文件
if (!challenge.multiPath) { // 单path任务 多path任务 path是数组
if (challenge.path.trim() == nodePath.trim()) {
if (challenge.pathIndex === 0) {
showSnackbar(`当前编辑文件已经是${nodePath}`)
} else {
onPathChange(0)
}
return;
} else {
onPathChange(-1)
}
} else {
let isCurrentFile = false;
let cur_index = -1;
if (challenge.path && challenge.path.forEach) {
challenge.path.forEach((item, index) => {
if (nodePath == item) {
isCurrentFile = true;
cur_index = index;
}
})
}
if (isCurrentFile) {
onPathChange(cur_index)
showSnackbar(`当前编辑文件已经是${nodePath}`)
} else {
onPathChange(-1)
}
}
if (nodePath) {
const filetype = nodePath.split('.').pop().toLowerCase();
if (filetype == 'jpg' || filetype == 'png' || filetype == 'gif' || filetype == 'jpeg'
|| filetype == 'jar'
|| filetype == 'doc' || filetype == 'pdf' || filetype == 'xsl' || filetype == 'ppt') {
showSnackbar(`不支持加载${filetype}类型的文件。`)
return;
}
fetchRepositoryCode(null, nodePath, 1);
} else {
console.error('no eventKey:', info.node)
}
}
}
// /shixuns/mnf6b7z3/shixun_discuss?challenge_id=88
render() {
return (
<React.Fragment>
{this.props.isOnlyContainer == true ?
React.Children.map(this.props.children, child => {
if(!child) {
return ''
}
return React.cloneElement(child, Object.assign({...this.state}, {
loadRepoFiles: this.loadRepoFiles,
onTreeSelect: this.onTreeSelect,
onLoadData: this.onLoadData,
}))
})
:
<CodeRepositoryView {...this.props}
{...this.state}
showFilesDrawer={this.showFilesDrawer}
loadRepoFiles={this.loadRepoFiles}
onLoadData={this.onLoadData}
onTreeSelect={ this.onTreeSelect }
onRepositoryViewExpand={this.onRepositoryViewExpand}
tabIndexChange={this.tabIndexChange}
showSettingDrawer={this.showSettingDrawer}
></CodeRepositoryView> }
</React.Fragment>
);
}
}
export default CodeRepositoryViewContainer;
import React, { Component } from 'react';
import CodeRepositoryView from './CodeRepositoryView'
import axios from 'axios'
import './CodeRepositoryView.css'
// 自己处理path加上父节点的path, 这里是处理树节点了所以是set key
function addPrePath(treeData, parentNodePath) {
return treeData.map(item => {
return {
...item,
key: `${parentNodePath}/${item.name}`
}
})
}
function getNewTreeData(treeData, curKey, child, level) {
const loop = (data) => {
data.forEach((item) => {
// 这里不能用indexOf 同一级可能出现test目录和test.py文件
if (item.key == curKey) {
child = addPrePath(child, curKey);
item.children = child;
} else {
if (item.children) {
loop(item.children);
}
}
});
};
loop(treeData);
}
function fileData2TreeData(repoFilesData) {
if(repoFilesData!=null){
const fileTreeData = [];
repoFilesData.forEach((item) => {
if (item.kind === 'file') {
fileTreeData.push({
key: item.path,
name: item.name,
isLeaf: true
})
} else {
fileTreeData.push({
key: item.path,
name: item.name,
// isLeaf: false
})
}
})
return fileTreeData;
}
}
class CodeRepositoryViewContainer extends Component {
constructor(props) {
super(props)
this.showFilesDrawer = this.showFilesDrawer.bind(this)
this.onRepositoryViewExpand = this.onRepositoryViewExpand.bind(this)
this.state = {
drawerOpen: false,
loadingFirstRepoFiles: false,
fileTreeData: "",
fileTreeSelectedKeys: [],
codeRepositoryViewExpanded: false,
tabIndex: 0,
settingDrawerOpen: false
}
}
showSettingDrawer = (open) => {
this.setState({settingDrawerOpen: open})
}
tabIndexChange = (index) => {
this.setState({tabIndex: index});
}
onRepositoryViewExpand() {
window.repository_extend_and_zoom();
this.setState({
evaluateViewExpanded: !this.state.evaluateViewExpanded
}, () => {
setTimeout(()=>{
window.__tpiOnResize()
}, 300)
})
}
showFilesDrawer(open) {
if (this.props.loading === true) {
return;
}
if (!this.state.fileTreeData) {
this.fetchRepoFiles();
}
this.setState({
drawerOpen: open,
})
}
loadRepoFiles = () => {
if (!this.state.fileTreeData) {
this.fetchRepoFiles();
}
}
componentWillReceiveProps(newProps, oldProps) {
}
componentDidMount() {
}
componentDidUpdate(prevProps, prevState, snapshot) {
const { game, challenge } = this.props
if (this.props.game && (!prevProps.game || prevProps.game.identifier !== this.props.game.identifier) ) {
this.setState({
fileTreeSelectedKeys: [ challenge.multiPath ? challenge.path[0] : challenge.path ]
})
// 初始化
} else if (this.state.fileTreeSelectedKeys.length === 0 && challenge && challenge.path) {
this.setState({
fileTreeSelectedKeys: [ challenge.multiPath ? challenge.path[0] : challenge.path ]
})
} else if (challenge && prevProps && prevProps.challenge
&& challenge.pathIndex != prevProps.challenge.pathIndex
&& challenge.pathIndex !== -1) {
this.setState({
fileTreeSelectedKeys: [ challenge.multiPath ? challenge.path[challenge.pathIndex] : challenge.path ]
})
}
}
handleDialogClose() {
this.setState({
dialogOpen: false
})
}
onLoadData = (treeNode) => {
if (treeNode.props.children && treeNode.props.children.length) {
return new Promise((resolve) => {
resolve();
});
}
return new Promise((resolve, reject) => {
this.fetchRepoFiles(treeNode, resolve, reject)
});
}
map2OldData = (treeData) => {
if (!treeData || treeData.length === 0) return treeData;
treeData = treeData.map(item => {
return {
kind: item.type == "blob" ? "file" : "dir", // blob->file tree->dir
path: item.name,
name: item.name
}
})
return treeData;
}
fetchRepoFiles(treeNode, resolve, reject) {
// http://localhost:3000/api/v1/games/829al3mst4fy/entries?path=src/step1&rev=master
if (!this.props.challenge || !this.props.game) {
return;
}
// var ar = this.props.challenge.path.split('/');
// ar.length = ar.length - 2;
// var _path = ar.join('/');
var _path = treeNode ? treeNode.props.eventKey : '' ;
if (_path.charAt(0) === '/') {
_path = _path.substring(1)
}
// var url = `/api/v1/games/${this.props.game.identifier}/entries?path=${_path}&rev=master&gpid=${this.props.myshixun.gpid}`
let url = `/myshixuns/${this.props.myshixun.identifier}/repository.json`
if (!this.state.fileTreeData || this.state.fileTreeData.length === 0) {
this.setState({
loadingFirstRepoFiles: true,
})
}
var that = this;
axios.post(url, {
path: _path
// withCredentials: true,
})
.then((response) => {
const repoFilesData = this.map2OldData(response.data.trees)
if (!this.state.fileTreeData || this.state.fileTreeData.length === 0) { // 还没树节点,没加载过
const fileTreeData = fileData2TreeData(repoFilesData)
this.setState({
fileTreeData,
loadingFirstRepoFiles: false,
});
} else {
var _treeNode = treeNode;
var _eventKey = _treeNode.props.eventKey;
const fileTreeData = that.state.fileTreeData;
// 新的数组放置到treenode下
const tempFileTreeData = fileData2TreeData(repoFilesData)
getNewTreeData(fileTreeData, _eventKey, tempFileTreeData, 2);
this.setState({
fileTreeData,
})
}
resolve && resolve();
})
.catch(function (error) {
console.log(error);
reject && reject();
});
}
onTreeSelect = (selectedKeys, info) => {
const isLeaf = info.node.props.isLeaf;
if (isLeaf) { // 叶子节点
selectedKeys.length && this.setState({
fileTreeSelectedKeys: selectedKeys
})
const { fetchRepositoryCode, onPathChange, showSnackbar, challenge } = this.props;
const nodePath = info.node.props.eventKey;
// 设置pathIndex为-1那么代码文件下拉可以切回可编辑的文件
if (!challenge.multiPath) { // 单path任务 多path任务 path是数组
if (challenge.path.trim() == nodePath.trim()) {
if (challenge.pathIndex === 0) {
showSnackbar(`当前编辑文件已经是${nodePath}`)
} else {
onPathChange(0)
}
return;
} else {
onPathChange(-1)
}
} else {
let isCurrentFile = false;
let cur_index = -1;
if (challenge.path && challenge.path.forEach) {
challenge.path.forEach((item, index) => {
if (nodePath == item) {
isCurrentFile = true;
cur_index = index;
}
})
}
if (isCurrentFile) {
onPathChange(cur_index)
showSnackbar(`当前编辑文件已经是${nodePath}`)
} else {
onPathChange(-1)
}
}
if (nodePath) {
const filetype = nodePath.split('.').pop().toLowerCase();
if (filetype == 'jpg' || filetype == 'png' || filetype == 'gif' || filetype == 'jpeg'
|| filetype == 'jar'
|| filetype == 'doc' || filetype == 'pdf' || filetype == 'xsl' || filetype == 'ppt') {
showSnackbar(`不支持加载${filetype}类型的文件。`)
return;
}
fetchRepositoryCode(null, nodePath, 1);
} else {
console.error('no eventKey:', info.node)
}
}
}
// /shixuns/mnf6b7z3/shixun_discuss?challenge_id=88
render() {
return (
<React.Fragment>
{this.props.isOnlyContainer == true ?
React.Children.map(this.props.children, child => {
if(!child) {
return ''
}
return React.cloneElement(child, Object.assign({...this.state}, {
loadRepoFiles: this.loadRepoFiles,
onTreeSelect: this.onTreeSelect,
onLoadData: this.onLoadData,
}))
})
:
<CodeRepositoryView {...this.props}
{...this.state}
showFilesDrawer={this.showFilesDrawer}
loadRepoFiles={this.loadRepoFiles}
onLoadData={this.onLoadData}
onTreeSelect={ this.onTreeSelect }
onRepositoryViewExpand={this.onRepositoryViewExpand}
tabIndexChange={this.tabIndexChange}
showSettingDrawer={this.showSettingDrawer}
></CodeRepositoryView> }
</React.Fragment>
);
}
}
export default CodeRepositoryViewContainer;

@ -70,6 +70,14 @@ class InfosTopics extends Component{
// }else{
//
// }
let types=this.props.match.params.topicstype;
let professional_certification=this.props.current_user&&this.props.current_user.professional_certification;
if(professional_certification===false&&types==="publicly"){
}else{
this.setState({
isSpin:true
})
@ -77,43 +85,42 @@ class InfosTopics extends Component{
let user_id="";
if(types==="publicly"){
user_id=this.props.current_user&&this.props.current_user.login;
user_id=this.props.current_user&&this.props.current_user.login;
}else{
user_id=this.props.match.params&&this.props.match.params.username;
user_id=this.props.match.params&&this.props.match.params.username;
}
if(user_id===undefined){
user_id=this.props.match.params&&this.props.match.params.username;
user_id=1
}
if(user_id!=undefined){
let {per_page}=this.state;
let url=`/users/${user_id}/question_banks.json`;
axios.get(encodeURI(url),{params:{
type,
object_type:category,
course_list_id,
sort_by,
sort_direction,
page,
per_page
}
}).then((response) => {
this.setState({
data:response.data,
checkBoxValues:[],
isSpin:false
})
}).catch((error) => {
this.setState({
isSpin:false
})
});
}
let {per_page}=this.state;
let url=`/users/${user_id}/question_banks.json`;
axios.get(encodeURI(url),{params:{
type,
object_type:category,
course_list_id,
sort_by,
sort_direction,
page,
per_page
}
}).then((response) => {
this.setState({
data:response.data,
checkBoxValues:[],
isSpin:false
})
}).catch((error) => {
this.setState({
isSpin:false
})
});
}
}

@ -127,7 +127,7 @@ class BanksIndex extends Component{
{
crumbData &&
<Breadcrumb separator=">" className="breadcrumb mt22">
<Breadcrumb.Item href={crumbData && crumbData.is_public == true ?`/topicbank/${this.props.current_user && this.props.current_user.login}/publicly`:`/users/${this.props.current_user && this.props.current_user.login}/topics/personal`}>{ crumbData && crumbData.is_public == true ? '公共' : '我的' }题库</Breadcrumb.Item>
<Breadcrumb.Item href={crumbData && crumbData.is_public == true ?`/topicbank/publicly`:`/users/${this.props.current_user && this.props.current_user.login}/topics/personal`}>{ crumbData && crumbData.is_public == true ? '公共' : '我的' }题库</Breadcrumb.Item>
{
crumbData.crumbArray && crumbData.crumbArray.map((item,key)=>{
return(

Loading…
Cancel
Save