diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 83bba0d52..a57b5f8a5 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -353,7 +353,7 @@ class AttachmentsController < ApplicationController 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 + 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 diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 57fc44f5c..ca7f8e040 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -22,7 +22,7 @@ class FilesController < ApplicationController menu_item :files before_filter :find_project_by_project_id#, :except => [:getattachtype] - before_filter :authorize, :except => [:getattachtype,:quote_resource_show] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search] helper :sort include SortHelper @@ -41,6 +41,38 @@ class FilesController < ApplicationController @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 #sort_init 'filename', 'asc' sort_init 'created_on', 'desc' @@ -51,6 +83,7 @@ class FilesController < ApplicationController sort = "" @sort = "" @order = "" + @is_remote = false if params[:project_id] @isproject = true diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 78fdd3fc5..49747ae11 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -1,6 +1,6 @@ <% attachmenttypes = @course.attachmenttypes %> <% sufixtypes = @course.contenttypes %> -<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> + <%= stylesheet_link_tag 'resource', :media => 'all' %>