From 6f1c648770b94a10a4e0da339bee71b9d44e1f30 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 4 Nov 2016 11:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E4=BD=9C=E4=B8=9A=EF=BC=9A?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=84=E5=88=86=E5=90=8E=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=BA=BA=E7=9A=84=E4=B9=8B=E5=89=8D=E7=9A=84=E8=AF=84?= =?UTF-8?q?=E5=88=86=EF=BC=8C=E5=B0=B1=E4=B8=8D=E6=98=BE=E7=A4=BA=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 3 ++- app/helpers/student_work_helper.rb | 9 +++++++++ .../student_work/_programing_work_show.html.erb | 8 ++------ app/views/student_work/_show.html.erb | 11 ++--------- app/views/student_work/_student_work_list.html.erb | 6 +++--- .../_student_work_score_records.html.erb | 8 ++++++++ app/views/student_work/add_score.js.erb | 12 +++++++----- 7 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 app/views/student_work/_student_work_score_records.html.erb diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 0e9599a51..979f74aa4 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -691,7 +691,7 @@ class StudentWorkController < ApplicationController def show @score = student_work_score @work,User.current @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - @student_work_scores = @work.student_works_scores.order("updated_at desc") + @student_work_scores = student_work_score_record(@work) respond_to do |format| format.js end @@ -854,6 +854,7 @@ class StudentWorkController < ApplicationController if @work.save @work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => @work.id).first @count = @homework.student_works.has_committed.count + @student_work_scores = student_work_score_record @work respond_to do |format| format.js end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 63344fa1a..954e0ba48 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -69,6 +69,15 @@ module StudentWorkHelper str end + #获取学生作品的评分记录:同一个教师或教辅只显示最后一次评分 + def student_work_score_record work + sql = "SELECT MAX(id) id FROM student_works_scores WHERE (reviewer_role = 2 OR reviewer_role = 1) AND score IS NOT NULL AND student_work_id = #{work.id} GROUP BY user_id" + tea_ts_ids = StudentWorksScore.find_by_sql sql + tea_ts_ids = tea_ts_ids.empty? ? "(-1)" : "(" + tea_ts_ids.map{|tea| tea.id}.join(",") + ")" + scores = work.student_works_scores.where("score IS NULL or reviewer_role = 3 or id in #{tea_ts_ids}").order("updated_at desc") + return scores + end + #获取赞的总数 def praise_homework_count obj_id PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").count diff --git a/app/views/student_work/_programing_work_show.html.erb b/app/views/student_work/_programing_work_show.html.erb index 6d5538e23..908b4a1d2 100644 --- a/app/views/student_work/_programing_work_show.html.erb +++ b/app/views/student_work/_programing_work_show.html.erb @@ -106,12 +106,8 @@
-
- <%student_work_scores.each do |student_score|%> -
- <%= render :partial => 'student_work_score',:locals => {:score => student_score,:is_last => student_score == student_work_scores.last}%> -
- <% end%> +
+ <%= render :partial => 'student_work_score_records', :locals => {:student_work_scores => student_work_scores, :is_member_work => false} %>
diff --git a/app/views/student_work/_show.html.erb b/app/views/student_work/_show.html.erb index cb9c7fbe0..786587d7b 100644 --- a/app/views/student_work/_show.html.erb +++ b/app/views/student_work/_show.html.erb @@ -109,15 +109,8 @@ <% end %> -
- <%student_work_scores.each do |student_score|%> -
- <%= render :partial => 'student_work_score',:locals => {:score => student_score,:is_last => student_score == student_work_scores.last}%> -
- <% end%> - <% if is_member_work && student_work_scores.empty? && !@is_teacher %> -

暂无评分

