This commit is contained in:
yanxd 2014-01-14 20:48:43 +08:00
parent 91a6c13ced
commit 2bb44456d6
4 changed files with 45 additions and 15 deletions

View File

@ -9,10 +9,10 @@ class StoresController < ApplicationController
def search
name = params[:name] ||= ''
@searched_attach = Attachment.includes(:project).where("projects.is_public = ? AND filename LIKE '%"<< name <<"%' ", 1)
# @searched_attach = Attachment.all[0..20]
@searched_attach.take 20
# reutrn @searched_attach
# 按文件名搜索
result = Attachment.includes(:project).where("projects.is_public = ? AND filename LIKE '%" << name << "%' ", 1)
@searched_attach = result
return @searched_attach
end
LIMIT = 12 unless const_defined?(:LIMIT)
@ -47,12 +47,12 @@ class StoresController < ApplicationController
where("projects.project_type=#{project_type}").
reorder("downloads DESC").
limit(LIMIT)
doc_attach = join_tools_project "documents", project_type
issue_attach = join_tools_project "issues", project_type
mess_attach = []#join_tools_project "messages", project_type
news_attach = join_tools_project "news", project_type
vers_attach = join_tools_project "versions", project_type
wiki_attach = []#join_tools_project "wiki_pages", project_type
doc_attach = join_tools_project Document, project_type
issue_attach = join_tools_project Issue, project_type
mess_attach = []#join_tools_project Message, project_type
news_attach = join_tools_project News"news", project_type
vers_attach = join_tools_project Version"versions", project_type
wiki_attach = []#join_tools_project WikiPage, project_type
tmp = pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
tmp.sort { |a, b| b.downloads <=> a.downloads }
@ -64,9 +64,9 @@ class StoresController < ApplicationController
limit(LIMIT)
end
def str_join_table tableName
str = "LEFT JOIN #{tableName} ON attachments.container_id = #{tableName}.id
LEFT JOIN projects ON #{tableName}.project_id = projects.id"
def str_join_table tableClass
str = "LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
LEFT JOIN projects ON #{tableClass.table_name}.project_id = projects.id"
str
end
end

View File

@ -27,4 +27,34 @@ module StoresHelper
'#'#logger.error "StoresHelper#attachUrl unkown type ==> #{container}"
end
end
def come_from_local attachment # TODO: title_html look at.
container = attachment.container
case container.class.to_s
when 'Message'
board_message_path(container.board, container)
when 'Issue'
issue_path(container)
when 'Document'
document_path container
when 'HomeworkAttach'
bid_path(container.bid)
when 'Memo'
forum_memo_path(container.forum, container)
when 'News'
news_path(container)
when 'Project'
project_files_path(container)
when 'Version'
# version_path(container)
project_files_path(container.project)
when 'WikiPage'
project_wiki_path(container.project)
when 'Bid'
bid_path(container)
else
'#'#logger.error "StoresHelper#attachUrl unkown type ==> #{container}"
end
end
end

View File

@ -38,7 +38,7 @@
</tr>
<tr>
<td style="padding-left: 8px"><%= link_to stores_url , stores_url %></td>
<td><p class="top-content-list"><%=link_to l(:label_home),home_path %> > <%=link_to l(:label_course_file),:controller => 'projects', :action => 'index', :project_type => 0 %> > <%=link_to @project, '' %></p></td>
<td><p class="top-content-list"><%=link_to l(:label_home),home_path %> > <%=link_to l(:label_course_file),stores_url %> </p></td>
</tr>
</table>
</div>

View File

@ -1,7 +1,7 @@
<% content_for :top_field do%>
<div style="margin: 10px 5%;">
<%= form_tag( search_stores_path, method: 'get') do %>
<%= text_field_tag 'name', nil, size:"100", placeholder:'请输入要搜索的关键字' %>
<%= text_field_tag 'name', nil, size:"100", placeholder:'请输入要搜索的关键字', :value => params[:name] %>
<%= submit_tag l(:label_search), class:"whiteButton m3p10 h30"%>
<% end %>
</div>