优化列表

newyslclassrooms
daiao 5 years ago
parent 25956ec86e
commit f8af1125d3

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

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

@ -19,7 +19,7 @@ if @challenges.present?
json.passed_count challenge.user_passed_count
json.playing_count challenge.playing_count
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
json.edit_url edit_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
end
#json.passed challenge.has_passed?(@user.id)
json.status challenge.user_tpi_status @user.id
json.status challenge.user_tpi_status
end
end

Loading…
Cancel
Save