Merge branch 'bigchange' of 10.0.47.245:/home/trustie2 into bigchange

This commit is contained in:
nieguanghui 2014-01-16 10:17:51 +08:00
commit 346e9574ca
6 changed files with 90 additions and 24 deletions

View File

@ -25,13 +25,15 @@ class StoresController < ApplicationController
LIMIT = 12 unless const_defined?(:LIMIT) LIMIT = 12 unless const_defined?(:LIMIT)
def index def index
@projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1). @projects_attach = project_classification(0).take(LIMIT)
reorder("#{Attachment.table_name}.downloads DESC"). @courses_attach = project_classification(1).take(LIMIT)
limit(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). # @courses_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 1, 1).
reorder("#{Attachment.table_name}.downloads DESC"). # reorder("#{Attachment.table_name}.downloads DESC").
limit(LIMIT) # limit(LIMIT)
@homeworks_attach = Attachment.where("container_type = 'HomeworkAttach'"). @homeworks_attach = Attachment.where("container_type = 'HomeworkAttach'").
reorder("downloads DESC"). reorder("downloads DESC").
limit(LIMIT) limit(LIMIT)
@ -49,30 +51,45 @@ class StoresController < ApplicationController
private private
def project_classification project_type=0 def project_classification project_type=0
pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id"). # pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").
where("projects.project_type=#{project_type}"). # where("attachments.container_type='Project' AND projects.is_public=1 AND projects.project_type=#{project_type}").
reorder("downloads DESC"). # reorder("downloads DESC").
limit(LIMIT) # limit(LIMIT)
pro_attach = join_tools_project Project, project_type
doc_attach = join_tools_project Document, project_type doc_attach = join_tools_project Document, project_type
issue_attach = join_tools_project Issue, project_type issue_attach = join_tools_project Issue, project_type
mess_attach = [] mess_attach = join_tools_project Message, project_type
news_attach = join_tools_project News"news", project_type news_attach = join_tools_project News, project_type
vers_attach = join_tools_project Version"versions", project_type vers_attach = join_tools_project Version, project_type
wiki_attach = [] wiki_attach = join_tools_project WikiPage, project_type
tmp = pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach 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 } tmp.sort { |a, b| b.downloads <=> a.downloads }
end end
def join_tools_project tableName, project_type=0 def join_tools_project tableName, project_type=0
Attachment.joins(str_join_table(tableName)). 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'). reorder('downloads DESC').
limit(LIMIT) limit(LIMIT)
end end
def str_join_table tableClass def str_join_table tableClass
str = "LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id case tableClass.to_s
LEFT JOIN projects ON #{tableClass.table_name}.project_id = projects.id" when 'Project'
str "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"
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
end end

View File

@ -2,6 +2,7 @@
<html lang="<%= current_language %>"> <html lang="<%= current_language %>">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title><%= h html_title %></title> <title><%= h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" /> <meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" /> <meta name="keywords" content="issue,bug,tracker" />

View File

@ -1,7 +1,7 @@
<% content_for :top_field do%> <% content_for :top_field do%>
<div style="margin: 10px 5%;vertical-align: bottom;"> <div style="margin: 10px 5%;vertical-align: bottom;">
<%= form_tag( search_stores_path, method: 'get') do %> <%= 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"%> <%= submit_tag l(:label_search), :class => "enterprise"%>
<% end %> <% end %>
</div> </div>

View File

@ -1,7 +1,22 @@
<style type='text/css'>
.highlight {
background-color: #fff34d;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 1px 4px rgba(0,0,0,0.7);
-webkit-box-shadow: 0px 1px 4px rgba(0,0,0,0.7);
box-shadow: 0px 1px 4px rgba(0,0,0,0.7);
}
.highlight {
padding: 1px 4px;
margin: 0 -4px;
}
</style>
<% content_for :top_field do%> <% content_for :top_field do%>
<div style="margin: 10px 5%;"> <div style="margin: 10px 5%;">
<%= form_tag( search_stores_path, method: 'get') do %> <%= 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"%> <%= submit_tag l(:label_search), :class => "enterprise"%>
<% end %> <% end %>
</div> </div>
@ -31,4 +46,37 @@
</table> </table>
<div style="height: 20px; width: 100%;"></div> <div style="height: 20px; width: 100%;"></div>
<% end %> <% end %>
<div class="pagination"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %></div> <div class="pagination"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %></div>
<script type='text/javascript'>
jQuery.fn.highlight = function(pat) {
function innerHighlight(node, pat) {
var skip = 0;
if (node.nodeType == 3) {
var pos = node.data.toUpperCase().indexOf(pat);
if (pos >= 0) {
var spannode = document.createElement('span');
spannode.className = 'highlight';
var middlebit = node.splitText(pos);
var endbit = middlebit.splitText(pat.length);
var middleclone = middlebit.cloneNode(true);
spannode.appendChild(middleclone);
middlebit.parentNode.replaceChild(spannode, middlebit);
skip = 1;
}
}
else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
for (var i = 0; i < node.childNodes.length; ++i) {
i += innerHighlight(node.childNodes[i], pat);
}
}
return skip;
}
return this.each(function() {
innerHighlight(this, pat.toUpperCase());
});
};
$(document).ready(function($) {
$('.cb span').highlight('<%=params[:name]%>')
// $('#main').highlight('<%=params[:name]%>')
});
</script>

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