From 1738703bdaa7dea31e94ec2aa74947e075b7aa9b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 26 Jul 2019 14:24:17 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=B7=B2=E8=AE=A4=E8=AF=81=E7=9A=84?= =?UTF-8?q?=E8=80=81=E5=B8=88=E8=83=BD=E5=A4=9F=E8=B7=B3=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 13 ++++++++++++- app/controllers/myshixuns_controller.rb | 4 ++-- app/helpers/myshixuns_helper.rb | 12 ++++++++++++ app/models/shixun.rb | 1 + app/views/myshixuns/challenges.json.jbuilder | 6 +++--- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index a51dccb6f..ef648f6b3 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -37,7 +37,8 @@ class GamesController < ApplicationController # 上一关、下一关 prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) - next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) + #next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) + next_game = user_next_game(@shixun, game_challenge, @game, @identity) # 关卡点赞数, praise_or_tread = 1则表示赞过 praise_count = game_challenge.praises_count @@ -962,4 +963,14 @@ class GamesController < ApplicationController @identity = current_user.game_identity(@game) raise Educoder::TipException.new(403, "..") if @identity > User::EDU_GAME_MANAGER end + # identity用户身份 + def user_next_game(shixun, challenge, game, identity) + next_game = game.next_of_current_game(shixun.id, game.myshixun_id, challenge.position) + # 实训允许跳关 、 当前关卡已经通关、 用户是已认证的老师以上权限的人,允许跳关 + if shixun.task_pass || game.status == 2 || identity >= User::EDU_CERTIFICATION_TEACHER + next_game + else + nil + end + end end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index cdeca4871..6fe3e4be8 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -7,9 +7,9 @@ class MyshixunsController < ApplicationController ## TPI关卡列表 def challenges # @challenges = Challenge.where(shixun_id: params[:shixun_id]) - - @shixun_status = @myshixun.shixun.status + @shixun = @myshixun.shixun @games = @myshixun.games.includes(:challenge).reorder("challenges.position") + @identity = current_user.game_identity(@games.first) end diff --git a/app/helpers/myshixuns_helper.rb b/app/helpers/myshixuns_helper.rb index 650f32f40..b7843612d 100644 --- a/app/helpers/myshixuns_helper.rb +++ b/app/helpers/myshixuns_helper.rb @@ -1,2 +1,14 @@ module MyshixunsHelper + + # 获取tpi的identifier, + # identity表示用户关卡的身份 + # task_pass: 实训是否允许跳关 + def get_game_identifier task_pass, game, game_identity + # 允许跳关、 关卡已经开启、 用户是已认证老师以上的身份 + if task_pass || game.status != 3 || game_identity >= User::EDU_CERTIFICATION_TEACHER + game.identifier + else + nil + end + end end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index e35f9f1a6..82f689e3f 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -4,6 +4,7 @@ class Shixun < ApplicationRecord # status: 0:编辑 1:申请发布 2:正式发布 3:关闭 -1:软删除 # hide_code: 隐藏代码窗口 # code_hidden: 隐藏代码目录 + # task_pass: 跳关 has_many :challenges, dependent: :destroy has_many :challenge_tags, through: :challenges has_many :myshixuns, :dependent => :destroy diff --git a/app/views/myshixuns/challenges.json.jbuilder b/app/views/myshixuns/challenges.json.jbuilder index 802c2b561..0be94d9fd 100644 --- a/app/views/myshixuns/challenges.json.jbuilder +++ b/app/views/myshixuns/challenges.json.jbuilder @@ -3,7 +3,7 @@ json.array! @games do |game| json.partial! 'challenges/challenge', locals: { challenge: challenge } json.status game.status json.star game.star - json.identifier game.identifier - json.get_gold game.user_get_gold_and_experience(@shixun_status, challenge)[0] - json.get_experience game.user_get_gold_and_experience(@shixun_status, challenge)[1] + json.identifier get_game_identifier(@shixun.task_pass, game, @identity) + json.get_gold game.user_get_gold_and_experience(@shixun.status, challenge)[0] + json.get_experience game.user_get_gold_and_experience(@shixun.status, challenge)[1] end \ No newline at end of file From 0648d7a7b9d27de3673830aeec18057fbbe905db Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 26 Jul 2019 14:31:18 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 6fe3e4be8..fa47fd7f6 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -42,7 +42,7 @@ class MyshixunsController < ApplicationController if e.message != "ActiveRecord::RecordInvalid" logger.error("######delete_repository_error:#{e.message}") end - raise ActiveRecord::Rollback + raise "delete_repository_error:#{e.message}" end end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 1999c473f..11016cfbb 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -718,7 +718,7 @@ class ShixunsController < ApplicationController logger.error("##########project_fork error #{e.message}") @current_task.destroy! end - raise ActiveRecord::Rollback + raise "实训云平台繁忙(繁忙等级:81)" end end end From dbbd7e9ae4104541a183cf5ff692b3a2aa939a4e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 26 Jul 2019 14:37:35 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/helpers/myshixuns_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ef648f6b3..b2de6dcad 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -967,7 +967,7 @@ class GamesController < ApplicationController def user_next_game(shixun, challenge, game, identity) next_game = game.next_of_current_game(shixun.id, game.myshixun_id, challenge.position) # 实训允许跳关 、 当前关卡已经通关、 用户是已认证的老师以上权限的人,允许跳关 - if shixun.task_pass || game.status == 2 || identity >= User::EDU_CERTIFICATION_TEACHER + if shixun.task_pass || game.status == 2 || identity <= User::EDU_CERTIFICATION_TEACHER next_game else nil diff --git a/app/helpers/myshixuns_helper.rb b/app/helpers/myshixuns_helper.rb index b7843612d..2a487e361 100644 --- a/app/helpers/myshixuns_helper.rb +++ b/app/helpers/myshixuns_helper.rb @@ -5,7 +5,7 @@ module MyshixunsHelper # task_pass: 实训是否允许跳关 def get_game_identifier task_pass, game, game_identity # 允许跳关、 关卡已经开启、 用户是已认证老师以上的身份 - if task_pass || game.status != 3 || game_identity >= User::EDU_CERTIFICATION_TEACHER + if task_pass || game.status != 3 || game_identity <= User::EDU_CERTIFICATION_TEACHER game.identifier else nil From c7706f29d12fe8536973acfa65a7a5e6313b26cf Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Fri, 26 Jul 2019 14:47:36 +0800 Subject: [PATCH 4/4] toHTML delay --- public/react/src/common/TextUtil.js | 6 ++--- .../components/markdown/MarkdownToHtml.js | 25 ++++++++++++++++--- .../courses/exercise/new/MainDisplay.js | 10 +++++--- .../courses/exercise/new/NullDisplay.js | 8 ++++-- .../exercise/new/QestionDisplayHeader.js | 11 +++++--- .../courses/exercise/new/SingleDisplay.js | 16 ++++++++---- 6 files changed, 55 insertions(+), 21 deletions(-) diff --git a/public/react/src/common/TextUtil.js b/public/react/src/common/TextUtil.js index bd524c4a9..70ca23258 100644 --- a/public/react/src/common/TextUtil.js +++ b/public/react/src/common/TextUtil.js @@ -6,11 +6,9 @@ export function isImageExtension(fileName) { export function markdownToHTML(oldContent, selector) { window.$('#md_div').html('') // markdown to html - try { - - + try { var markdwonParser = window.editormd.markdownToHTML("md_div", { - markdown: oldContent, + markdown: oldContent, // .replace(/▁/g,"▁▁▁"), emoji: true, htmlDecode: "style,script,iframe", // you can filter tags decode taskList: true, diff --git a/public/react/src/common/components/markdown/MarkdownToHtml.js b/public/react/src/common/components/markdown/MarkdownToHtml.js index 266f831ee..0780fc789 100644 --- a/public/react/src/common/components/markdown/MarkdownToHtml.js +++ b/public/react/src/common/components/markdown/MarkdownToHtml.js @@ -1,27 +1,44 @@ import React,{ Component } from "react"; import { markdownToHTML } from 'educoder' +/** + selector 需要传入唯一的selector作为id,不然会引起冲突 + delay 如果有公式,需要传入delay={true} +*/ class MarkdownToHtml extends Component{ constructor(props){ super(props); this.state={ } } + _markdownToHTML = (content, selector) => { + if (this.props.delay == true) { + (function(content, selector) { + // console.log('selector: ', selector) + setTimeout(() => { + markdownToHTML(content, selector) + }, 600) + })(content, selector) + } else { + markdownToHTML(content, selector) + } + } componentDidUpdate = (prevProps) => { if (this.props.content) { if ( prevProps.content != this.props.content ) { - markdownToHTML(this.props.content, `.markdown_to_html_${this.props.selector || ''}`) + this._markdownToHTML(this.props.content, `.markdown_to_html_${this.props.selector || ''}`) } } } componentDidMount () { - this.props.content && markdownToHTML(this.props.content, `.markdown_to_html_${this.props.selector || ''}`) + this.props.content && this._markdownToHTML(this.props.content, `.markdown_to_html_${this.props.selector || ''}`) } render(){ - + const { style, className } = this.props return( -