From 52dabc6b984c5f70ced86f5209bac77d4f4bac06 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 31 Oct 2014 17:47:39 +0800 Subject: [PATCH 1/4] =?UTF-8?q?1.=E5=8F=96=E6=B6=88=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E6=94=B9=E4=BD=9C=E4=B8=9A=E6=97=B6=E4=BA=92?= =?UTF-8?q?=E8=AF=84=E5=8A=9F=E8=83=BD=E7=9A=84=E6=B7=BB=E5=8A=A0=202.?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E9=A1=B5=E9=9D=A2=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=81=E5=8F=96=E6=B6=88=E5=88=A0=E9=99=A4=E8=80=81=E5=B8=88?= =?UTF-8?q?=E5=B8=83=E7=BD=AE=E4=BD=9C=E4=B8=9A=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/bids/_bid_homework_show.html.erb | 217 +++++++++++++-------- app/views/courses/_homework_form.html.erb | 2 +- 2 files changed, 136 insertions(+), 83 deletions(-) diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index d452b6d53..469a9e85d 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -5,94 +5,147 @@ <% else %> <% bids.each do |bid|%>
<%= link_to(image_tag(url_to_avatar(bid.author), :class => 'avatar'), user_path(bid.author), :class => "avatar") %> | -
-
|
+
From c045b4682a6328c7d3f0a5b6e3cf541d5a2d9744 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 31 Oct 2014 19:30:49 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8C=BF=E8=AF=84?= =?UTF-8?q?=E5=88=86=E9=85=8D=E4=BD=9C=E4=B8=9A=E8=A1=A8=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=92=8C=E4=BD=9C=E4=B8=9A=E3=80=81=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E3=80=81=E7=94=A8=E6=88=B7=E8=A1=A8=E5=85=B3=E7=B3=BB=E9=94=AE?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/bid.rb | 1 + app/models/homework_attach.rb | 1 + app/models/homework_evaluation.rb | 6 ++++++ app/models/user.rb | 1 + .../20141031111632_create_homework_evaluations.rb | 10 ++++++++++ db/schema.rb | 9 ++++++++- 6 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/models/homework_evaluation.rb create mode 100644 db/migrate/20141031111632_create_homework_evaluations.rb diff --git a/app/models/bid.rb b/app/models/bid.rb index bc00a8460..88014477b 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -28,6 +28,7 @@ class Bid < ActiveRecord::Base has_many :homework_for_courses, :dependent => :destroy has_many :courses, :through => :homework_for_courses, :source => :course has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy + has_many :homework_evaluations, :through => :homeworks has_many :join_in_contests, :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy # has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}" diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index 99d540bd1..e18e254cb 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -10,6 +10,7 @@ class HomeworkAttach < ActiveRecord::Base has_many :users, :through => :homework_users seems_rateable :allow_update => true, :dimensions => :quality belongs_to :project + has_many :homework_evaluations, :dependent => :destroy safe_attributes "bid_id", "user_id" diff --git a/app/models/homework_evaluation.rb b/app/models/homework_evaluation.rb new file mode 100644 index 000000000..ccbd26f8c --- /dev/null +++ b/app/models/homework_evaluation.rb @@ -0,0 +1,6 @@ +class HomeworkEvaluation < ActiveRecord::Base + attr_accessible :homework_attach_id, :user_id + + belongs_to :homework_attach + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 0bb359812..bbee7f763 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -75,6 +75,7 @@ class User < Principal has_many :homework_users has_many :homework_attaches, :through => :homework_users + has_many :homework_evaluations has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} diff --git a/db/migrate/20141031111632_create_homework_evaluations.rb b/db/migrate/20141031111632_create_homework_evaluations.rb new file mode 100644 index 000000000..39b65a033 --- /dev/null +++ b/db/migrate/20141031111632_create_homework_evaluations.rb @@ -0,0 +1,10 @@ +class CreateHomeworkEvaluations < ActiveRecord::Migration + def change + create_table :homework_evaluations do |t| + t.string :user_id + t.string :homework_attach_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4d194b54e..3961db258 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20141029065917) do +ActiveRecord::Schema.define(:version => 20141031111632) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -478,6 +478,13 @@ ActiveRecord::Schema.define(:version => 20141029065917) do t.integer "project_id", :default => 0 end + create_table "homework_evaluations", :force => true do |t| + t.string "user_id" + t.string "homework_attach_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "homework_for_courses", :force => true do |t| t.integer "course_id" t.integer "bid_id" From 58d23067284e7f385d4e2bbe3eee23ce514e853b Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sat, 1 Nov 2014 11:02:13 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E8=AF=BE=E7=A8=8B=E4=BD=9C=E4=B8=9A=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=90=8E=E7=9B=B8=E5=85=B3=E7=9A=84=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E3=80=81=E7=95=8C=E9=9D=A2=E5=8A=A8=E6=80=81=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 31 ++++++++------ app/controllers/homework_attach_controller.rb | 42 ++++++++++++++++++- app/views/bids/_homework_list.html.erb | 12 +++--- .../homework_attach/get_homework_jours.js.erb | 3 ++ .../homework_attach/get_homeworks.js.erb | 3 ++ .../homework_attach/get_my_homework.js.erb | 4 ++ .../get_not_batch_homework.js.erb | 2 +- .../get_student_batch_homework.js.erb | 4 ++ config/routes.rb | 2 + 9 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 app/views/homework_attach/get_my_homework.js.erb create mode 100644 app/views/homework_attach/get_student_batch_homework.js.erb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 49760f734..fcb62ea46 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -490,24 +490,31 @@ class BidsController < ApplicationController if @bid.homework_type @homework = HomeworkAttach.new @is_teacher = is_course_teacher(User.current,@bid.courses.first) - #if @is_teacher - teachers = "(" - teacher_members = searchTeacherAndAssistant(@bid.courses.first) - teacher_members.each do |member| - if member == teacher_members.last - teachers += member.user_id.to_s + ")" - else - teachers += member.user_id.to_s + "," - end + teachers = "(" + teacher_members = searchTeacherAndAssistant(@bid.courses.first) + 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 + if @is_teacher 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 s_score DESC,created_at ASC) AS table1 WHERE table1.t_score IS NULL") - #else - # all_homework_list = HomeworkAttach.all - #end + else + 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, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = 3123) AS m_score + FROM homework_attaches + INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id + WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id}) AS table1 + WHERE table1.m_score IS NULL") + end @homework_list = paginateHelper all_homework_list,10 diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index e85f21517..e9a7a96be 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -7,7 +7,7 @@ class HomeworkAttachController < ApplicationController before_filter :can_show_course,except: [] #判断当前角色权限时需先找到当前操作的project 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_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours, :get_student_batch_homework, :get_my_homework] 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] @@ -68,6 +68,46 @@ class HomeworkAttachController < ApplicationController end end + #获取学生匿评列表 + def get_student_batch_homework + 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, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = 3123) AS m_score + FROM homework_attaches + INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id + WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id}) AS table1 + WHERE table1.m_score IS NULL") + @homework_list = paginateHelper all_homework_list,10 + respond_to do |format| + format.js + end + end + + #获取我的作业 + def get_my_homework + teachers = find_course_teachers @course + all_homework_list = HomeworkAttach.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 homework_attaches.bid_id = #{@bid.id} AND homework_attaches.user_id = #{User.current.id}"); + #如果我没有创建过作业,就检索我是否参与了某个作业 + if all_homework_list.empty? + all_homework_list = HomeworkAttach.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 + INNER JOIN homework_users ON homework_users.homework_attach_id = homework_attaches.id + WHERE homework_attaches.bid_id = #{@bid.id} AND homework_users.user_id = #{User.current.id}") + end + @homework_list = paginateHelper all_homework_list,10 + respond_to do |format| + format.js + end + end + #获取作业的留言列表 def get_homework_jours #@user = @bid.author diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index b34e1cd3c..13f3e6557 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -28,16 +28,16 @@ <% else %>