From 68505239f9cd42c59049d0743dc90d5f1bbe2dc5 Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 21 Nov 2014 11:38:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=9A=82=E6=97=B6=E5=B1=8F?= =?UTF-8?q?=E8=94=BD=E6=8E=92=E5=BA=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 2 +- app/controllers/files_controller.rb | 35 ++++- app/views/files/_course_file.html.erb | 157 ++-------------------- app/views/files/_course_list.html.erb | 51 +++++++ app/views/files/search.js.erb | 1 + config/routes.rb | 1 + 6 files changed, 96 insertions(+), 151 deletions(-) create mode 100644 app/views/files/_course_list.html.erb create mode 100644 app/views/files/search.js.erb 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' %>