From 3fa5a4b3c5f2dc54fda1f4903d0e1701080847a2 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 30 Oct 2014 16:33:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E8=AF=BE=E7=A8=8B=E7=95=99?= =?UTF-8?q?=E8=A8=80=E7=95=8C=E9=9D=A2=E7=9A=84=E8=B7=AF=E7=94=B1=202.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=82=B9=E5=87=BB=E5=B7=B2=E6=89=B9=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E3=80=81=E6=9C=AA=E6=89=B9=E4=BD=9C=E4=B8=9A=E3=80=81?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E4=BD=9C=E4=B8=9A=E3=80=81=E7=95=99=E8=A8=80?= =?UTF-8?q?=E7=9A=84ajax=E8=B0=83=E7=94=A8=203.=E5=AE=9E=E7=8E=B0=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=B7=B2=E6=89=B9=E4=BD=9C=E4=B8=9A=E3=80=81=E6=9C=AA?= =?UTF-8?q?=E6=89=B9=E4=BD=9C=E4=B8=9A=E3=80=81=E5=85=A8=E9=83=A8=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E3=80=81=E7=95=99=E8=A8=80=E6=97=B6=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 67 ++++++++++- app/views/bids/_homework_list.html.erb | 109 ++---------------- .../homework_attach/_homework_jours.html.erb | 7 ++ ...work.html.erb => _homeworks_list.html.erb} | 0 .../get_batch_homeworks.js.erb | 1 + .../homework_attach/get_homework_jours.js.erb | 1 + .../homework_attach/get_homeworks.js.erb | 2 + .../get_not_batch_homework.js.erb | 1 + config/routes.rb | 3 + 9 files changed, 91 insertions(+), 100 deletions(-) create mode 100644 app/views/homework_attach/_homework_jours.html.erb rename app/views/homework_attach/{_not_batch_homwork.html.erb => _homeworks_list.html.erb} (100%) create mode 100644 app/views/homework_attach/get_batch_homeworks.js.erb create mode 100644 app/views/homework_attach/get_homework_jours.js.erb create mode 100644 app/views/homework_attach/get_homeworks.js.erb create mode 100644 app/views/homework_attach/get_not_batch_homework.js.erb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 4a9e3bb1f..b2ecf7cba 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -4,14 +4,61 @@ class HomeworkAttachController < ApplicationController ############################### before_filter :can_show_course,except: [] #判断当前角色权限时需先找到当前操作的project - before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework] + 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_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users] #判断当前角色是否有操作权限 #勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy] #获取未批作业列表 def get_not_batch_homework - @homeworks = HomeworkAttach.all + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @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 s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取已评作业列表 + def get_batch_homeworks + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @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 s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取所有作业列表 + def get_homeworks + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @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 s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取作业的留言列表 + def get_homework_jours respond_to do |format| format.js end @@ -328,7 +375,7 @@ class HomeworkAttachController < ApplicationController def find_course_by_bid_id @bid = Bid.find(params[:id]) - @course = @bid.courses[0] + @course = @bid.courses.first rescue ActiveRecord::RecordNotFound render_404 end @@ -337,5 +384,19 @@ class HomeworkAttachController < ApplicationController @homework = HomeworkAttach.find(params[:id]) @course = @homework.bid.courses[0] end + + #获取课程的老师列表 + def find_course_teachers course + teachers = "(" + teacher_members = searchTeacherAndAssistant(course) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + teachers + end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 947dd455f..46bdf4b3d 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -2,20 +2,8 @@