diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 0c16cbb9..a1e7299a 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -30,19 +30,30 @@ class WelcomeController < ApplicationController require 'simple_xlsx_reader' def index - @shixuns = Shixun.select([:id, :user_id, :homepage_show, :identifier, :status, :name, :challenges_count, :myshixuns_count, :use_scope, - :trainee]).where(:homepage_show => 1).includes(:users, :shixun_tag_repertoires, challenges: :challenge_chooses).order("myshixuns_count desc").limit(8) - @subjects = Subject.select([:id, :name, :homepage_show, :user_id, :visits, :stages_count, :score_count, :repertoire_id]).where(:homepage_show => 1).includes(:users, stages: :stage_shixuns) - @subjects.each do |subject| - subject[:myshixun_member_count] = Myshixun.where(:shixun_id=>subject.stage_shixuns.map(&:shixun_id)).count + images = PortalImage.where(status: true).order("position asc") + @images_url = [] + images.each do |image| + @images_url << {path: image.link, image_url: "/images/avatars/PortalImage/#{image.id}"} end - @subjects = @subjects.sort{|x,y| y[:myshixun_member_count] <=> x[:myshixun_member_count] }[0, 8] - @tea_users = User.where(:homepage_teacher => 1).includes(:user_extensions).limit(10).order("experience desc") - @eng_users = User.where(:homepage_engineer => 1).includes(:user_extensions).limit(10).order("experience desc") - @eng_users = User.find_by_sql("select u.* from users u join user_extensions ue on ue.user_id = u.id where ue.identity = 1 order by experience desc limit 10") if @eng_users.blank? - @repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc") - @images = PortalImage.where(:status => true).order("position asc") - logger.info("########images: #{@images.count}") + # 目录分级 + repertoires = Repertoire.includes(sub_repertoires: :tag_repertoires).order("updated_at asc") + @rep_list = [] + repertoires.each do |rep| + sub_rep_list = [] + rep.sub_repertoires.each do |sub_rep| + tag_rep_list = [] + sub_rep.tag_repertoires.each do |tag_rep| + tag_rep_list << {tag_id: tag_rep.id, tag_name: tag_rep.name} + end + sub_rep_list << {sub_rep_id: sub_rep.id, sub_rep_name: sub_rep.name, tag_rep_list: tag_rep_list} + end + @rep_list << {rep_id: rep.id, rep_name: rep.name, sub_rep_list: sub_rep_list} + end + @shixuns = Shixun.select([:id, :user_id, :homepage_show, :identifier, :status, :name, :challenges_count, :myshixuns_count, :use_scope, + :trainee, :averge_star]).where(homepage_show: 1).includes(:tag_repertoires).order("myshixuns_count desc").limit(8) + @subjects = Subject.where(homepage_show: 1).includes(:shixuns).limit(8) + @tea_users = User.where(homepage_teacher: 1).includes(:user_extensions).limit(10).order("experience desc") + @stu_users = User.includes(:user_extensions).where(user_extensions: {identity: 1}).limit(10).order("experience desc") render :layout => 'educoder' end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bd7e961a..66b6c745 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -240,7 +240,7 @@ module ApplicationHelper container = [] mirror_repositories.each do |mr| if mr.name.present? - container << {:image => mr.name, :cpuLimit => mr.cpu_limit, :memoryLimit => "#{mr.memory_limit}M"} + container << {:image => mr.name, :cpuLimit => mr.cpu_limit, :memoryLimit => "#{mr.memory_limit}M", :type => mr.try(:main_type) == "1" ? "main" : "sub"} end end return container.to_json diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 1bd7805c..0a7fff62 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -49,7 +49,7 @@ class Shixun < ActiveRecord::Base has_many :schools, :through => :shixun_schools has_many :exercise_shixun_challenges, :dependent => :destroy has_many :exercise_bank_shixun_challenges, :dependent => :destroy - has_many :tag_repertoires, :through => :shixun_tag_repertoires, :order => "tag_repertoires.name ASC" + has_many :tag_repertoires, :through => :shixun_tag_repertoires has_many :shixun_tag_repertoires, :dependent => :destroy diff --git a/app/views/shixuns/_shixun_item.html.erb b/app/views/shixuns/_shixun_item.html.erb index 81bc0f25..40420a8b 100644 --- a/app/views/shixuns/_shixun_item.html.erb +++ b/app/views/shixuns/_shixun_item.html.erb @@ -1,25 +1,26 @@ - +<% result = User.current.is_certification_teacher || User.current.admin? %> <% shixuns.each do |shixun| %>
<% if shixun.tag_repertoires.first.present? %>
<%= shixun.tag_repertoires.first.try(:name) %>
<% end %> - <% if params[:controller] != "welcome" && shixun_view_allow(shixun, true) %> + <% unless result %>
-

