diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 3c815c7d8..a57b5f8a5 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -141,6 +141,23 @@ class AttachmentsController < ApplicationController
end
end
+ def update_file_dense
+ @attachment = Attachment.find(params[:attachmentid])
+ if @attachment != nil
+ filedense = params[:newtype].to_s
+ if filedense == "1"
+ @attachment.is_public = 1
+ else
+ @attachment.is_public = 0
+ end
+ @attachment.save
+ @newfiledense = filedense
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
def thumbnail
if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size])
if stale?(:etag => thumbnail)
@@ -326,6 +343,35 @@ class AttachmentsController < ApplicationController
end
end
+ def add_exist_file_to_courses
+ file = Attachment.find(params[:file_id])
+ courses = params[:courses][:course]
+ courses.each do |course|
+ c = Course.find(course);
+ attach_copied_obj = file.copy
+ attach_copied_obj.tag_list.add(file.tag_list) # tag关联
+ attach_copied_obj.container = c
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 4
+ end
+ @obj = c
+ @save_flag = attach_copied_obj.save
+ @save_message = attach_copied_obj.errors.full_messages
+ end
+ respond_to do |format|
+ format.js
+ end
+ rescue NoMethodError
+ @save_flag = false
+ @save_message = [] << l(:error_attachment_empty)
+ respond_to do |format|
+ format.js
+ end
+ end
+
private
def find_project
@attachment = Attachment.find(params[:id])
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 91176efdf..ca7f8e040 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -22,22 +22,55 @@ class FilesController < ApplicationController
menu_item :files
before_filter :find_project_by_project_id#, :except => [:getattachtype]
- before_filter :authorize, :except => [:getattachtype]
+ before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search]
helper :sort
include SortHelper
helper :project_score
def show_attachments obj
- all_attachments = []
+ @all_attachments = []
obj.each do |container|
- all_attachments += container.attachments
+ @all_attachments += container.attachments
end
@limit = 10
- @feedback_count = all_attachments.count
+ @feedback_count = @all_attachments.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
- @curse_attachments = all_attachments[@offset, @limit]
+ @curse_attachments_all = @all_attachments[@offset, @limit]
+ @curse_attachments = paginateHelper @all_attachments,10
+ end
+
+ def search
+ begin
+ @is_remote = true
+ q = "%#{params[:name].strip}%"
+ #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
+ if params[:insite]
+ @result = find_public_attache q
+ @searched_attach = paginateHelper @result,10
+ else
+ @result = find_course_attache q,@course
+ @searched_attach = paginateHelper @result,10
+ end
+
+ rescue Exception => e
+ #render 'stores'
+ redirect_to stores_url
+ end
+ end
+
+ def find_course_attache keywords,course
+ resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").
+ reorder("created_on DESC")
+ end
+
+ def find_public_attache keywords
+ # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map
+ # 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。
+ # 现在还木有思路 药丸
+ resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%").
+ reorder("created_on DESC")
end
def index
@@ -48,7 +81,9 @@ class FilesController < ApplicationController
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
sort = ""
-
+ @sort = ""
+ @order = ""
+ @is_remote = false
if params[:project_id]
@isproject = true
@@ -113,7 +148,8 @@ class FilesController < ApplicationController
when "created_on"
attribute = "created_on"
end
-
+ @sort = order_by[0]
+ @order = order_by[1]
if order_by.count == 1
sort += "#{Attachment.table_name}.#{attribute} asc "
elsif order_by.count == 2
@@ -134,6 +170,10 @@ class FilesController < ApplicationController
end
+ def quote_resource_show
+ @file = Attachment.find(params[:id])
+ end
+
def new
@versions = @project.versions.sort
@course_tag = @project.project_type
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index b64c18b33..5bd5fb0e3 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -14,12 +14,14 @@ class TagsController < ApplicationController
include AttachmentsHelper
include ContestsHelper
include ActsAsTaggableOn::TagsHelper
+ include TagsHelper
helper :projects
helper :courses
helper :tags
include OpenSourceProjectsHelper
before_filter :require_admin,:only => [:delete,:show_all]
+ before_filter :require_login,:only => [:tag_save]
# $selected_tags = Array.new
# $related_tags = Array.new
@@ -187,6 +189,83 @@ class TagsController < ApplicationController
# end
end
end
+
+ # 只删除某个对象的该tag
+ def remove_tag_new
+ @obj = nil
+ @object_flag = nil
+
+ if request.get?
+ # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象
+ @tag_name = params[:tag_name]
+ @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id
+ @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串
+ @taggable_type = numbers_to_object_type(params[:taggable_type])
+
+ @obj = get_object(@taggable_id,params[:taggable_type])
+ @object_flag = params[:taggable_type]
+
+ # if can_remove_tag?(User.current,@taggable_id,@taggable_type)
+
+ @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type)
+
+ unless @taggings.nil?
+ @taggings.delete
+ end
+
+ # 是否还有其他记录 引用了 tag_id
+ @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
+ # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作
+ if @tagging.nil?
+ @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
+ @tag.delete unless @tag.nil?
+ end
+ # end
+ end
+ end
+
+ def tag_save
+ @tags = params[:tag_for_save][:name]
+ @obj_id = params[:tag_for_save][:object_id]
+ @obj_flag = params[:tag_for_save][:object_flag]
+
+ case @obj_flag
+ when '1' then
+ @obj = User.find_by_id(@obj_id)
+ when '2' then
+ @obj = Project.find_by_id(@obj_id)
+ when '3' then
+ @obj = Issue.find_by_id(@obj_id)
+ when '4' then
+ @obj = Bid.find_by_id(@obj_id)
+ when '5' then
+ @obj = Forum.find_by_id(@obj_id)
+ when '6'
+ @obj = Attachment.find_by_id(@obj_id)
+ when '7' then
+ @obj = Contest.find_by_id(@obj_id)
+ when '8'
+ @obj = OpenSourceProject.find_by_id(@obj_id)
+ when '9'
+ @obj = Course.find_by_id(@obj_id)
+ else
+ @obj = nil
+ end
+ unless @obj.nil?
+ @obj.tag_list.add(@tags.split(","))
+ else
+ return
+ end
+ if @obj.save
+ logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}"
+ else
+ logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}"
+ end
+ respond_to do |format|
+ format.js
+ format.html
+ end
+ end
private
# 这里用来刷新搜索结果的区域
@@ -307,5 +386,7 @@ class TagsController < ApplicationController
return
end
end
+
+
end
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 7ea49dad2..3c882d393 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -177,6 +177,8 @@ module AttachmentsHelper
s.html_safe
end
+
+
# Modified by Longjun
# 有参数的方法要加()
def private_filter(resultSet)
diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb
index 052aae468..9a0a1127f 100644
--- a/app/helpers/files_helper.rb
+++ b/app/helpers/files_helper.rb
@@ -44,6 +44,16 @@ module FilesHelper
File.new(zipfile_name,'w+')
end
+ def courses_check_box_tags(name,courses,current_course)
+ s = ''
+ courses.each do |course|
+ if course.id != current_course.id && is_course_teacher(User.current,course)
+ s << "
"
+ end
+ end
+ s.html_safe
+ end
+
# 判断指定的资源时候符合类型
def isTypeOk(attachment, type, contentType)
result = false
diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb
new file mode 100644
index 000000000..23761647f
--- /dev/null
+++ b/app/views/attachments/add_exist_file_to_courses.js.erb
@@ -0,0 +1,5 @@
+<% if !@save_flag%>
+ $("#error_show").html("<%= @save_message.join(', ') %>");
+<% else %>
+ closeModal();
+<% end %>
diff --git a/app/views/attachments/update_file_dense.js.erb b/app/views/attachments/update_file_dense.js.erb
new file mode 100644
index 000000000..d99481d08
--- /dev/null
+++ b/app/views/attachments/update_file_dense.js.erb
@@ -0,0 +1,2 @@
+$("#is_public_<%= @attachment.id %>").html("<%= escape_javascript(link_to (@attachment.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>@attachment.id,:newtype=>(@attachment.is_public? ? 0:1)),
+ :remote=>true,:class=>"f_l re_open",:method => :post) %>");
diff --git a/app/views/files/_arrow_show.erb b/app/views/files/_arrow_show.erb
new file mode 100644
index 000000000..d8f094719
--- /dev/null
+++ b/app/views/files/_arrow_show.erb
@@ -0,0 +1,10 @@
+
+<% if sort == current %>
+ <% if order =="asc" %>
+ ↑
+ <% elsif order == "desc" %>
+ ↓
+ <% else %>
+
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/files/_attachement_list.html.erb b/app/views/files/_attachement_list.html.erb
new file mode 100644
index 000000000..f65ba8d41
--- /dev/null
+++ b/app/views/files/_attachement_list.html.erb
@@ -0,0 +1,46 @@
+
共有 <%= User.current.member_of_course?(course) ? all_attachments.count : 0 %> 个资源
+ +文件大小:<%= 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 %> +<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %> | 下载<%= file.downloads %> | 引用0
+