From b2f75d5826d16768c972c00bf6b3220799ee3696 Mon Sep 17 00:00:00 2001 From: gonglexin <18008490802@163.com> Date: Thu, 30 Oct 2014 21:08:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E6=97=B6=E9=97=B4=E5=92=8C=E5=88=86?= =?UTF-8?q?=E6=95=B0=E6=8E=92=E5=BA=8F=E5=A2=9E=E5=8A=A0=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E5=92=8C=E5=80=92=E5=BA=8F=E6=8E=92=E5=BA=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 6 ++++++ app/helpers/application_helper.rb | 8 ++++---- app/views/homework_attach/_homeworks_list.html.erb | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 138030a3c..aa7bc506f 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index be197a7da..e2fdf4739 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/homework_attach/_homeworks_list.html.erb b/app/views/homework_attach/_homeworks_list.html.erb index c3abba458..578c1f9e5 100644 --- a/app/views/homework_attach/_homeworks_list.html.erb +++ b/app/views/homework_attach/_homeworks_list.html.erb @@ -7,9 +7,9 @@ ) 按  - <%= 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) %>