From 5a20945e0d813ad71e1e9be6ec434f00af38a97d Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 26 Nov 2014 14:54:31 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=80=89=E5=85=A5=E6=88=91=E5=BE=97?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E6=9C=9F=E7=9A=84=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 1 + app/helpers/files_helper.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 251496e30..aa1c158e0 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -28,6 +28,7 @@ class FilesController < ApplicationController include SortHelper include FilesHelper helper :project_score + include CoursesHelper def show_attachments obj @attachments = [] diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 399b7be1d..4b6eccb81 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -48,7 +48,7 @@ module FilesHelper s = '' courses.each do |course| if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) - s << "
" + s << " [#{get_course_term course}]
" end end s.html_safe From 8a3669ba3b560fc4d2d17537e4370686b2918704 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 26 Nov 2014 15:26:57 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=BC=95=E7=94=A8=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=8C=85=E6=8B=AC=E5=A4=9A=E7=BA=A7=E5=BC=95?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/files_helper.rb | 10 ++++++++-- app/views/files/_course_list.html.erb | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 4b6eccb81..f3be6e904 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -94,9 +94,15 @@ module FilesHelper end def get_qute_number attachment - if attachment.copy_from.nil? + if attachment.copy_from + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") + else + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") + end + if result.nil? || result.count <= 0 return 0 + else + return result[0].number end - count = Attachment.find_by_sql("select count(*) from attachments where copy_from = #{attachment.copy_from}") end end \ No newline at end of file diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 6e434ed14..93e39f73f 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -41,7 +41,7 @@

文件大小:<%= number_to_human_size(file.filesize) %>

<%= link_to( l(:button_delete), attachment_path(file), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%> -

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  

+

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  |  引用<%= get_qute_number file %>

From f267a3daf8c52e0dc4ad5d74e4ce00e1a04ece67 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 26 Nov 2014 16:51:09 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=BC=95=E7=94=A8=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E4=B8=AD=E5=B7=B2=E6=9C=89=E7=9A=84=E8=B5=84=E6=BA=90=E6=97=B6?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=B5=84=E6=BA=90=E5=B7=B2=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 6 ++++++ app/helpers/attachments_helper.rb | 9 +++++++++ app/views/attachments/add_exist_file_to_courses.js.erb | 4 +++- config/locales/zh.yml | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 31463d691..89a96a836 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -25,6 +25,7 @@ class AttachmentsController < ApplicationController #before_filter :login_without_softapplication, only: [:download] accept_api_auth :show, :download, :upload require 'iconv' + include AttachmentsHelper def show @@ -346,8 +347,13 @@ class AttachmentsController < ApplicationController def add_exist_file_to_courses file = Attachment.find(params[:file_id]) courses = params[:courses][:course] + @message = "" courses.each do |course| c = Course.find(course); + if course_contains_attachment?(c,file) + @message += l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + end attach_copied_obj = file.copy attach_copied_obj.tag_list.add(file.tag_list) # tag关联 attach_copied_obj.container = c diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 3c882d393..f631f56ff 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -67,6 +67,15 @@ module AttachmentsHelper end end + def course_contains_attachment? course,attachment + course.attachments.each do |att| + if att.id == attachment.id || att.copy_from == attachment.copy_from || att.copy_from = attachment.id || att.id == attachment.copy_from + return true + end + end + false + end + private def deletable? container, user=User.current diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb index 23761647f..761111cec 100644 --- a/app/views/attachments/add_exist_file_to_courses.js.erb +++ b/app/views/attachments/add_exist_file_to_courses.js.erb @@ -1,5 +1,7 @@ -<% if !@save_flag%> +<% if !@save_flag && @save_message %> $("#error_show").html("<%= @save_message.join(', ') %>"); +<% elsif @message || @message != "" %> + $("#error_show").html("<%= @message %>"); <% else %> closeModal(); <% end %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 7d6cc85b2..0ec623217 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2205,3 +2205,7 @@ zh: label_my_score: 我的评分 field_open_anonymous_evaluation: 是否使用匿评 label_course_empty_select: 尚未选择课程! + label_course_prompt: 课程: + label_contain_resource: 已包含资源: + label_quote_resource_failed: ",此资源引用失败! " + From b0db7dfece135a97d374872ec185a0793703e801 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 26 Nov 2014 17:38:46 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=98=AF=E5=90=A6=E4=B8=BA=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E5=AD=A6=E6=9C=9F=E6=88=96=E4=B8=8B=E4=B8=80=E5=AD=A6=E6=9C=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 14 ++++++++++++++ app/helpers/files_helper.rb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 178782da3..04b5ad89d 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -486,6 +486,20 @@ module CoursesHelper term end + def course_in_current_or_next_term course + is_current_term = false + is_next_term = false + if course.time == Time.now.year && course.term == cur_course_term + is_current_term = true + end + if cur_course_term == "秋季学期" && course.time == (Time.now.year + 1) && course.term == "春季学期" + is_next_term = true + elsif cur_course_term == "春季学期" && course.time == Time.now.year && course.term == "秋季学期" + is_next_term = true + end + is_current_term || is_next_term + end + #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index f3be6e904..d51606d90 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -47,7 +47,7 @@ module FilesHelper def courses_check_box_tags(name,courses,current_course,attachment) s = '' courses.each do |course| - if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) + if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course) s << " [#{get_course_term course}]
" end end From 9898e1650b0ed31358b2e9e3ec6d1427b8a96fdc Mon Sep 17 00:00:00 2001 From: z9hang Date: Thu, 27 Nov 2014 10:18:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?1=E3=80=81=E5=AD=A6=E7=94=9F=E7=9C=8B?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E7=A7=81=E6=9C=89=E8=B5=84=E6=BA=90bug?= =?UTF-8?q?=E3=80=822=E3=80=81=E5=BC=95=E7=94=A8=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=E4=B8=AD=E6=97=A0=E8=AF=BE=E7=A8=8B=E5=8F=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=97=B6=E4=B8=8D=E6=98=BE=E7=A4=BA=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E6=88=91=E7=9A=84=E8=AF=BE=E7=A8=8B=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E3=80=823=E3=80=81=E5=BC=95=E7=94=A8=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=97=B6=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 9 +++++++-- app/helpers/attachments_helper.rb | 2 +- app/helpers/files_helper.rb | 6 +++--- app/views/attachments/add_exist_file_to_courses.js.erb | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 89a96a836..25bb31cbb 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -351,8 +351,13 @@ class AttachmentsController < ApplicationController courses.each do |course| c = Course.find(course); if course_contains_attachment?(c,file) - @message += l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) - next + if @message && @message == "" + @message += l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + else + @message += "
" + l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + end end attach_copied_obj = file.copy attach_copied_obj.tag_list.add(file.tag_list) # tag关联 diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index f631f56ff..52002b028 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -69,7 +69,7 @@ module AttachmentsHelper def course_contains_attachment? course,attachment course.attachments.each do |att| - if att.id == attachment.id || att.copy_from == attachment.copy_from || att.copy_from = attachment.id || att.id == attachment.copy_from + if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from return true end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index d51606d90..c3a6a7b3e 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -54,11 +54,11 @@ module FilesHelper s.html_safe end - #判断用户是否拥有课程,需用户在该课程中角色为教师 + #判断用户是否拥有课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 def has_course? user result = false user.courses.each do |course| - if is_course_teacher(user,course) + if is_course_teacher(User.current,course) && course_in_current_or_next_term(course) return true end end @@ -86,7 +86,7 @@ module FilesHelper def visable_attachemnts attachments result = [] attachments.each do |attachment| - if attachment.is_public? || attachment.author_id == User.current.id + if attachment.is_public? || (attachment.container_type == "Course" && attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id result << attachment end end diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb index 761111cec..eec1e255a 100644 --- a/app/views/attachments/add_exist_file_to_courses.js.erb +++ b/app/views/attachments/add_exist_file_to_courses.js.erb @@ -1,7 +1,7 @@ <% if !@save_flag && @save_message %> $("#error_show").html("<%= @save_message.join(', ') %>"); -<% elsif @message || @message != "" %> - $("#error_show").html("<%= @message %>"); +<% elsif @message && @message != "" %> + $("#error_show").html("<%= @message.html_safe %>"); <% else %> closeModal(); <% end %>