给时间和分数排序增加顺序和倒序排序功能
This commit is contained in:
parent
bb642d320d
commit
b2f75d5826
|
@ -11,6 +11,7 @@ class HomeworkAttachController < ApplicationController
|
|||
|
||||
#获取未批作业列表
|
||||
def get_not_batch_homework
|
||||
sort, direction = params[:sort], params[: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,
|
||||
|
@ -19,6 +20,7 @@ class HomeworkAttachController < ApplicationController
|
|||
WHERE table1.t_score IS NULL")
|
||||
|
||||
@homework_list = paginateHelper all_homework_list,10
|
||||
@direction = direction == 'asc'? 'desc' : 'asc'
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
@ -26,6 +28,7 @@ class HomeworkAttachController < ApplicationController
|
|||
|
||||
#获取已评作业列表
|
||||
def get_batch_homeworks
|
||||
sort, direction = params[:sort], params[:direction]
|
||||
teachers = find_course_teachers @course
|
||||
teacher_proportion = get_teacher_proportion @bid
|
||||
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
|
||||
|
@ -35,6 +38,7 @@ class HomeworkAttachController < ApplicationController
|
|||
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
|
||||
WHERE table1.t_score IS NOT NULL")
|
||||
@homework_list = paginateHelper all_homework_list,10
|
||||
@direction = direction == 'asc'? 'desc' : 'asc'
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
@ -42,6 +46,7 @@ class HomeworkAttachController < ApplicationController
|
|||
|
||||
#获取所有作业列表
|
||||
def get_homeworks
|
||||
sort, direction = params[:sort], params[:direction]
|
||||
teachers = find_course_teachers @course
|
||||
teacher_proportion = get_teacher_proportion @bid
|
||||
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
|
||||
|
@ -50,6 +55,7 @@ class HomeworkAttachController < ApplicationController
|
|||
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")
|
||||
@homework_list = paginateHelper all_homework_list,10
|
||||
@direction = direction == 'asc'? 'desc' : 'asc'
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
|
@ -1892,14 +1892,14 @@ module ApplicationHelper
|
|||
content_tag(:ul, logos.join("").html_safe, :class => ul_class.to_s).html_safe
|
||||
end
|
||||
|
||||
def sort_homework_path(bid, sort)
|
||||
def sort_homework_path(bid, sort, direction)
|
||||
case self.action_name
|
||||
when 'get_not_batch_homework', 'show_courseEx'
|
||||
get_not_batch_homework_homework_attach_path(bid, sort: sort)
|
||||
get_not_batch_homework_homework_attach_path(bid, sort: sort, direction: direction)
|
||||
when 'get_batch_homeworks'
|
||||
get_batch_homeworks_homework_attach_path(bid, sort: sort)
|
||||
get_batch_homeworks_homework_attach_path(bid, sort: sort, direction: direction)
|
||||
when 'get_homeworks'
|
||||
get_homeworks_homework_attach_path(bid, sort: sort)
|
||||
get_homeworks_homework_attach_path(bid, sort: sort, direction: direction)
|
||||
else
|
||||
'#'
|
||||
end
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
</font>)
|
||||
</span><span class="fr">
|
||||
按
|
||||
<%= link_to l(:label_work_rating), sort_homework_path(@bid, 'socre'), {:remote => true}%>
|
||||
<%= link_to l(:label_work_rating), sort_homework_path(@bid, 'socre', @direction), {:remote => true}%>
|
||||
/
|
||||
<%= link_to l(:label_time), sort_homework_path(@bid, 'time'), {:remote => true}%>
|
||||
<%= link_to l(:label_time), sort_homework_path(@bid, 'time', @direction), {:remote => true}%>
|
||||
<%= l(:label_sort) %>
|
||||
</span>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue