From 8a7757f3c242fe94d2aaabd6e8d06b63a2700fb9 Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Sun, 2 Nov 2014 09:39:18 +0800
Subject: [PATCH] =?UTF-8?q?1.=E6=95=B4=E7=90=86=E8=B8=A9=E3=80=81=E8=B5=9E?=
=?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BB=A3=E7=A0=81=202.=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD=203.?=
=?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8=E7=95=8C=E9=9D=A2=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E6=98=AF=E5=90=A6=E5=B7=B2=E7=BB=8F=E7=82=B9=E8=B5=9E?=
=?UTF-8?q?=E5=88=A4=E6=96=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/homework_attach_controller.rb | 21 ++++-
app/helpers/homework_attach_helper.rb | 10 +++
app/views/bids/_homework_list.html.erb | 2 +-
app/views/homework_attach/_homework.html.erb | 81 +++++++++++++++++++
.../homework_attach/_homeworks_list.html.erb | 73 +----------------
.../homework_attach/praise_homework.js.erb | 4 +
config/routes.rb | 1 +
7 files changed, 121 insertions(+), 71 deletions(-)
create mode 100644 app/views/homework_attach/_homework.html.erb
create mode 100644 app/views/homework_attach/praise_homework.js.erb
diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb
index bb17a90b2..57c786f50 100644
--- a/app/controllers/homework_attach_controller.rb
+++ b/app/controllers/homework_attach_controller.rb
@@ -8,7 +8,7 @@ class HomeworkAttachController < ApplicationController
#判断当前角色权限时需先找到当前操作的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, :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 :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users, :praise_homework]
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
@@ -121,6 +121,25 @@ class HomeworkAttachController < ApplicationController
end
end
+ #为作业点赞
+ def praise_homework
+ pt = PraiseTread.new
+ pt.user_id = User.current.id
+ pt.praise_tread_object_id = @homework.id
+ pt.praise_tread_object_type = "HomeworkAttach"
+ pt.praise_or_tread = 1
+ @is_my_homework = params[:is_my_homework]
+ @is_student_batch_homework = params[:is_student_batch_homework]
+ @is_teacher = params[:is_teacher]
+ if pt.save
+ respond_to do |format|
+ format.js
+ end
+ else
+ render_404
+ end
+ end
+
#获取作业的成员
def get_homework_member homework
@hoemwork_users = users_for_homework(@homework)
diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb
index 3510dc783..c3bd240a3 100644
--- a/app/helpers/homework_attach_helper.rb
+++ b/app/helpers/homework_attach_helper.rb
@@ -74,4 +74,14 @@ module HomeworkAttachHelper
end
type
end
+
+ #判断指定用户是不是已经赞过该作业
+ def is_praise_homework user_id, obj_id
+ PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'HomeworkAttach'").empty?
+ end
+
+ #获取赞的总数
+ def praise_homework_count obj_id
+ PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'HomeworkAttach'").count
+ end
end
\ No newline at end of file
diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb
index 81843479f..5979e64d8 100644
--- a/app/views/bids/_homework_list.html.erb
+++ b/app/views/bids/_homework_list.html.erb
@@ -47,7 +47,7 @@
- <%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => false, :is_student_batch_homework => @is_student_batch_homework}%>
+ <%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :remote => false, :is_student_batch_homework => @is_student_batch_homework}%>
diff --git a/app/views/homework_attach/_homework.html.erb b/app/views/homework_attach/_homework.html.erb
new file mode 100644
index 000000000..6bf4128eb
--- /dev/null
+++ b/app/views/homework_attach/_homework.html.erb
@@ -0,0 +1,81 @@
+
+ <%= link_to image_tag(url_to_avatar(homework.user), :width => "40", :height => "40"), user_path(homework.user) %>
+
+ <% user_realname = homework.user.lastname.to_s + homework.user.firstname.to_s %>
+ <% user_name = is_teacher ? (user_realname.empty? ? homework.user.login : user_realname) : homework.user.login %>
+ <%= link_to user_name, user_path(homework.user), :title => user_name %>
+
+
+
+ <% if homework.name == nil || homework.name == "" %>
+ <% homework_filename = homework.user.name + "提交的作业" %>
+ <% else %>
+ <% homework_filename = homework.name %>
+ <% end %>
+ <%= link_to homework_filename , homework_attach_path(homework), :title => homework_filename, :remote => true%>
+
+
+ <%= link_to "(#{homework.attachments.count.to_s}个附件)", zipdown_download_user_homework_path(:homework => homework)%>
+
+
+ <%= l(:label_teacher_score)%>:
+
+ <%= homework.t_score.nil? ? l(:label_without_score) : format("%.2f",homework.t_score)%>
+
+
+
+
+ <%= l(:label_student_score)%>:
+
+ <%= homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score) %>
+
+
+<% if is_teacher %>
+
+
+ <%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
+ <% if Time.parse(@bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
+ 迟交!
+ <% end %>
+
+<% else %>
+
+ <% if is_my_homework %>
+
+
+ <%= link_to l(:button_edit), edit_homework_attach_path(homework) %>
+ <% if homework.user == User.current || User.current.admin? %>
+ <%= link_to(l(:label_bid_respond_delete), homework,
+ method: :delete, :confirm => l(:text_are_you_sure), :remote => true ) %>
+ <% end %>
+
+ <% elsif is_student_batch_homework%>
+
+
+ <%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
+ <% if Time.parse(@bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
+ 迟交!
+ <% end %>
+
+ <% else %>
+
+ <% if is_praise_homework User.current.id,homework.id %>
+
+ <%= link_to "",praise_homework_homework_attach_path(homework,:is_my_homework => is_my_homework,
+ :is_student_batch_homework => is_student_batch_homework,
+ :is_teacher => is_teacher),
+ :class => "wzan_img wzan_visited", :remote => true%>
+
+ <%= praise_homework_count homework.id %>
+
+
+ <% else %>
+
+
+
+ <%= praise_homework_count homework.id %>
+
+
+ <% end %>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/homework_attach/_homeworks_list.html.erb b/app/views/homework_attach/_homeworks_list.html.erb
index 278155ce6..d03ca22b0 100644
--- a/app/views/homework_attach/_homeworks_list.html.erb
+++ b/app/views/homework_attach/_homeworks_list.html.erb
@@ -40,75 +40,10 @@
<% end %>
<% homeworks.each do |homework| %>
-
- -
- <%= link_to image_tag(url_to_avatar(homework.user), :width => "40", :height => "40"), user_path(homework.user) %>
-
- <% user_realname = homework.user.lastname.to_s + homework.user.firstname.to_s %>
- <% user_name = is_teacher ? (user_realname.empty? ? homework.user.login : user_realname) : homework.user.login %>
- <%= link_to user_name, user_path(homework.user), :title => user_name %>
-
-
- -
- <% if homework.name == nil || homework.name == "" %>
- <% homework_filename = homework.user.name + "提交的作业" %>
- <% else %>
- <% homework_filename = homework.name %>
- <% end %>
- <%= link_to homework_filename , homework_attach_path(homework), :title => homework_filename, :remote => true%>
-
- -
- <%= link_to "(#{homework.attachments.count.to_s}个附件)", zipdown_download_user_homework_path(:homework => homework)%>
-
- -
- <%= l(:label_teacher_score)%>:
-
- <%= homework.t_score.nil? ? l(:label_without_score) : format("%.2f",homework.t_score)%>
-
-
-
- -
- <%= l(:label_student_score)%>:
-
- <%= homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score) %>
-
-
- <% if is_teacher %>
-
- -
- <%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
- <% if Time.parse(bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
- 迟交!
- <% end %>
-
- <% else %>
-
- <% if is_my_homework %>
-
- -
- <%= link_to l(:button_edit), edit_homework_attach_path(homework) %>
- <% if homework.user == User.current || User.current.admin? %>
- <%= link_to(l(:label_bid_respond_delete), homework,
- method: :delete, :confirm => l(:text_are_you_sure), :remote => true ) %>
- <% end %>
-
- <% elsif is_student_batch_homework%>
-
- -
- <%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
- <% if Time.parse(bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
- 迟交!
- <% end %>
-
- <% else %>
-
- -
-
-
- 15
-
- <% end %>
- <% end %>
+
+ <%= render :partial => 'homework_attach/homework',
+ :locals => {:homework => homework, :is_student_batch_homework => is_student_batch_homework,
+ :is_my_homework => is_my_homework, :is_teacher => is_teacher}%>
<% end %>
diff --git a/app/views/homework_attach/praise_homework.js.erb b/app/views/homework_attach/praise_homework.js.erb
new file mode 100644
index 000000000..77855cd3c
--- /dev/null
+++ b/app/views/homework_attach/praise_homework.js.erb
@@ -0,0 +1,4 @@
+$('#homework_li_<%= @homework.id%>').
+ html('<%= escape_javascript(render :partial => 'homework_attach/homework',
+ :locals => {:homework => @homework, :is_student_batch_homework => @is_student_batch_homework,
+ :is_my_homework => @is_my_homework, :is_teacher => @is_teacher})%>');
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 5eae3c445..2132d7aba 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -54,6 +54,7 @@ RedmineApp::Application.routes.draw do
member do
match 'add_homework_users', :via => [:get,:post]
match 'destory_homework_users', :via => [:get,:post]
+ get 'praise_homework'
end
end