From 78ac974a75bc662b56c83bcfad2ac7771e462141 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 4 Jun 2014 16:01:33 +0800 Subject: [PATCH 01/10] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8=E7=95=8C=E9=9D=A2=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E4=BD=9C=E4=B8=9A=202.=E4=BF=AE=E5=A4=8D=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E5=9C=A8=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E4=BD=9C=E4=B8=9A=E4=B8=8B=E6=8F=90=E4=BA=A4=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=96=B9=E6=B3=95=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 2 +- app/views/bids/_bid_homework_show.html.erb | 8 +++++++- config/locales/zh.yml | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b0c7e1861..054b3b5a3 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -159,7 +159,7 @@ module CoursesHelper end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid - cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,params[:id]) + cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,bid.id) cur_user_homework end end diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 3ef55c567..c4eb875a1 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -15,7 +15,13 @@ <% if(User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)) %> <%# 提交作业按钮 %> - <%= link_to l(:label_commit_homework), '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id}, '#{bid.name}');" if User.current.member_of?(@project) %> + + <% cur_user_homework = cur_user_homework_for_bid(bid) %> + <% if cur_user_homework!= nil && cur_user_homework.count == 0 %> + <%= link_to l(:label_commit_homework),new_homework_attach_path(bid) %> + <% else %> + <%= l(:lable_has_commit_homework)%> + <% end %> <% end %> <% if (User.current.admin?||User.current.id==bid.author_id) %> <%= link_to( diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 9f6fb26c9..de390a8f8 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1277,6 +1277,7 @@ zh: label_current_contributors: 位当前贡献者 label_commit_limit: 作业提交时间已过! label_commit_ar: 作业提交截止时间快到了! + lable_has_commit_homework: 您已提交过作业 #modify by men label_x_current_contributors: zero: 位当前贡献者 From af68d154515f9d7aa05c8b8c54c36c0bb97d70f4 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 4 Jun 2014 16:23:43 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=9A=84=E5=A2=9E?= =?UTF-8?q?=E3=80=81=E5=88=A0=E3=80=81=E6=94=B9=E3=80=81=E6=9F=A5=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E4=BD=9C=E4=B8=9A=E8=B5=84=E6=96=99=E7=9A=84=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 108 +++++++++++------- app/controllers/zipdown_controller.rb | 19 +-- 2 files changed, 77 insertions(+), 50 deletions(-) diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 24e1a86e4..64b34dfc1 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -18,7 +18,8 @@ class HomeworkAttachController < ApplicationController end def create - #if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) + bid = Bid.find params[:bid_id] + if User.current.admin? || User.current.member_of?(bid.courses.first) user_id = params[:user_id] bid_id = params[:bid_id] sta = 0 @@ -32,7 +33,7 @@ class HomeworkAttachController < ApplicationController :bid_id => bid_id } - #@bid = Bid.find bid_id + #@homework_list = @bid.homeworks @homework = HomeworkAttach.new(options) @@ -45,77 +46,98 @@ class HomeworkAttachController < ApplicationController format.json { head :no_content } end else - + render_403 :message => :notice_not_authorized end - #end + else + + end end def new - @homework = HomeworkAttach.new @bid = Bid.find(params[:id]) - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @homework } + if User.current.admin? || User.current.member_of?(@bid.courses.first) + @homework = HomeworkAttach.new + respond_to do |format| + format.html # new.html.erb + format.json { render json: @homework } + end + else + render_403 :message => :notice_not_authorized end end def edit @homework = HomeworkAttach.find(params[:id]) + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + else + render_403 :message => :notice_not_authorized + end end def update @homework = HomeworkAttach.find(params[:id]) - name = params[:homework_name] - description = params[:homework_description] - @homework.name = name - @homework.description = description - if params[:attachments] - @homework.save_attachments(params[:attachments]) - end - if @homework.save - respond_to do |format| - format.html { redirect_to project_for_bid_path @homework.bid } - format.json { head :no_content } + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + name = params[:homework_name] + description = params[:homework_description] + @homework.name = name + @homework.description = description + if params[:attachments] + @homework.save_attachments(params[:attachments]) + end + if @homework.save + respond_to do |format| + format.html { redirect_to project_for_bid_path @homework.bid } + format.json { head :no_content } + end + else end else + render_403 :message => :notice_not_authorized end end def destroy @homework = HomeworkAttach.find(params[:id]) - if @homework.destroy - respond_to do |format| - format.html { redirect_to project_for_bid_path @homework.bid } - format.json { head :no_content } + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + if @homework.destroy + respond_to do |format| + format.html { redirect_to project_for_bid_path @homework.bid } + format.json { head :no_content } + end + else end else + render_403 :message => :notice_not_authorized end end #显示作业信息 def show @homework = HomeworkAttach.find(params[:id]) - # 打分统计 - stars_reates = @homework. - rates(:quality) - stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count - stars_status = stars_reates.select("stars, count(*) as scount"). - group("stars") - @stars_status_map = Hash.new(0.0) - stars_status.each do |star_status| - percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f - percent_m = format("%.2f", percent) - @stars_status_map["star#{star_status.stars.to_i}".to_sym] = - percent_m.to_s + "%" + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + # 打分统计 + stars_reates = @homework. + rates(:quality) + stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + stars_status = stars_reates.select("stars, count(*) as scount"). + group("stars") + @stars_status_map = Hash.new(0.0) + stars_status.each do |star_status| + percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f + percent_m = format("%.2f", percent) + @stars_status_map["star#{star_status.stars.to_i}".to_sym] = + percent_m.to_s + "%" + end + @limit = 10 + @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") + else + render_403 :message => :notice_not_authorized end - @limit = 10 - @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") end #删除留言 diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 5f5a22279..5caa97a22 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -26,14 +26,19 @@ class ZipdownController < ApplicationController obj_id = params[:obj_id] user_id = params[:user_id] obj = obj_class.constantize.find(obj_id) - zipfile = nil - case obj.class.to_s.to_sym - when :Bid - zipfile = zip_user_bid obj,user_id - else - logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!" + + if User.current.admin? || User.current.member_of?(obj.courses.first) + zipfile = nil + case obj.class.to_s.to_sym + when :Bid + zipfile = zip_user_bid obj,user_id + else + logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!" + end + send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile + else + render_403 :message => :notice_not_authorized end - send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile end private From 39ce95a950e62553af283021546a97fbc8de5840 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 4 Jun 2014 17:22:42 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E7=BE=8E=E5=8C=96=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_homework.html.erb | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/views/layouts/base_homework.html.erb b/app/views/layouts/base_homework.html.erb index 5a358628e..81a8b0861 100644 --- a/app/views/layouts/base_homework.html.erb +++ b/app/views/layouts/base_homework.html.erb @@ -47,27 +47,31 @@
- +
- From 1c7923e5bdedff26d45b7002a38455c9bdf7fbd1 Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 5 Jun 2014 16:53:41 +0800 Subject: [PATCH 07/10] sql --- app/controllers/bids_controller.rb | 4 +--- app/helpers/bids_helper.rb | 2 +- app/helpers/courses_helper.rb | 2 +- app/models/user.rb | 2 +- app/views/bids/_homework_list.html.erb | 11 +++-------- app/views/layouts/base_homework.html.erb | 4 ++-- 6 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index c0df0699c..2ad60fc29 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -410,9 +410,7 @@ class BidsController < ApplicationController @homework = HomeworkAttach.new #@homework_list = @bid.homeworks #增加作业按评分排序, - @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) AS score - FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY score DESC") + @homework_list = @bid.homeworks.joins(:user).includes(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC') if params[:student_id].present? @temp = [] @homework_list.each do |pro| diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index 8b03d74cd..40cec6edb 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -158,7 +158,7 @@ module BidsHelper #当前用户是不是指定课程的学生 def is_cur_course_student? course people = [] - course.members.each do |member| + course.members.includes(:user, :roles).each do |member| if [5,10].include? member.roles.first.id people << member.user end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index fb0a269e6..f16aef911 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -139,7 +139,7 @@ module CoursesHelper #判断制定用户是不是当前课程的老师 def is_course_teacher user,course people = [] - course.members.each do |member| + course.members.includes(:roles, :user).each do |member| role_id = member.roles.first.id if TeacherRoles.include? role_id people << member.user diff --git a/app/models/user.rb b/app/models/user.rb index d79cf11e1..689cc7b2e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -137,7 +137,7 @@ class User < Principal has_one :user_extensions,:dependent => :destroy ## end - #default_scope -> { includes(:user_extensions, :user_score) } + default_scope -> { includes(:user_extensions, :user_score) } scope :teacher, -> { joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER) } diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 48f1c150d..d2d58753b 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -83,13 +83,8 @@
+ <% if get_avatar?(project) %> - <%= image_tag(url_to_avatar(project),:style => "width:60px;height:60px" ) %> + <%= image_tag(url_to_avatar(project),:style => "width:80px;height:80px" ) %> <% else %> - <%= image_tag('../images/avatars/Project/course.jpg', :style => "width:60px;height:60px") %> + <%= image_tag('../images/avatars/Project/course.jpg', :style => "width:80px;height:80px") %> <% end %> - - - + - - +

