项目资源搜索

This commit is contained in:
huang 2016-01-06 11:05:52 +08:00
parent 0a1aa9e569
commit c4718f992c
3 changed files with 35 additions and 36 deletions

View File

@ -99,6 +99,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]
@ -107,24 +108,26 @@ class FilesController < ApplicationController
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
@project_attachment_result = []
@searched_attach = paginateHelper @project_attachment_result, 10
else
@result = find_public_attache q,sort
@result = visable_attachemnts_insite @result,@project
@searched_attach = paginateHelper @result,10
@project_attachment_result = find_public_attache q,sort
@project_attachment_result = visable_attachemnts_insite @project_attachment_result, @project
@searched_attach = paginateHelper @project_attachment_result, 10
end
else
@result = find_project_attache q,@project,sort
@result = visable_attachemnts @result
@searched_attach = paginateHelper @result,10
end
@project_attachment_result = find_project_attache q, @project,sort
@project_attachment_result = visable_attachemnts @project_attachment_result
@searched_attach = paginateHelper @project_attachment_result,10
@tag_list = get_course_tag_list @project
end
#rescue Exception => e
# #render 'stores'
# redirect_to search_course_files_url
@ -200,23 +203,10 @@ class FilesController < ApplicationController
if sort == ""
sort = "created_on DESC"
end
ids = ""
len = 0
count = project.versions.count
project.versions.each do |version|
len = len + 1
if len != count
ids += version.id.to_s + ','
if keywords != "%%"
resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort)
else
ids += version.id.to_s
end
end
if ids.blank?
resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").
reorder(sort)
else
resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%").
reorder(sort)
resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' "). reorder(sort)
end
end

View File

@ -8,9 +8,9 @@
</div>
<div class="homepagePostDes">
<div class="homepagePostTitle break_word mt-4">
<%= link_to truncate(file.filename,length: 35, omission: '...'), download_named_attachment_path(file.id, file.filename),
:title => file.filename+"\n"+file.description.to_s,
:style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkBlue f_14 f_b" %>
<%= link_to truncate(file.filename,length: 35, omission: '...'),
download_named_attachment_path(file.id, file.filename),
:title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkBlue f_14 f_b" %>
<%= file_preview_eye(file, class: 'preview') %>
<span id="image_private_<%= file.id%>">
<% if file.is_public? == false%>
@ -33,11 +33,13 @@
<%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %>
</div>
<div class="homepagePostSetting">
<ul>
<li class="homepagePostSettingIcon">
<%= render :partial => 'file_tools', :locals => {:project => @project, :file => file, :tag_name => @tag_name, :delete_allowed => delete_allowed} %>
</li>
</ul>
</div>
<div class="cl"></div>
</div>
@ -53,6 +55,7 @@
<% if params[:action] == 'search' %>
<%=link_to "点击展开更多", search_project_files_path({:project_id => project.id,:page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %>
<%else%>
<!-- 全站搜索的时候 返回的页码对象是obj_pages,而站内搜索返回的页码对象是feedback_pages -->
<%=link_to "点击展开更多", project_files_path({:project_id => project.id,:page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %>
<%end%>
<% end%>

View File

@ -1 +1,7 @@
$("#course_list").html("<%= escape_javascript(render :partial => 'project_file_list',:locals => {project: @project,all_attachments: @result,sort:@sort,order:@order,project_attachments:@searched_attach,:manage_allowed => User.current.allowed_to?(:manage_files, @project)})%>");
<% if (@obj_pages &&( @obj_pages.page > 1)) || (@feedback_pages && (@feedback_pages.page > 1)) %> //搜索的时候有时候是需要加载下一页,有时候是直接替换当前 #course_list。这个根据 page来判定
$("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/project_list',
:locals => {project: @project, all_attachments:@result, sort:@sort, order:@order, project_attachments:@searched_attach})%>");
<% else %>
$("#course_list").html("<%= escape_javascript(render :partial => 'files/project_list',:locals => {project:@project, all_attachments:@result, sort:@sort, order:@order,project_attachments:@searched_attach})%>");
$("#attachment_count").html("<%= @project_attachment_result.count %>")
<% end %>