非试用内容,需要授权

+

暂未公开

<% end %> - + " class="square-img" target="_blank"> <%= image_tag(url_to_avatar(shixun)) %>

- <%= shixun.name %> + " class="justify color-grey-name" title="<%= shixun.name %>" target="_blank"><%= shixun.name %>

-

<%= shixun.shixun_preference %>分

+

+ <%= shixun.averge_star %>分

<% if shixun.challenges_count > 0 %> @@ -27,14 +28,9 @@ <%= shixun.challenges_count %> <% end %> - <% if shixun.shixun_score > 0 %> - - <%= shixun.shixun_score %> - - <% end %> - <% if shixun.myshixuns.count > 0 %> + <% if shixun.myshixuns_count > 0 %> - <%= shixun.myshixuns.count %> + <%= shixun.myshixuns_count %> <% end %> <%= shixun.shixun_level %> @@ -44,24 +40,24 @@ <% end %> \ No newline at end of file + }); + }) + diff --git a/app/views/subjects/_subject_item.html.erb b/app/views/subjects/_subject_item.html.erb index 4632750b..ac08c8a6 100644 --- a/app/views/subjects/_subject_item.html.erb +++ b/app/views/subjects/_subject_item.html.erb @@ -1,37 +1,27 @@ +<% result = User.current.is_certification_teacher || User.current.admin? %> <% subjects.each do |subject| %>

<% if subject.repertoire.present? %>
<%= subject.repertoire.name %>
<% end %> - <% if params[:controller] != "welcome" && subject.status < 2 && !User.current.member_of_subject?(subject) %> + <% unless result %>
-

非试用内容,需要授权

+

暂未开发

<% end %> - <%= image_tag(url_to_avatar(subject)) %> + " class="square-img" target="_blank"><%= image_tag(url_to_avatar(subject)) %>

- <%= link_to subject.name, subject_path(subject), :class => "justify color-grey-name", :target => "_blank" %> + <%= link_to subject.name, "#{result ? subject_path(subject) : "javascript:void(0);"}", :class => "justify color-grey-name", :target => "_blank" %>

<% if subject.stages_count > 0 %> <%= subject.stages_count %> <% end %> - <% if params[:controller] == "welcome" %> - - <%= subject.subject_shixun_score + subject.subject_shixun_choose_score %> - <% else %> - <% if (subject.subject_shixun_score + subject.subject_shixun_choose_score) > 0 %> - - <%= subject.subject_shixun_score + subject.subject_shixun_choose_score %> - <% end %> - <% end %> - <% myshixun_member_count = subject.respond_to?("myshixun_member_count") ? subject.myshixun_member_count : Myshixun.where(:shixun_id=>subject.stage_shixuns.map(&:shixun_id)).count %> - <%# REDO:汗!!!这块的关联关系有问题,所以这个统计的N+1问题没法避免。可以考虑改关联关系或者写单字段 %> - <% if myshixun_member_count > 0 %> - <%= myshixun_member_count %> + <% if subject.member_count > 0 %> + <%= subject.member_count %> <% end %>

diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 837d1e9b..f9a52452 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -7,17 +7,17 @@