From 0cc809c3e0fac4685062518894799c803cea5182 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 15 Apr 2015 19:57:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=AF=BE=E7=A8=8B=E8=B5=84?= =?UTF-8?q?=E6=BA=90TAG=E4=BA=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 26 +++++++++++++++++++- app/helpers/files_helper.rb | 6 +++++ app/views/files/_course_file.html.erb | 1 - app/views/files/_course_list.html.erb | 2 +- app/views/files/search_tag_attachment.js.erb | 1 + config/routes.rb | 1 + public/javascripts/course.js | 16 ++++++++++++ 7 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 app/views/files/search_tag_attachment.js.erb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 47cabbc6c..29350f0f7 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,7 +23,7 @@ class FilesController < ApplicationController before_filter :auth_login1, :only => [:index] before_filter :logged_user_by_apptoken,:only => [:index] before_filter :find_project_by_project_id#, :except => [:getattachtype] - before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project,:search_tag_attachment] helper :sort include SortHelper @@ -51,6 +51,7 @@ class FilesController < ApplicationController @sort = "" @order = "" @is_remote = true + @q = params[:name].strip if params[:sort] order_by = params[:sort].split(":") @sort = order_by[0] @@ -519,8 +520,31 @@ class FilesController < ApplicationController format.html end end + end + #查找指定TAG的按条件过滤的资源列表 + def search_tag_attachment + @q,@tag_name,@order = params[:q],params[:tag_name] + @is_remote = true + if params[:sort] + order_by = params[:sort].split(":") + @sort = order_by[0] + if order_by.count > 1 + @order = order_by[1] + end + sort = "#{@sort} #{@order}" + end + q = "%#{@q.strip}%" + @result = find_course_attache q,@course,sort + @result = visable_attachemnts @result + @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} + @searched_attach = paginateHelper @result,10 + @tag_list = attachment_tag_list @result + respond_to do |format| + format.js + # format.html + end end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 111b9214f..0be59c0da 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -128,6 +128,12 @@ module FilesHelper tag_list.sort {|a,b| b[1]<=>a[1]} end + def get_attachments_by_tag attachments,tag + attachments.each do |attachment| + attachment.tag_list.include?(tag) + end + end + def visable_attachemnts_insite attachments,obj result = [] if obj.is_a?(Course) diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 62fd14248..7b2acd875 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -48,7 +48,6 @@ $('#incourse').attr("class", "re_schbtn b_lblue"); $('#insite').attr("class", "re_schbtn b_lblue"); } -