diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 731a3741..f147b9b2 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -321,9 +321,9 @@ class ShixunsController < ApplicationController @search_name = "#{sub.name} / #{tag.name}" end shixun_id = ShixunTagRepertoire.where(:tag_repertoire_id => tag).map(&:shixun_id) - @shixuns = Shixun.select([:id, :name, :user_id, :challenges_count, :visits, :status, :myshixuns_count, :trainee, :use_scope, :identifier, :image_text]).where(:id => shixun_id, :hidden => 0).includes(:challenges, :schools, :shixun_members, :users).order("status = 2 desc, publish_time asc") + @shixuns = Shixun.select([:id, :name, :user_id, :challenges_count, :visits, :status, :myshixuns_count, :trainee, :use_scope, :identifier, :image_text, :averge_star]).where(:id => shixun_id, :hidden => 0).includes(:challenges, :schools, :shixun_members, :users).order("status = 2 desc, publish_time asc") else - @shixuns = Shixun.select([:id, :name, :user_id, :challenges_count, :visits, :status, :myshixuns_count, :trainee, :use_scope, :identifier, :image_text]).where(:hidden => 0).includes(:challenges, :schools, :shixun_members, :users).order("status = 2 desc, publish_time asc") + @shixuns = Shixun.select([:id, :name, :user_id, :challenges_count, :visits, :status, :myshixuns_count, :trainee, :use_scope, :identifier, :image_text, :averge_star]).where(:hidden => 0).includes(:challenges, :schools, :shixun_members, :users).order("status = 2 desc, publish_time asc") end # # 依据tag和语言推荐实训,如果tag不够,则依据语言推荐;语言不够,则取系统的三个 # @recommend_shixuns = Shixun.find_by_sql("select challenge_id from challenge_tags where name like 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..b4b156a0 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 @@ -318,11 +318,15 @@ module ApplicationHelper # TPM查看权限 # result一般为页面权限 def shixun_view_allow shixun, result = nil - if User.current.manager_of_shixun?(shixun) + if params[:openi].to_i == 1 result ? false : true else - if shixun.status == 0 || (shixun.use_scope == 1 && !shixun.schools.map(&:name).include?(User.current.school_name)) - result ? true : (render_403) + if User.current.manager_of_shixun?(shixun) + result ? false : true + else + if shixun.status == 0 || (shixun.use_scope == 1 && !shixun.schools.map(&:name).include?(User.current.school_name)) + result ? true : (render_403) + end end end end 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/models/subject.rb b/app/models/subject.rb index 4388839c..c416974e 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -39,6 +39,10 @@ class Subject < ActiveRecord::Base count end + def member_count + self.shixuns.map(&:myshixuns_count).sum + end + def subject_shixuns count = 0 self.stage_shixuns.each do |stage_shixun| diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index e685d10d..4f188f78 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -55,9 +55,10 @@
  • 实训课程+
  • 职业路径
  • diff --git a/app/views/managements/_class_level_system.html.erb b/app/views/managements/_class_level_system.html.erb new file mode 100644 index 00000000..7a25d233 --- /dev/null +++ b/app/views/managements/_class_level_system.html.erb @@ -0,0 +1,88 @@ +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    等级名称实训课程数创建时间操作
    1初级课程5002019-03-02 10:38 + 删除 + 重命名 +
    2初级课程--2019-03-02 10:38 + 删除 + 重命名 +
    + + 新建 +
    +
    + + + \ No newline at end of file diff --git a/app/views/managements/_subject_list.html.erb b/app/views/managements/_subject_list.html.erb index 24ca38ba..abc18548 100644 --- a/app/views/managements/_subject_list.html.erb +++ b/app/views/managements/_subject_list.html.erb @@ -3,9 +3,10 @@ ID - 实训套件名称 + 实训套件名称 阶段 技术体系 + 等级体系 上传图片 创建者 创建时间 color-light-green ml5"> @@ -26,6 +27,11 @@ <% end %> + + + <%= file_field_tag 'avatar[image]', :id => "upload_img_#{c_shixun.id}", 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..abcf0f11 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.try(:member_count).to_i > 0 %> + <%= subject.try(: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 @@