icon search controller
This commit is contained in:
parent
76f69973b4
commit
00022ce9fe
|
@ -25,13 +25,15 @@ class StoresController < ApplicationController
|
|||
|
||||
LIMIT = 12 unless const_defined?(:LIMIT)
|
||||
def index
|
||||
@projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1).
|
||||
reorder("#{Attachment.table_name}.downloads DESC").
|
||||
limit(LIMIT)
|
||||
@projects_attach = project_classification(0).take(LIMIT)
|
||||
@courses_attach = project_classification(1).take(LIMIT)
|
||||
# @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1).
|
||||
# reorder("#{Attachment.table_name}.downloads DESC").
|
||||
# limit(LIMIT)
|
||||
|
||||
@courses_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 1, 1).
|
||||
reorder("#{Attachment.table_name}.downloads DESC").
|
||||
limit(LIMIT)
|
||||
# @courses_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 1, 1).
|
||||
# reorder("#{Attachment.table_name}.downloads DESC").
|
||||
# limit(LIMIT)
|
||||
@homeworks_attach = Attachment.where("container_type = 'HomeworkAttach'").
|
||||
reorder("downloads DESC").
|
||||
limit(LIMIT)
|
||||
|
@ -49,30 +51,45 @@ class StoresController < ApplicationController
|
|||
private
|
||||
|
||||
def project_classification project_type=0
|
||||
pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").
|
||||
where("projects.project_type=#{project_type}").
|
||||
reorder("downloads DESC").
|
||||
limit(LIMIT)
|
||||
# pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").
|
||||
# where("attachments.container_type='Project' AND projects.is_public=1 AND projects.project_type=#{project_type}").
|
||||
# reorder("downloads DESC").
|
||||
# limit(LIMIT)
|
||||
pro_attach = join_tools_project Project, project_type
|
||||
doc_attach = join_tools_project Document, project_type
|
||||
issue_attach = join_tools_project Issue, project_type
|
||||
mess_attach = []
|
||||
news_attach = join_tools_project News"news", project_type
|
||||
vers_attach = join_tools_project Version"versions", project_type
|
||||
wiki_attach = []
|
||||
mess_attach = join_tools_project Message, project_type
|
||||
news_attach = join_tools_project News, project_type
|
||||
vers_attach = join_tools_project Version, project_type
|
||||
wiki_attach = join_tools_project WikiPage, project_type
|
||||
|
||||
tmp = pro_attach
|
||||
tmp = pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
|
||||
tmp.sort { |a, b| b.downloads <=> a.downloads }
|
||||
end
|
||||
def join_tools_project tableName, project_type=0
|
||||
Attachment.joins(str_join_table(tableName)).
|
||||
where("projects.project_type=#{project_type}").
|
||||
where("attachments.container_type='#{tableName.to_s}' AND projects.is_public=1 AND projects.project_type=#{project_type}").
|
||||
reorder('downloads DESC').
|
||||
limit(LIMIT)
|
||||
end
|
||||
|
||||
def str_join_table tableClass
|
||||
str = "LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
|
||||
case tableClass.to_s
|
||||
when 'Project'
|
||||
"LEFT JOIN projects ON attachments.container_id = projects.id"
|
||||
when 'Document', 'Issue', 'Version', 'News' # 连接子表即有 project_id 字段,即两层连接
|
||||
"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
|
||||
when 'Message' # 三层连接
|
||||
"LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
|
||||
LEFT JOIN boards ON boards.id = #{tableClass.table_name}.board_id
|
||||
LEFT JOIN projects ON boards.project_id = projects.id"
|
||||
when 'WikiPage'# 三层连接
|
||||
"LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
|
||||
LEFT JOIN wikis ON wikis.id = #{tableClass.table_name}.wiki_id
|
||||
LEFT JOIN projects ON wikis.project_id = projects.id"
|
||||
else
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<% content_for :top_field do%>
|
||||
<div style="margin: 10px 5%;vertical-align: bottom;">
|
||||
<%= form_tag( search_stores_path, method: 'post') do %>
|
||||
<%= text_field_tag 'name', nil, size:"100", placeholder:'请输入要搜索的关键字', :class => 'blueinputbar' %>
|
||||
<%= text_field_tag 'name', nil, size:"100", placeholder:'请输入要搜索的关键字', :class => 'blueinputbar', :required => true %>
|
||||
<%= submit_tag l(:label_search), :class => "enterprise"%>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<% content_for :top_field do%>
|
||||
<div style="margin: 10px 5%;">
|
||||
<%= form_tag( search_stores_path, method: 'post') do %>
|
||||
<%= text_field_tag 'name', nil, size:"100", placeholder:'请输入要搜索的关键字', :value => params[:name] , :class => 'blueinputbar'%>
|
||||
<%= text_field_tag 'name', nil, size:"100", placeholder:'请输入要搜索的关键字', :value => params[:name] , :class => 'blueinputbar', :required => true %>
|
||||
<%= submit_tag l(:label_search), :class => "enterprise"%>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 41 KiB |
Binary file not shown.
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 41 KiB |
Loading…
Reference in New Issue