From 0602a03e12000d2b4081b33215c0e7d97969f6e1 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Mon, 14 Dec 2015 10:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E8=B5=84=E6=BA=90=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=A0=8F=E7=9B=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=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 | 93 +++++++++++++++++++ app/helpers/files_helper.rb | 6 ++ app/views/files/_subfield_files.html.erb | 2 +- .../files/search_files_in_subfield.js.erb | 2 + .../_org_left_subfield_list.html.erb | 4 +- config/routes.rb | 2 +- db/schema.rb | 4 + 7 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 app/views/files/search_files_in_subfield.js.erb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 328446fbb..6ed42bd6e 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -131,6 +131,45 @@ class FilesController < ApplicationController end end + def search_files_in_subfield + sort = "" + @sort = "" + @order = "" + @is_remote = true + @q = params[:name].strip + 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 + # show_attachments [@course] + begin + q = "%#{params[:name].strip}%" + #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? + if params[:insite] + if q == "%%" + @result = [] + @searched_attach = paginateHelper @result,10 + else + @result = find_public_attache q,sort + @result = visable_attachemnts_insite @result,@org_subfield + @searched_attach = paginateHelper @result,10 + end + else + @result = find_org_subfield_attache q,@org_subfield,sort + @result = visable_attachemnts @result + @searched_attach = paginateHelper @result,10 + #@tag_list = get_course_tag_list @course + end + #rescue Exception => e + # #render 'stores' + # redirect_to search_course_files_url + end + end + def find_course_attache keywords,course,sort = "" if sort == "" sort = "created_on DESC" @@ -144,6 +183,19 @@ class FilesController < ApplicationController #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") end + def find_org_subfield_attache keywords,org_subfield,sort = "" + if sort == "" + sort = "created_on DESC" + end + if keywords != "%%" + resultSet = Attachment.where("attachments.container_type = 'OrgSubfield' And attachments.container_id = '#{org_subfield.id}' AND filename LIKE :like ", like: "%#{keywords}%"). + reorder(sort) + else + resultSet = Attachment.where("attachments.container_type = 'OrgSubfield' And attachments.container_id = '#{org_subfield.id}' "). reorder(sort) + end + #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") + end + def find_project_attache keywords,project,sort = "" if sort == "" sort = "created_on DESC" @@ -298,6 +350,47 @@ class FilesController < ApplicationController render :layout => 'base_courses' elsif params[:org_subfield_id] + if params[:sort] + params[:sort].split(",").each do |sort_type| + order_by = sort_type.split(":") + + case order_by[0] + when "filename" + attribute = "filename" + when "size" + attribute = "filesize" + when "attach_type" + attribute = "attachtype" + when "content_type" + attribute = "created_on" + when "field_file_dense" + attribute = "is_public" + when "downloads" + attribute = "downloads" + when "created_on" + attribute = "created_on" + when "quotes" + attribute = "quotes" + else + attribute = "created_on" + end + @sort = order_by[0] + @order = order_by[1] + if order_by.count == 1 && attribute + sort += "#{Attachment.table_name}.#{attribute} asc " + if sort_type != params[:sort].split(",").last + sort += "," + end + elsif order_by.count == 2 && order_by[1] + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + if sort_type != params[:sort].split(",").last + sort += "," + end + end + end + else + sort = "#{Attachment.table_name}.created_on desc" + end @container_type = 2 @organization = Organization.find(params[:organization_id]) @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index cf9cbcc32..276786fb7 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -141,6 +141,12 @@ module FilesHelper result << attachment end end + elsif obj.is_a?(OrgSubfield) + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "OrgSubfield" && attachment.container_id == obj.id )|| attachment.author_id == User.current.id + result << attachment + end + end end end result diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb index ea408c7a6..b0bc9ea09 100644 --- a/app/views/files/_subfield_files.html.erb +++ b/app/views/files/_subfield_files.html.erb @@ -68,7 +68,7 @@
- <%= form_tag( search_org_subfield_files_path(@org_subfield), method: 'get',:class => "re_search f_l",:remote=>true) do %> + <%= form_tag( search_files_in_subfield_org_subfield_files_path(@org_subfield), method: 'get',:class => "re_search f_l",:remote=>true) do %> <%= text_field_tag 'name', params[:name], name: "name", :class => 're_schbox',:style=>"padding: 0px"%> <%= submit_tag "栏目内搜索", :class => "re_schbtn b_lblue",:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %> <%= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> diff --git a/app/views/files/search_files_in_subfield.js.erb b/app/views/files/search_files_in_subfield.js.erb new file mode 100644 index 000000000..deed2d5d3 --- /dev/null +++ b/app/views/files/search_files_in_subfield.js.erb @@ -0,0 +1,2 @@ +$("#org_subfield_list").html("<%= escape_javascript(render :partial => 'org_subfield_list', + :locals => {org_subfield: @org_subfield,all_attachments: @result,sort:@sort,order:@order,org_subfield_attachments:@searched_attach})%>"); \ No newline at end of file diff --git a/app/views/organizations/_org_left_subfield_list.html.erb b/app/views/organizations/_org_left_subfield_list.html.erb index 367c23843..152310bba 100644 --- a/app/views/organizations/_org_left_subfield_list.html.erb +++ b/app/views/organizations/_org_left_subfield_list.html.erb @@ -29,8 +29,8 @@ <%= link_to "#{field.name}", organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText" %> <%=link_to "", new_organization_org_document_comment_path(organization, :field_id => field.id), :method => "get", :class => "homepageMenuSetting fr", :title => "发布帖子"%> <% else %> - <%#= link_to "#{field.name}", org_subfield_files_path(field, :organization_id => organization.id), :class => "homepageMenuText" %> - <%= field.name %> + <%= link_to "#{field.name}", org_subfield_files_path(field, :organization_id => organization.id), :class => "homepageMenuText" %> + <% end %>