diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index f7c37d97..e1d89df0 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -16,6 +16,50 @@ class ManagementsController < ApplicationController CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) + # 更新实训课程的等级 + def update_level_for_subject + subject = Subject.find params[:subject_id] + subject.update_attribute(:subject_level_system_id, params[:level_id]) + render :json => {status: 1} + end + + # 实训课程等级体系 + def subject_level_system + @levels = SubjectLevelSystem.all + end + + # 创建课程等级体系 + def create_subject_level + raise("名称不能为空") if params[:name].blank? + repeat_name = SubjectLevelSystem.where(name: params[:name]).count + raise("名称不能重复") if repeat_name > 0 + level = SubjectLevelSystem.pluck(:level).max.to_i + 1 + SubjectLevelSystem.create(name: params[:name], level: level) + redirect_to subject_level_system_managements_path(:format => "js") + end + + # 重命名课程等级 + def rename_subject_level + raise("名称不能为空!") if params[:name].blank? + repeat_name = SubjectLevelSystem.where("name = ? and id != ?", params[:name], params[:id]).count + raise("名称不能重复") if repeat_name > 0 + level = SubjectLevelSystem.find params[:id] + level.update_attribute(:name, params[:name]) + redirect_to subject_level_system_managements_path(:format => "js") + end + + # 删除课程等级 + def delete_subject_level + level = SubjectLevelSystem.find params[:id] + Subject.where(:subject_level_system_id => level).update_all(:subject_level_system_id => nil) + levels = SubjectLevelSystem.where("level > ?", level.level) + levels.each do |l| + l.update_attribute(:level, l.level-1) + end + level.delete + redirect_to subject_level_system_managements_path(:format => "js") + end + # 工程认证视频导入模板 def ec_template @template = EcTemplate.where(nil) @@ -1927,6 +1971,7 @@ end @audit_class_sx_num=Subject.where(:status => 1).count @publish_class_sx_num=Subject.where(:status => 2).count @repertories = Repertoire.where(nil).order("CONVERT( name USING gbk ) COLLATE gbk_chinese_ci ASC") + @levels = SubjectLevelSystem.all search = params[:search] # 搜索字 keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索 status = params[:status].to_i 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/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..bd92c39c 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -18,6 +18,7 @@ class Subject < ActiveRecord::Base has_many :tidings, :as => :container, :dependent => :destroy belongs_to :repertoire belongs_to :user + has_one :subject_level_system scope :visible, lambda{where(status: 2)} @@ -39,6 +40,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/models/subject_level_system.rb b/app/models/subject_level_system.rb new file mode 100644 index 00000000..dae815b2 --- /dev/null +++ b/app/models/subject_level_system.rb @@ -0,0 +1,7 @@ +class SubjectLevelSystem < ActiveRecord::Base + default_scope :order => 'level' + + # attr_accessible :title, :body + has_many :subjects + +end diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index 4f188f78..c6e87870 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -55,7 +55,7 @@
等级 | -名称 | -实训课程数 | -创建时间 | -操作 | - - -
---|---|---|---|---|
1 | -初级课程 | -500 | -2019-03-02 10:38 | -- 删除 - 重命名 - | -
2 | -初级课程 | --- | -2019-03-02 10:38 | -- 删除 - 重命名 - | -
- + 新建 - | -
等级 | +名称 | +实训课程数 | +创建时间 | +操作 | + + + <% @levels.each do |l| %> +
---|---|---|---|---|
<%= l.level %> | +<%= l.name %> | +<%= l.subjects.size %> | +<%= format_time l.created_at %> | ++ 删除 + 重命名 + | +
+ + 新建 + | +
非试用内容,需要授权
+暂未公开
- <%= 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| %>
非试用内容,需要授权
+暂未开发
- <%= 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 %>