个人主页实训tab
This commit is contained in:
parent
f46860d15b
commit
aa7bb35cc9
|
|
@ -2109,8 +2109,8 @@ class UsersController < ApplicationController
|
|||
@courses = @user.courses.visible.not_deleted
|
||||
@courses_count = @courses.count
|
||||
@courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc").limit(8)
|
||||
@shixuns = []
|
||||
@shixuns_count = 0
|
||||
@shixuns = @user.shixuns
|
||||
@shixuns_count = @shixuns.count
|
||||
# if User.current == @user
|
||||
# # 点击小铃铛,更新点击时间
|
||||
# update_onclick_time if params[:click_user_message] == 'true'
|
||||
|
|
|
|||
|
|
@ -68,6 +68,16 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
# 已通过的关卡数
|
||||
def had_passed_changllenge_count shixun
|
||||
myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => User.current.id).first
|
||||
if myshixun.nil?
|
||||
0
|
||||
else
|
||||
myshixun.games.select{|game| game.status == 2}.count
|
||||
end
|
||||
end
|
||||
|
||||
# 定义实训相关方法
|
||||
def sum_final_score
|
||||
Game.find_by_sql("SELECT sum(final_score) as total_score FROM `games` where user_id=#{User.current.id}").first.try(:total_score)
|
||||
|
|
|
|||
|
|
@ -21,4 +21,5 @@ module ShixunsHelper
|
|||
def had_passed_challenge challenge
|
||||
Game.where(:challenge_id => challenge.id, :status => 2).limit(3).reorder("final_score desc")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class Shixun < ActiveRecord::Base
|
|||
attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, :myshixun_count, :propaedeutics
|
||||
|
||||
has_many :users, :through => :shixun_members
|
||||
has_many :shixun_members
|
||||
has_many :shixun_members, :dependent => :destroy
|
||||
has_one :repository
|
||||
has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC"
|
||||
has_many :myshixuns
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ class User < Principal
|
|||
has_many :contestant_work_scores
|
||||
has_many :contestant_work_projects
|
||||
|
||||
has_many :shixuns, :through => :shixun_members
|
||||
has_many :shixun_members, :dependent => :destroy
|
||||
has_many :challenges, :dependent => :destroy
|
||||
|
||||
|
|
|
|||
|
|
@ -213,11 +213,11 @@
|
|||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="train none" id="my_shixuns_list">
|
||||
<div class="" id="my_shixuns_list">
|
||||
<% @shixuns.each do |shixun| %>
|
||||
<p class="pl10">
|
||||
<span class="font-16 first"><i class="fa fa-circle-o color-orange" aria-hidden="true"></i> 胡莎莎/Helloword:java实训入门</span>
|
||||
<span class="hasmargin font-14"><span class="total mr20 mt10"><em class="part"></em></span>已解锁第<i>2</i>关/共<i>8</i>关</span>
|
||||
<p class="clearfix pl10">
|
||||
<span class="font-16 first"><i class="fa fa-circle-o color-orange" aria-hidden="true"></i> <%= link_to shixun.name, shixun_path %></span>
|
||||
<span class="hasmargin font-14"><span class="total mr20 mt10"><em class="part"></em></span>已解锁第<i><%= had_passed_changllenge_count(shixun) %></i>关/共<i><%= shixun.challenges.count %></i>关</span>
|
||||
<span class="font-14 last cl">分享 <i class="fa fa-weixin font-14 blue" aria-hidden="true"></i></span>
|
||||
</p>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -44,4 +44,5 @@ $(function(){
|
|||
$("#cancel_watch").live('mouseleave',function(){
|
||||
$("#cancel_watch").html("已关注");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue