+<% is_float ||= false %>
<% for attachment in attachments %>
-
+ <%if is_float%>
+
+ <% end%>
<% if options[:length] %>
<%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true,:length => options[:length] -%>
@@ -9,7 +12,10 @@
<%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
<% end %>
-
+ <%if is_float%>
+
+ <% end%>
+
<% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'),
:controller => 'attachments',
diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb
index 0330b65e4..995529fe9 100644
--- a/app/views/memos/show.html.erb
+++ b/app/views/memos/show.html.erb
@@ -67,7 +67,7 @@
<% if @memo.attachments.any?%>
<% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %>
- <%= render :partial => 'attachments/links', :locals => {:attachments => @memo.attachments, :options => options} %>
+ <%= render :partial => 'attachments/links', :locals => {:attachments => @memo.attachments, :options => options, :is_float => true} %>
<% end %>
@@ -136,7 +136,7 @@
<% if reply.attachments.any?%>
<% options = {:author => true, :deletable => reply.deleted_attach_able_by?(User.current) } %>
- <%= render :partial => 'attachments/links', :locals => {:attachments => reply.attachments, :options => options} %>
+ <%= render :partial => 'attachments/links', :locals => {:attachments => reply.attachments, :options => options, :is_float => true} %>
<% end %>
From 4cdb3c83ddb69c6334f68e5053d7b5bad642cdca Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Fri, 6 Feb 2015 11:22:29 +0800
Subject: [PATCH 16/18] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E5=9C=A8=E6=8C=87=E5=AE=9A=E8=AF=BE=E7=A8=8B?=
=?UTF-8?q?=E5=86=85=E4=BD=9C=E4=B8=9A=E6=95=B0=E9=87=8F=E7=9A=84=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/helpers/api_helper.rb | 24 ++++++++++++++++++++++++
app/helpers/homework_attach_helper.rb | 18 ++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb
index 8ff6f725c..b227a96ab 100644
--- a/app/helpers/api_helper.rb
+++ b/app/helpers/api_helper.rb
@@ -37,4 +37,28 @@ module ApiHelper
end
result
end
+
+ #########################################################
+ #sw
+ #获取课程未匿评数量
+ #param: user => "用户", course_id => "查询的课程ID"
+ #return: 作业的数量
+ #########################################################
+ def get_course_anonymous_evaluation user,course_id
+ course = Course.find course_id
+ count = 0
+ if course
+ is_teacher = is_course_teacher user,course
+ if is_teacher #如果是老师,显示学生提交的作业数
+ course.homeworks.each do |bid|
+ count += bid.homeworks.count
+ end
+ else #如果是学生,显示未匿评的数量
+ course.homeworks.each do |bid|
+ count += get_student_not_batch_homework_list bid,user
+ end
+ end
+ end
+ count
+ end
end
\ No newline at end of file
diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb
index c41ba54ee..0b98283ff 100644
--- a/app/helpers/homework_attach_helper.rb
+++ b/app/helpers/homework_attach_helper.rb
@@ -130,4 +130,22 @@ module HomeworkAttachHelper
WHERE homework_attaches.bid_id = #{bid.id} AND homework_evaluations.user_id = #{user.id} ORDER BY m_score DESC")
student_batch_homework_list
end
+
+ #########################################################
+ #sw
+ #获取学生未进行匿评的数量
+ #param: bid => 作业 user => 用户
+ #return 指定用户未进行匿评的作业的数量
+ #user必须是学生用户
+ #######################################################
+ def get_student_not_batch_homework_list bid,user
+ HomeworkAttach.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 is_teacher_score = 1) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score,
+ (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{user.id} AND is_teacher_score = 0) 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.id}) AS table1
+ WHERE table1.m_score IS NULL").count
+ end
end
\ No newline at end of file
From cc83b30fc6c230a54182cf4a3c0979f69210db4d Mon Sep 17 00:00:00 2001
From: z9hang
Date: Fri, 6 Feb 2015 14:29:42 +0800
Subject: [PATCH 17/18] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=90=9C=E7=B4=A2?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/api/mobile/apis/courses.rb | 10 ++++++++++
app/api/mobile/apis/users.rb | 18 ++++++++++--------
app/services/courses_service.rb | 8 ++++++++
3 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index 8f8c08c3f..7b3fc7cd5 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -209,6 +209,16 @@ module Mobile
present :status, 0
end
+ desc '课程动态'
+ params do
+ requires :token, type: String
+ end
+ get "course_dynamic/:id" do
+ cs = CoursesService.new
+ count = cs.course_dynamic(params,current_user)
+ present :data, count
+ present :status, 0
+ end
end
end
diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb
index 69260716e..d780b9db4 100644
--- a/app/api/mobile/apis/users.rb
+++ b/app/api/mobile/apis/users.rb
@@ -22,13 +22,15 @@ module Mobile
desc "显示用户"
params do
-
+ requires :id, type: Integer
end
- get ':id' do
- us = UsersService.new
- ue = us.show_user params
- present :data, ue,with: Mobile::Entities::User
- present :status, 0
+ route_param :id do
+ get do
+ us = UsersService.new
+ ue = us.show_user params
+ present :data, ue,with: Mobile::Entities::User
+ present :status, 0
+ end
end
desc "修改用户"
@@ -77,11 +79,11 @@ module Mobile
present :status, 0
end
- desc "用户搜索"
+ desc "用户搜索"
params do
requires :name, type: String, desc: '用户名关键字'
end
- get 'search' do
+ get 'search/search_user' do
us = UsersService.new
user = us.search_user params
present :data, user, with: Mobile::Entities::User
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index 341ecd422..d987514c2 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -2,6 +2,7 @@ class CoursesService
include ApplicationHelper
include CoursesHelper
include HomeworkAttachHelper
+ include ApiHelper
#TODO:尚未整合权限系统
#参数school_id为0或不传时返回所有课程,否则返回对应学校的课程
#参数per_page_count分页功能,每页显示的课程数
@@ -326,6 +327,11 @@ class CoursesService
end
end
+ def course_dynamic params,current_user
+ count = get_course_anonymous_evaluation current_user,params[:id]
+ count
+ end
+
private
def show_homework_info course,bid,current_user,is_course_teacher
author = bid.author.lastname + bid.author.firstname
@@ -361,4 +367,6 @@ class CoursesService
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation}
end
+
+
end
\ No newline at end of file
From d913f89a82b640bfd9b11a9d3c92cc31919b351b Mon Sep 17 00:00:00 2001
From: z9hang
Date: Fri, 6 Feb 2015 15:52:34 +0800
Subject: [PATCH 18/18] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8B?=
=?UTF-8?q?=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/api/mobile/apis/courses.rb | 2 +-
app/api/mobile/entities/course_dynamic.rb | 17 +++++++++++++++++
app/helpers/api_helper.rb | 5 ++---
app/services/courses_service.rb | 17 ++++++++++++++---
4 files changed, 34 insertions(+), 7 deletions(-)
create mode 100644 app/api/mobile/entities/course_dynamic.rb
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index 7b3fc7cd5..7dbfaffb0 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -216,7 +216,7 @@ module Mobile
get "course_dynamic/:id" do
cs = CoursesService.new
count = cs.course_dynamic(params,current_user)
- present :data, count
+ present :data, count, with: Mobile::Entities::CourseDynamic
present :status, 0
end
diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb
new file mode 100644
index 000000000..11f8c2682
--- /dev/null
+++ b/app/api/mobile/entities/course_dynamic.rb
@@ -0,0 +1,17 @@
+module Mobile
+ module Entities
+ class CourseDynamic < Grape::Entity
+ def self.course_dynamic_expose(field)
+ expose field do |c,opt|
+ c[field] if (c.is_a?(Hash) && c.key?(field))
+ end
+ end
+
+ course_dynamic_expose :course_name
+ course_dynamic_expose :need_anonymous_comments_count
+ course_dynamic_expose :student_commit_number
+ course_dynamic_expose :news_count
+ course_dynamic_expose :message_count
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb
index b227a96ab..c865a500b 100644
--- a/app/helpers/api_helper.rb
+++ b/app/helpers/api_helper.rb
@@ -44,8 +44,7 @@ module ApiHelper
#param: user => "用户", course_id => "查询的课程ID"
#return: 作业的数量
#########################################################
- def get_course_anonymous_evaluation user,course_id
- course = Course.find course_id
+ def get_course_anonymous_evaluation user,course
count = 0
if course
is_teacher = is_course_teacher user,course
@@ -59,6 +58,6 @@ module ApiHelper
end
end
end
- count
+ [count,is_teacher]
end
end
\ No newline at end of file
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index d987514c2..f4201774a 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -327,9 +327,20 @@ class CoursesService
end
end
- def course_dynamic params,current_user
- count = get_course_anonymous_evaluation current_user,params[:id]
- count
+ def course_dynamic(params,current_user)
+ course = Course.find(params[:id])
+ if current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course)))
+ raise '403'
+ end
+ count,is_teacher = get_course_anonymous_evaluation current_user,course
+ if is_teacher
+ student_commit_number = count
+ else
+ need_anonymous_comments_count = count
+ end
+ news_count = course.news.count
+ message_count = course.journals_for_messages.count
+ {:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count}
end
private