From aa7bb35cc9cbb6a97a660888b6bc89af6db4483d Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 19 May 2017 10:34:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5=E5=AE=9E?= =?UTF-8?q?=E8=AE=ADtab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 4 ++-- app/helpers/application_helper.rb | 10 ++++++++++ app/helpers/shixuns_helper.rb | 1 + app/models/shixun.rb | 2 +- app/models/user.rb | 1 + app/views/users/show.html.erb | 8 ++++---- public/javascripts/edu/user.js | 3 ++- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 14af87c5c..80faef066 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 97b4ae6e6..99159e721 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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) diff --git a/app/helpers/shixuns_helper.rb b/app/helpers/shixuns_helper.rb index 635645587..6a9004aca 100644 --- a/app/helpers/shixuns_helper.rb +++ b/app/helpers/shixuns_helper.rb @@ -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 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index be8c7b989..988bdd557 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 19e3d83b7..a3fdc06b2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 50e855ddd..c0ec981ea 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -213,11 +213,11 @@ <% end %> -
+
<% @shixuns.each do |shixun| %> -

-   胡莎莎/Helloword:java实训入门 - 已解锁第2关/共8 +

+   <%= link_to shixun.name, shixun_path %> + 已解锁第<%= had_passed_changllenge_count(shixun) %>关/共<%= shixun.challenges.count %> 分享  

<% end %> diff --git a/public/javascripts/edu/user.js b/public/javascripts/edu/user.js index acc551eb9..6bb75bc77 100644 --- a/public/javascripts/edu/user.js +++ b/public/javascripts/edu/user.js @@ -44,4 +44,5 @@ $(function(){ $("#cancel_watch").live('mouseleave',function(){ $("#cancel_watch").html("已关注"); }); -}); \ No newline at end of file +}); +