- <% end %> +
+ <%= render :partial => 'student_work_score_records', :locals => {:student_work_scores => student_work_scores, :is_member_work => is_member_work} %>
diff --git a/app/views/student_work/_student_work_list.html.erb b/app/views/student_work/_student_work_list.html.erb index 8e34dc20f..94b033cd2 100644 --- a/app/views/student_work/_student_work_list.html.erb +++ b/app/views/student_work/_student_work_list.html.erb @@ -76,7 +76,7 @@ <% unless work.nil? %> location.hash = "<%=work.id %>"; <% if @homework.homework_type == 2 %> - $("#about_hwork_<%= work.id%>").html("<%= escape_javascript(render :partial => 'programing_work_show',:locals => {:work =>work,:score =>student_work_score(work,User.current),:student_work_scores => work.student_works_scores.order("updated_at desc"),:is_focus => @is_focus}) %>"); + $("#about_hwork_<%= work.id%>").html("<%= escape_javascript(render :partial => 'programing_work_show',:locals => {:work =>work,:score =>student_work_score(work,User.current),:student_work_scores => student_work_score_record(work),:is_focus => @is_focus}) %>"); var program_name = "text/x-csrc"; var language = <%= @homework.language %>; @@ -100,9 +100,9 @@ value: $("#work-src_<%= work.id%>").text() }); <% elsif @homework.homework_type == 1 %> - $("#about_hwork_<%= work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work => work, :score =>student_work_score(work,User.current),:student_work_scores => work.student_works_scores.order("updated_at desc"),:is_focus => @is_focus}) %>"); + $("#about_hwork_<%= work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work => work, :score =>student_work_score(work,User.current),:student_work_scores => student_work_score_record(work),:is_focus => @is_focus}) %>"); <% elsif @homework.homework_type == 3 %> - $("#about_hwork_<%= work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work => work, :score =>student_work_score(work,User.current),:student_work_scores => work.student_works_scores.order("updated_at desc"),:is_focus => @is_focus}) %>"); + $("#about_hwork_<%= work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work => work, :score =>student_work_score(work,User.current),:student_work_scores => student_work_score_record(work),:is_focus => @is_focus}) %>"); <% end %> $('#score_<%= work.id%>').peSlider({range: 'min'}); <% end %> diff --git a/app/views/student_work/_student_work_score_records.html.erb b/app/views/student_work/_student_work_score_records.html.erb new file mode 100644 index 000000000..b0215d127 --- /dev/null +++ b/app/views/student_work/_student_work_score_records.html.erb @@ -0,0 +1,8 @@ +<%student_work_scores.each do |student_score|%> +
+ <%= render :partial => 'student_work_score',:locals => {:score => student_score,:is_last => student_score == student_work_scores.last}%> +
+<% end%> +<% if is_member_work && student_work_scores.empty? && !@is_teacher %> +

暂无评分

+<% end %> \ No newline at end of file diff --git a/app/views/student_work/add_score.js.erb b/app/views/student_work/add_score.js.erb index 6acf9eb45..5372360b9 100644 --- a/app/views/student_work/add_score.js.erb +++ b/app/views/student_work/add_score.js.erb @@ -1,12 +1,14 @@ $("#add_student_score_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'add_score',:locals => {:work => @work,:score => @new_score}) %>"); $('#score_<%= @work.id%>').peSlider({range: 'min'}); -<% if @is_new%> - $("#score_list_<%= @work.id%>").prepend("
<%= escape_javascript(render :partial => 'student_work_score', :locals => {:score => @new_score,:is_last => @is_last_a}) %>
"); -<% else %> - $("#work_score_<%= @score.id%>").html("<%= escape_javascript(render :partial => 'student_work_score', :locals => {:score => @new_score,:is_last => @is_last}) %>"); -<% end%> +<%# if @is_new%> + //$("#score_list_<%#= @work.id%>").prepend("
<%#= escape_javascript(render :partial => 'student_work_score', :locals => {:score => @new_score,:is_last => @is_last_a}) %>
"); +<%# else %> + //$("#work_score_<%#= @score.id%>").html("<%#= escape_javascript(render :partial => 'student_work_score', :locals => {:score => @new_score,:is_last => @is_last}) %>"); +<%# end%> +<% is_member_work = @homework.homework_type == 3 && @work.student_work_projects.empty? %> +$("#score_list_<%= @work.id%>").replaceWith("<%=escape_javascript(render :partial => 'student_work_score_records', :locals => {:student_work_scores => @student_work_scores, :is_member_work => is_member_work}) %>"); var num = $("#work_num_<%= @work.id%>").html(); $("#score_list_<%= @work.id%>").removeAttr("style");