diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 43e9ef82..c2132bf1 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1533,6 +1533,16 @@ class CoursesController < ApplicationController end end + # 删除实训作业子目录 + def delete_homework_category + category = @course.course_homework_categories.where(:id => params[:category_id]).first + if category.present? + category.homework_commons.update_all(:course_homework_category_id => nil) + category.destroy + end + redirect_to homework_common_index_path(:course => @course.id, :homework_type => 4) + end + def toggleCourse @course_prefs = Course.find_by_extra(@course.extra) unless (User.current.allowed_to?(:as_teacher,@course_prefs) || User.current.admin?) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index f7c37d97..fe5aa922 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 @@ -3120,13 +3165,14 @@ end def update_notice @menu_type = 12 @sub_type = 8 - @notice = SystemUpdateNotice.first + @notice = SystemUpdateNotice.last end def edit_update_notice - notice = SystemUpdateNotice.first - if notice.present? + notice = SystemUpdateNotice.last + if notice.present? && notice.end_time > Time.now notice.update_attributes(:end_time => params[:end_time], :start_time => params[:start_time], :subject => params[:subject], :notes => params[:notes]) + UserSystemNotice.where(:notice_type => notice.notice_type).destroy_all else notice_type = UserSystemNotice.find_by_sql("select max(notice_type) as max_notice_type from user_system_notices").first.try(:max_notice_type).to_i + 1 SystemUpdateNotice.create(:end_time => params[:end_time], :start_time => params[:start_time], :subject => params[:subject], :notes => params[:notes], :notice_type => notice_type) 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/users_controller.rb b/app/controllers/users_controller.rb index 2e958f6f..e44a170b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2372,7 +2372,7 @@ class UsersController < ApplicationController if @user.certification == 3 @user.update_column('certification', 0) @noticed = true - notice = SystemUpdateNotice.first + notice = SystemUpdateNotice.last if notice.present? && notice.end_time > Time.now && notice.start_time >= Time.now - 21600 && User.current.user_system_notices.where(:notice_type => notice.notice_type).count == 0 @noticed_update = true end 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 e6645b3f..8b58703a 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 @@ -5016,12 +5016,13 @@ module ApplicationHelper link_to "开始实战", shixun_path(homework.homework_commons_shixuns.shixun), :class => 'edu-default-btn user_bluebg_btn fr mr20 pl7 pr7',:target => "_blank" else myshixun = Myshixun.where(:id => work.myshixun_id).first - is_modify = ShixunModify.where(:myshixun_id => myshixun.try(:id), :shixun_id => myshixun.shixun.try(:id), :status => 1).first - if myshixun && is_modify.blank? - link_to "继续实战", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "edu-default-btn user_orangebg_btn fr mr20 pl7 pr7", :target => "_blank" - elsif myshixun - link_to "继续实战", 'javascript:void(0);', :onclick => "sure_box_redirect('#{myshixun_reset_myshixun_path(myshixun)}', '实训已经更新啦,系统正在为您重置');", :class => "edu-default-btn user_orangebg_btn fr mr20 pl7 pr7" - end + # is_modify = ShixunModify.where(:myshixun_id => myshixun.try(:id), :shixun_id => myshixun.shixun.try(:id), :status => 1).first + link_to "继续实战", shixun_path(myshixun.shixun), :class => "edu-default-btn user_orangebg_btn fr mr20 pl7 pr7", :target => "_blank" + # if myshixun && is_modify.blank? + # link_to "继续实战", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "edu-default-btn user_orangebg_btn fr mr20 pl7 pr7", :target => "_blank" + # elsif myshixun + # link_to "继续实战", 'javascript:void(0);', :onclick => "sure_box_redirect('#{myshixun_reset_myshixun_path(myshixun)}', '实训已经更新啦,系统正在为您重置');", :class => "edu-default-btn user_orangebg_btn fr mr20 pl7 pr7" + # end end elsif work.nil? && setting_time.end_time >= Time.now if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 8d6265c6..c40a9a54 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -173,12 +173,13 @@ module StudentWorkHelper elsif work if homework.homework_type == 4 myshixun = Myshixun.find work.myshixun_id - is_modify = ShixunModify.where(:myshixun_id => myshixun.try(:id), :shixun_id => myshixun.shixun.try(:id), :status => 1).first - if myshixun && is_modify.blank? - link_to "继续实战", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "white-btn orange-btn fr mr10 mt8", :target => "_blank" - elsif myshixun - link_to "继续实战", 'javascript:void(0);', :onclick => "sure_box_redirect('#{myshixun_reset_myshixun_path(myshixun)}', '实训已经更新啦,系统正在为您重置');", :class => "white-btn orange-btn fr mr10 mt8" - end + # is_modify = ShixunModify.where(:myshixun_id => myshixun.try(:id), :shixun_id => myshixun.shixun.try(:id), :status => 1).first + link_to "继续实战", shixun_path(myshixun.shixun), :class => "white-btn orange-btn fr mr10 mt8", :target => "_blank" + # if myshixun && is_modify.blank? + # link_to "继续实战", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "white-btn orange-btn fr mr10 mt8", :target => "_blank" + # elsif myshixun + # link_to "继续实战", 'javascript:void(0);', :onclick => "sure_box_redirect('#{myshixun_reset_myshixun_path(myshixun)}', '实训已经更新啦,系统正在为您重置');", :class => "white-btn orange-btn fr mr10 mt8" + # end else if setting_time.end_time >= Time.now link_to "修改作品", edit_student_work_url_without_domain(work.id), :class => 'white-btn orange-btn fr mr10 mt8' diff --git a/app/models/course_homework_category.rb b/app/models/course_homework_category.rb index 6a1f900e..6e27de18 100644 --- a/app/models/course_homework_category.rb +++ b/app/models/course_homework_category.rb @@ -1,5 +1,5 @@ class CourseHomeworkCategory < ActiveRecord::Base belongs_to :course - has_many :shixun_homework_categories + has_many :homework_commons attr_accessible :name 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/homework_common/index.html.erb b/app/views/homework_common/index.html.erb index b03e56dd..931537a7 100644 --- a/app/views/homework_common/index.html.erb +++ b/app/views/homework_common/index.html.erb @@ -11,6 +11,7 @@ <%= link_to '选用实训', shixuns_homework_common_index_path(:course => @course.id, :category_id => @category.try(:id)), :remote => true, :class => "white-btn edu-orangeback-btn fr mr20 mt2", :title => "新建作业" %> <% if @category.present? %> 子栏目重命名 + 删除子目录 <% else %> 添加子栏目 <% end %> diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 0b7bb769..ee3a571d 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -117,13 +117,13 @@ <% end %> - <% notice = SystemUpdateNotice.first %> + <% notice = SystemUpdateNotice.last %> <% if @noticed_update || ((User.current.certification == 1 || params[:controller] != "welcome") && notice.present? && notice.end_time > Time.now && notice.start_time >= (Time.now - 21600) && User.current.user_system_notices.where(:notice_type => notice.notice_type).count == 0) %> var htmlvalue = "<%= escape_javascript(render :partial => 'account/user_update_notice', :locals => {:notice => notice})%>"; pop_box_new(htmlvalue, 500, 380); <% UserSystemNotice.create(:user_id => User.current.id, :notice_type => notice.notice_type) %> - <% elsif notice.present? && notice.end_time < Time.now %> - <% notice.destroy %> + <%# elsif notice.present? && notice.end_time < Time.now %> + <%# notice.destroy %> <% end %> }); diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index e685d10d..c6e87870 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -55,9 +55,10 @@
等级 | +名称 | +实训课程数 | +创建时间 | +操作 | + + + <% @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 %>