From 49cf70f38fe7eaddf8fd56accb75b86c0b15f681 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 26 Mar 2019 15:33:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E3=80=91=E5=AE=9E=E8=AE=AD=E9=85=8D=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E8=AF=84=E6=B5=8B=E8=84=9A=E6=9C=AC=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E6=97=A0=E6=B3=95=E6=B8=85=E7=A9=BA=EF=BC=8C?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E9=80=9A=E8=BF=87=E9=87=8D=E6=96=B0=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E5=B9=B3=E5=8F=B0=E6=89=8D=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 15 ++++++++++----- app/views/shixuns/_settings_edit.html.erb | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 18107cae..2f07b182 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1163,11 +1163,16 @@ class ShixunsController < ApplicationController end def get_script_contents - mirrir_script = MirrorScript.find(params[:script_id]) - script = mirrir_script.try(:script) - description = mirrir_script.try(:description) - script = modify_shixun_script @shixun, script - render :json => {contents: script, description: description} + if params[:script_id].to_i == -1 + render :json => {contents: "", description: ""} + else + mirrir_script = MirrorScript.find(params[:script_id]) + script = mirrir_script.try(:script) + description = mirrir_script.try(:description) + script = modify_shixun_script @shixun, script + render :json => {contents: script, description: description} + end + end def get_common_script diff --git a/app/views/shixuns/_settings_edit.html.erb b/app/views/shixuns/_settings_edit.html.erb index b68a4f57..05ffd841 100644 --- a/app/views/shixuns/_settings_edit.html.erb +++ b/app/views/shixuns/_settings_edit.html.erb @@ -85,8 +85,9 @@
无
<% @shixun.standrad_script.each do |script| %><%= script.script_type %>
<% end %> From a71e82ae787645c3625b9c419f2e87ff3e43f5cd Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 26 Mar 2019 16:13:23 +0800 Subject: [PATCH 2/2] https://www.trustie.net/issues/18634 --- app/services/shixuns_service.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/services/shixuns_service.rb b/app/services/shixuns_service.rb index ffec7924..f4842076 100644 --- a/app/services/shixuns_service.rb +++ b/app/services/shixuns_service.rb @@ -125,9 +125,21 @@ class ShixunsService praise_count = d.praise_tread.where(:praise_or_tread => 1).count user_praise= d.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false # 实训(TPM)的管理员可以看到隐藏的评论 - parents = {:id => d.id, :content => d.content, :time => time_from_now(d.created_at), :position => d.position, :user_id => d.user.try(:id), :reward => d.reward, - :image_url => url_to_avatar(d.user), :username => d.username, :user_login => d.user.try(:login), :shixun_id => dis.id, :hidden => d.hidden, - :manager => current_user.manager_of_shixun?(dis, current_user), :praise_count => praise_count, :user_praise => user_praise, :admin => current_user.admin?} + manager = current_user.manager_of_shixun?(dis, current_user) + game_url = + if manager + challenge_id = dis.challenges.where(position: d.position).pluck(:id).first + game_identifier = Game.where(user_id: current_user, + challenge_id: challenge_id).pluck(:identifier).first + "/tasks/#{game_identifier}" + else + "" + end + parents = {:id => d.id, :content => d.content, :time => time_from_now(d.created_at), :position => d.position, + :user_id => d.user.try(:id), :reward => d.reward, :image_url => url_to_avatar(d.user), + :username => d.username, :user_login => d.user.try(:login), :shixun_id => dis.id, :hidden => d.hidden, + :manager => manager, :praise_count => praise_count, game_url: game_url, + :user_praise => user_praise, :admin => current_user.admin?} # 现在没有二级回复,所以查询的时候直接从root_id取 children = Discuss.where(:root_id => d.id).includes(:user).reorder("created_at asc")