<%= f.select :is_evaluation, is_evaluation_option %>

<%= l(:label_attachment_plural) %>

<%= render :partial => 'attachments/form', :locals => {:container => @homework} %>

\ No newline at end of file diff --git a/app/views/bids/_homework_form.html.erb b/app/views/bids/_homework_form.html.erb index f726c038f..92b162035 100644 --- a/app/views/bids/_homework_form.html.erb +++ b/app/views/bids/_homework_form.html.erb @@ -36,6 +36,7 @@

<%= f.select :homework_type, homework_type_option %>

--> +

<%= f.select :is_evaluation, is_evaluation_option %>

<%= hidden_field_tag 'course_id', @project_id %>

<%= l(:label_attachment_plural) %> diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index fd4b0a93e..5e041065d 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -1,6 +1,8 @@ <% is_student = is_cur_course_student? @bid.courses.first %> <% is_teacher = is_course_teacher User.current,@bid.courses.first %> + +<% is_evaluation = @bid.is_evaluation == 1 || @bid.is_evaluation == nil %> <%= form_tag(:controller => 'bids', :action => "show_project", :method => :get) do %>
@@ -53,11 +55,21 @@ <% else %> <% homework_filename = homework.name %> <% end %> - <%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:obj_class => @bid.class,:obj_id => @bid, :user_id =>homework.user%> + + <% if is_evaluation || is_teacher%> + <%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:obj_class => @bid.class,:obj_id => @bid, :user_id =>homework.user%> + <% else %> + <%= homework_filename %> + <% end %> +
@@ -112,20 +112,6 @@ <% end %> - -
课程名: - <%= link_to @bid.courses.first.name.to_s, homework_project_path(@bid.courses.first) if @bid.courses.first %> +
+ + + <%= link_to @bid.courses.first.name.to_s, homework_project_path(@bid.courses.first) if @bid.courses.first %> + +
作业名: - <%= h @bid.name %> + + + <%= h @bid.name %> +
<% if is_student %> - <%= link_to "互评>>" , homework_attach_path(homework)%> + <% if is_evaluation %> + <%= link_to "互评>>" , homework_attach_path(homework)%> + <% else %> + <%= link_to "查看详细" , homework_attach_path(homework)%> + <% end %> <% else %> <% if is_teacher %> <%= link_to "综评>>" , homework_attach_path(homework)%> diff --git a/app/views/homework_attach/_comprehensive_evaluation.html.erb b/app/views/homework_attach/_comprehensive_evaluation.html.erb index e6ebacffe..08db30542 100644 --- a/app/views/homework_attach/_comprehensive_evaluation.html.erb +++ b/app/views/homework_attach/_comprehensive_evaluation.html.erb @@ -22,12 +22,6 @@
<%= comprehensive_evaluation.first.notes%>
- <% if is_teacher %> -
评分: - <%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %> - (您可以重新打分,打分结果以最后一次打分为主!) -
- <% end %> <% else %> <% if is_teacher %> @@ -35,10 +29,7 @@
作业综评:
-
评分: - <%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %> - (您可以重新打分,打分结果以最后一次打分为主!) -
+ <%= render :partial => 'evaluation', :locals => {:homework => homework} %>
<%= render :partial => 'addjour', :locals => {:homework_attach => homework, :sta => 0,:is_comprehensive_evaluation => 1} %>
diff --git a/app/views/homework_attach/_evaluation.html.erb b/app/views/homework_attach/_evaluation.html.erb new file mode 100644 index 000000000..bd8677fb1 --- /dev/null +++ b/app/views/homework_attach/_evaluation.html.erb @@ -0,0 +1,4 @@ +
评分: + <%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %> + (每个用户对每份作业只能进行一次评价!) +
\ No newline at end of file diff --git a/app/views/homework_attach/show.html.erb b/app/views/homework_attach/show.html.erb index 2b2ec5cce..cdbbe9fda 100644 --- a/app/views/homework_attach/show.html.erb +++ b/app/views/homework_attach/show.html.erb @@ -8,7 +8,6 @@ <% is_student = is_cur_course_student? @homework.bid.courses.first %> <% is_teacher = is_course_teacher User.current,@homework.bid.courses.first %> -

<%= notice %>

@@ -29,8 +28,12 @@
作业下载: - <% options = {:author => true } %> - <%= render :partial => 'app_link', :locals => {:attachments => @homework.attachments, :options => options} %> + <% if @is_evaluation || is_teacher%> + <% options = {:author => true } %> + <%= render :partial => 'app_link', :locals => {:attachments => @homework.attachments, :options => options} %> + <% else %> + <%= l(:label_cant_download) %> + <% end %> 所属任务:<%= link_to(@homework.bid.name, project_for_bid_path(@homework.bid))%> @@ -133,10 +136,19 @@
作业评论:
<% if is_student %> -
评分: - <%= rating_for @homework, dimension: :quality, class: 'rateable div_inline' %> - (您可以重新打分,打分结果以最后一次打分为主!) -
+ <% if @is_evaluation %> + <% if @has_evaluation %> +
+ <%= l(:lable_has_evaluation)%> +
+ <% else %> + <%= render :partial => 'evaluation', :locals => {:homework => @homework} %> + <% end %> + <% else %> +
+ <%= l(:lable_close_evaluation)%> +
+ <% end %> <% end %>
diff --git a/app/views/projects/_homework_form.html.erb b/app/views/projects/_homework_form.html.erb index 13255120f..596d83071 100644 --- a/app/views/projects/_homework_form.html.erb +++ b/app/views/projects/_homework_form.html.erb @@ -32,10 +32,8 @@

