优化列表

newyslclassrooms
daiao 5 years ago
parent 25956ec86e
commit f8af1125d3

@ -155,9 +155,8 @@ class ChallengesController < ApplicationController
def index def index
uid_logger("identifier: #{params}") uid_logger("identifier: #{params}")
@challenges = @shixun.challenges.fields_for_list.joins(:games).where(games: {user_id: current_user.id})
@challenges = @shixun.challenges.fields_for_list .select("challenges.*, games.identifier identifier, games.status status")
@editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员 @editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user @user = current_user
@shixun.increment!(:visits) @shixun.increment!(:visits)

@ -69,10 +69,10 @@ class Challenge < ApplicationRecord
end end
# 开启挑战 # 开启挑战
def open_game user_id, shixun def open_game
game = self.games.where(user_id: user_id).first identifier = self.identifier
if game.present? if identifier.present?
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" shixun.task_pass || status != 3 ? "/tasks/#{identifier}" : ""
else else
self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : ""
end end
@ -92,16 +92,16 @@ class Challenge < ApplicationRecord
# end # end
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status user_id def user_tpi_status
# todo: 以前没加索引导致相同关卡,同一用户有多个games # todo: 以前没加索引导致相同关卡,同一用户有多个games
# 允许跳关则直接开启 # 允许跳关则直接开启
game = games.where(user_id: user_id).take identifier = self.identifier
if game.blank? if identifier.blank?
position == 1 ? 1 : 0 self.position == 1 ? 1 : 0
else else
if game.status == 3 if status == 3
shixun.task_pass ? 1 : 0 shixun.task_pass ? 1 : 0
elsif game.status == 2 elsif status == 2
2 2
else else
1 1

@ -19,7 +19,7 @@ if @challenges.present?
json.passed_count challenge.user_passed_count json.passed_count challenge.user_passed_count
json.playing_count challenge.playing_count json.playing_count challenge.playing_count
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.open_game challenge.open_game(@user.id, @shixun) json.open_game challenge.open_game
if @editable if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
@ -27,6 +27,6 @@ if @challenges.present?
json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position
end end
#json.passed challenge.has_passed?(@user.id) #json.passed challenge.has_passed?(@user.id)
json.status challenge.user_tpi_status @user.id json.status challenge.user_tpi_status
end end
end end

Loading…
Cancel
Save