diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index d2d9a2360..e85f21517 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -6,7 +6,8 @@ class HomeworkAttachController < ApplicationController ############################### before_filter :can_show_course,except: [] #判断当前角色权限时需先找到当前操作的project - before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours] + before_filter :find_course_by_bid_id, :only => [:new] + before_filter :find_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours] before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users] #判断当前角色是否有操作权限 #勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy] @@ -14,13 +15,13 @@ class HomeworkAttachController < ApplicationController #获取未批作业列表 def get_not_batch_homework sort, direction = params[:sort], params[:direction] - order_by = sort == 'score'? "s_score #{direction}" : "created_at #{direction}" - + order_by = sort == 'socre'? "s_score #{direction}" : "created_at #{direction}" teachers = find_course_teachers @course all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score - FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}) AS table1 + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY #{order_by}) AS table1 WHERE table1.t_score IS NULL") @homework_list = paginateHelper all_homework_list,10 @@ -33,13 +34,14 @@ class HomeworkAttachController < ApplicationController #获取已评作业列表 def get_batch_homeworks sort, direction = params[:sort], params[:direction] - teachers = find_course_teachers @course teacher_proportion = get_teacher_proportion @bid + order_by = sort == 'socre'? "(CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) #{direction}" : "created_at #{direction}" + teachers = find_course_teachers @course all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers} and stars IS NOT NULL) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} - ORDER BY (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC) AS table1 + ORDER BY #{order_by}) AS table1 WHERE table1.t_score IS NOT NULL") @homework_list = paginateHelper all_homework_list,10 @direction = direction == 'asc'? 'desc' : 'asc' @@ -51,13 +53,14 @@ class HomeworkAttachController < ApplicationController #获取所有作业列表 def get_homeworks sort, direction = params[:sort], params[:direction] - teachers = find_course_teachers @course teacher_proportion = get_teacher_proportion @bid + order_by = sort == 'socre'? "(CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) #{direction}" : "created_at #{direction}" + teachers = find_course_teachers @course all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} - ORDER BY (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC") + ORDER BY #{order_by}") @homework_list = paginateHelper all_homework_list,10 @direction = direction == 'asc'? 'desc' : 'asc' respond_to do |format| @@ -391,6 +394,13 @@ class HomeworkAttachController < ApplicationController end end + def find_bid_and_course + @bid = Bid.find(params[:bid_id]) + @course = @bid.courses.first + rescue ActiveRecord::RecordNotFound + render_404 + end + def find_course_by_bid_id @bid = Bid.find(params[:id]) @course = @bid.courses.first diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4be91c9b4..07d2dd4ba 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1896,13 +1896,13 @@ module ApplicationHelper def sort_homework_path(bid, sort, direction) case self.action_name when 'show_courseEx' - get_not_batch_homework_homework_attach_path(bid, sort: sort, direction: 'asc') + get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: 'asc') when 'get_not_batch_homework' - get_not_batch_homework_homework_attach_path(bid, sort: sort, direction: direction) + get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) when 'get_batch_homeworks' - get_batch_homeworks_homework_attach_path(bid, sort: sort, direction: direction) + get_batch_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) when 'get_homeworks' - get_homeworks_homework_attach_path(bid, sort: sort, direction: direction) + get_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) else '#' end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 960e3acff..ab067fdd0 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -14,17 +14,17 @@
@@ -32,7 +32,7 @@
- <%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid}%> + <%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => false}%>
diff --git a/app/views/homework_attach/_homeworks_list.html.erb b/app/views/homework_attach/_homeworks_list.html.erb index 578c1f9e5..4d456c3ae 100644 --- a/app/views/homework_attach/_homeworks_list.html.erb +++ b/app/views/homework_attach/_homeworks_list.html.erb @@ -20,9 +20,10 @@