-->

<%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>

-

<%= hidden_field_tag 'course_id', @project.id %>

<%= l(:label_attachment_plural) %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index de390a8f8..aecf2f19a 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1546,6 +1546,7 @@ zh: label_bids_credit_number: 分 field_budget: 奖励 field_deadline: 截止日期 + field_is_evaluation: 是否启动互评 label_tags_selected: 已选标签 label_tags_related: 相关标签 button_project_tags_add: 增加 @@ -1600,6 +1601,9 @@ zh: label_have_feedback: 有了 label_of_feedback: 的 label_welcome_participate: 参与了 + label_cant_download: 未开启互评功能作业不允许下载 + lable_close_evaluation: 该作业未开启互评功能 + lable_has_evaluation: 您已进行过评价 #modify by men label_x_welcome_participate: zero: 参与了 @@ -1789,6 +1793,8 @@ zh: label_new_join_order: 请输入课程密码 label_task_submit_form_accessory: 作业最终以附件形式提交 label_task_submit_form_project: 作业最终以项目形式提交 + lable_start_mutual_evaluation: 启动互评 + lable_close_mutual_evaluation: 关闭互评 label_has_been: 已经被 label_course_userd_by: 个课程引用 diff --git a/db/migrate/20140605025247_add_evaluation_to_bid.rb b/db/migrate/20140605025247_add_evaluation_to_bid.rb new file mode 100644 index 000000000..f940974b4 --- /dev/null +++ b/db/migrate/20140605025247_add_evaluation_to_bid.rb @@ -0,0 +1,5 @@ +class AddEvaluationToBid < ActiveRecord::Migration + def change + add_column :bids, :is_evaluation, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 721945ed4..185f5e134 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 => 20140527060344) do +ActiveRecord::Schema.define(:version => 20140605025247) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -105,6 +105,7 @@ ActiveRecord::Schema.define(:version => 20140527060344) do t.integer "homework_type" t.integer "parent_id" t.string "password" + t.integer "is_evaluation" end create_table "boards", :force => true do |t| From 999b856d84e907bc188d7c6534ad54494cc21148 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 5 Jun 2014 15:14:51 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E5=BC=80?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8=E7=95=8C=E9=9D=A2=E6=95=88?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 2 +- app/views/bids/_homework_list.html.erb | 16 +--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 97ebb4d49..c0df0699c 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -878,7 +878,7 @@ class BidsController < ApplicationController def find_bid if params[:id] - @bid = Bid.find(params[:id]) + @bid = Bid.find(params[:id], :include => [{:homeworks => :user}]) @user = @bid.author end rescue diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 5e041065d..48f1c150d 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -99,7 +99,7 @@
  - <% if is_cur_course_user? @bid %> + <% if User.current.member_of?(@bid.courses.first) %> <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> <% end %>
作业评分: - <% stars_reates = homework.rates(:quality) %> - <% sum = 0 %> - <% stars_reates.each do |star_reates| %> - <% sum = sum + star_reates.stars %> - <% end %> - <% stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count %> - <%= format("%.2f", sum * 1.0 / stars_reates_count) %> + + <%= format("%.2f", homework.rate_averages.first.try(:avg).to_i ) %> <% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %> @@ -100,7 +95,7 @@
  <% if User.current.member_of?(@bid.courses.first) %> - <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> + <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.student_id%> <% end %> diff --git a/app/views/layouts/base_homework.html.erb b/app/views/layouts/base_homework.html.erb index 81a8b0861..8c108ba22 100644 --- a/app/views/layouts/base_homework.html.erb +++ b/app/views/layouts/base_homework.html.erb @@ -18,8 +18,8 @@ <%= yield :header_tags -%> - <% project = @bid.courses.first %> - <% course = Course.find_by_extra(project.identifier) %> + <% project = @bid.courses.includes(:course_extra).first %> + <% course = project.course_extra %>
From bce592ba85d8063335c64152719c30d77d316b38 Mon Sep 17 00:00:00 2001 From: senluo Date: Thu, 5 Jun 2014 17:25:28 +0800 Subject: [PATCH 08/10] A gem who in lib and Gemfile must be have a suitable version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 3784e60d8..9dae2827c 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem "i18n", "~> 0.6.0" gem "coderay", "~> 1.0.6" gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] gem "builder", "3.0.0" -gem 'acts-as-taggable-on' +gem 'acts-as-taggable-on', '2.4.1' group :development do gem 'better_errors', path: 'lib/better_errors' From 57994edc0610bb31e10bcb2a162d34d13e23e86e Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 5 Jun 2014 17:29:11 +0800 Subject: [PATCH 09/10] load user in homework --- app/controllers/bids_controller.rb | 2 +- app/views/layouts/base_homework.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 2ad60fc29..8bfab408c 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -410,7 +410,7 @@ class BidsController < ApplicationController @homework = HomeworkAttach.new #@homework_list = @bid.homeworks #增加作业按评分排序, - @homework_list = @bid.homeworks.joins(:user).includes(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC') + @homework_list = @bid.homeworks.joins(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC') if params[:student_id].present? @temp = [] @homework_list.each do |pro| diff --git a/app/views/layouts/base_homework.html.erb b/app/views/layouts/base_homework.html.erb index 8c108ba22..4fbdda1d1 100644 --- a/app/views/layouts/base_homework.html.erb +++ b/app/views/layouts/base_homework.html.erb @@ -179,7 +179,7 @@
<% if @bid.homework_type == 1%> <% if @bid.homeworks.size>0 %> - <% for homework in @bid.homeworks %> + <% for homework in @bid.homeworks.eager_load(:user) %> <%= link_to image_tag(url_to_avatar(homework.user), :class => "avatar", :title => homework.user.name), user_path(homework.user), :class => "avatar" %> <% end %> <% else %>

From 0d8b06ec8755ccc5b30fe8ee5c9263db9c2b1699 Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 5 Jun 2014 17:32:26 +0800 Subject: [PATCH 10/10] e, bug --- app/controllers/bids_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 8bfab408c..ff6fda491 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -410,7 +410,7 @@ class BidsController < ApplicationController @homework = HomeworkAttach.new #@homework_list = @bid.homeworks #增加作业按评分排序, - @homework_list = @bid.homeworks.joins(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC') + @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC') if params[:student_id].present? @temp = [] @homework_list.each do |pro|