组织资源类型的栏目,增加搜索功能
This commit is contained in:
parent
c2d21b5a6b
commit
0602a03e12
|
@ -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)]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
<div class="container">
|
||||
<div class="resources"><!--资源库内容开始--->
|
||||
<div class="re_top" style="width:710px;">
|
||||
<%= 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()" %>
|
||||
|
|
|
@ -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})%>");
|
|
@ -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" %>
|
||||
<a href="javascript:void(0);" class="homepageMenuText"><%= field.name %></a>
|
||||
<%= link_to "#{field.name}", org_subfield_files_path(field, :organization_id => organization.id), :class => "homepageMenuText" %>
|
||||
<!--<a href="javascript:void(0);" class="homepageMenuText"><%#= field.name %></a>-->
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="homepageLeftMenuCourses" id="homepageLeftMenuField_<%= field.id %>" style="display:none;">
|
||||
|
|
|
@ -75,7 +75,7 @@ RedmineApp::Application.routes.draw do
|
|||
resources :files, :only => [:index, :new, :create] do
|
||||
collection do
|
||||
match "getattachtype", :via => [:get, :post]
|
||||
match "search",:via => [:post,:get]
|
||||
match "search_files_in_subfield",:via => [:post,:get]
|
||||
match "searchone4reload",:via => [:post,:get]
|
||||
match "search_tag_attachment", :via => [:post,:get]
|
||||
end
|
||||
|
|
|
@ -1619,6 +1619,10 @@ ActiveRecord::Schema.define(:version => 20151209085942) do
|
|||
t.string "extra"
|
||||
end
|
||||
|
||||
create_table "temp", :id => false, :force => true do |t|
|
||||
t.integer "id", :default => 0, :null => false
|
||||
end
|
||||
|
||||
create_table "time_entries", :force => true do |t|
|
||||
t.integer "project_id", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
|
|
Loading…
Reference in New Issue