修改tag搜索,使得tag搜索能够搜索开源项目

在帖子展示页面添加时间,并添加标签
This commit is contained in:
fanqiang 2014-04-26 10:42:19 +08:00
parent 91d5959016
commit 07b75924d8
8 changed files with 79 additions and 18 deletions

View File

@ -14,6 +14,7 @@ class TagsController < ApplicationController
helper :projects helper :projects
include TagsHelper include TagsHelper
helper :tags helper :tags
include OpenSourceProjectsHelper
before_filter :require_admin,:only => [:delete,:show_all] before_filter :require_admin,:only => [:delete,:show_all]
@ -53,7 +54,7 @@ class TagsController < ApplicationController
end end
@users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,
@forum_tags_num, @attachments_tags_num = get_tags_size @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size
# 获取搜索结果 # 获取搜索结果
@obj,@obj_pages,@results_count,@users_results, @obj,@obj_pages,@results_count,@users_results,
@ -61,7 +62,8 @@ class TagsController < ApplicationController
@issues_results, @issues_results,
@bids_results, @bids_results,
@forums_results, @forums_results,
@attachments_results = refresh_results(@obj_id,@obj_flag,@selected_tags) @attachments_results,
@open_source_projects_results = refresh_results(@obj_id,@obj_flag,@selected_tags)
# 这里是做tag推荐用的 用来生产推荐的tags # 这里是做tag推荐用的 用来生产推荐的tags
unless @obj.nil? unless @obj.nil?
@ -172,6 +174,7 @@ private
@bids_results = nil @bids_results = nil
@forums_results = nil @forums_results = nil
attachments_results = nil attachments_results = nil
@open_source_projects_results = nil
@obj_pages = nil @obj_pages = nil
@obj = nil @obj = nil
@ -195,10 +198,13 @@ private
when '6' when '6'
@obj = Attachment.find_by_id(obj_id) @obj = Attachment.find_by_id(obj_id)
@obj_pages, attachments_results, @results_count = for_pagination(get_attachments_by_tag(selected_tags)) @obj_pages, attachments_results, @results_count = for_pagination(get_attachments_by_tag(selected_tags))
when '7'
@obj = OpenSourceProject.find_by_id(obj_id)
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
else else
@obj = nil @obj = nil
end end
return @obj,@obj_pages,@results_count,@users_results,@projects_results,@issues_results,@bids_results,@forums_results, attachments_results return @obj,@obj_pages,@results_count,@users_results,@projects_results,@issues_results,@bids_results,@forums_results, attachments_results, @open_source_projects_results
end end
def for_pagination(results) def for_pagination(results)
@ -218,7 +224,8 @@ private
@bids_tags_num = Bid.tag_counts.size @bids_tags_num = Bid.tag_counts.size
forum_tags_num = Forum.tag_counts.size forum_tags_num = Forum.tag_counts.size
attachment_tags_num = Attachment.tag_counts.size attachment_tags_num = Attachment.tag_counts.size
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num @open_source_projects_num = OpenSourceProject.tag_counts.size
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @open_source_projects_num
end end
# 通过数字 来转换出对象的类型 # 通过数字 来转换出对象的类型
@ -239,6 +246,8 @@ private
return 'Forum' return 'Forum'
when '6' when '6'
return 'Attachment' return 'Attachment'
when '7'
return 'OpenSourceProject'
else else
render_error :message => e.message render_error :message => e.message
return return

View File

@ -446,6 +446,10 @@ module ApplicationHelper
l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe
end end
def added_time(created)
l(:label_added_time, :age => time_tag(created)).html_safe
end
#huang #huang
def betweentime(enddate) def betweentime(enddate)
ss=(DateTime.parse("#{enddate.to_date}")-DateTime.parse("#{DateTime.now.to_date}")).to_i ss=(DateTime.parse("#{enddate.to_date}")-DateTime.parse("#{DateTime.now.to_date}")).to_i

View File

@ -30,4 +30,8 @@ module OpenSourceProjectsHelper
s = content_tag('div', s, :id => 'tags') s = content_tag('div', s, :id => 'tags')
s = content_tag('div', s, :class => 'user_tags') s = content_tag('div', s, :class => 'user_tags')
end end
def get_open_source_projects_by_tag(tag_name)
OpenSourceProject.tagged_with(tag_name).order('created_at desc')
end
end end

View File

@ -1,6 +1,11 @@
<div class="lz"> <div class="lz">
<div class="lz-left"> <div class="lz-left">
<div class=""><%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) if @memo.author %></div> <div class="">
<% if @memo.author%>
<%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) %>
<% else %>
<%= image_tag('../images/avatars/User/0', :class => "avatar") %>
<% end %></div>
<p class=""><%=link_to @memo.author.name, user_path(@memo.author) if @memo.author%></p> <p class=""><%=link_to @memo.author.name, user_path(@memo.author) if @memo.author%></p>
</div> </div>
<div class="memo-section"> <div class="memo-section">
@ -40,8 +45,6 @@
:data => {:confirm => l(:text_are_you_sure)}, :data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete) :title => l(:button_delete)
) if @memo.destroyable_by?(User.current) %> ) if @memo.destroyable_by?(User.current) %>
</div> </div>
<div class="memo-title <%= @memo.sticky ? 'sticky' : '' %> <%= @memo.locked? ? 'locked' : '' %>"><%= label_tag l(:field_subject) %>: <%=h @memo.subject %></div> <div class="memo-title <%= @memo.sticky ? 'sticky' : '' %> <%= @memo.locked? ? 'locked' : '' %>"><%= label_tag l(:field_subject) %>: <%=h @memo.subject %></div>
@ -55,8 +58,18 @@
<% end %> <% end %>
</p> </p>
</div> </div>
<div class="memo-timestamp"> <%= authoring @memo.created_at, @memo.author.name if @memo.author %></div> <div class="memo-timestamp">
<% if @memo.author %>
<%= authoring @memo.created_at, @memo.author.name %>
<% else %>
<%= added_time @memo.created_at %>
<% end %></div>
<div class="tags">
<div id="tags">
<%= image_tag( "/images/sidebar/tags.png") %>
<%= render :partial => 'tags/tag_name', :locals => {:obj => @memo,:object_flag => "8",:non_list_all => true }%>
</div>
</div>
</div> </div>
<br /> <br />
</div> </div>
@ -107,7 +120,11 @@
<table class="borad-text-list"> <table class="borad-text-list">
<tr> <tr>
<td rowspan="3" valign="top" width="60px"> <td rowspan="3" valign="top" width="60px">
<%= link_to image_tag(url_to_avatar(reply.author), :class => "avatar"), user_path(reply.author) if reply.author %> <% if reply.author%>
<%= link_to image_tag(url_to_avatar(reply.author), :class => "avatar"), user_path(reply.author) %>
<% else %>
<%= image_tag('../images/avatars/User/0', :class => "avatar") %>
<% end %>
</td> </td>
<td class="comments"> <td class="comments">
<div class="reply_content" ><%=h reply.content.html_safe %></div> <div class="reply_content" ><%=h reply.content.html_safe %></div>
@ -121,7 +138,12 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="font_lighter" style="float:right"><%= authoring reply.created_at, reply.author.name if reply.author %></td> <td class="font_lighter" style="float:right">
<% if reply.author %>
<%= authoring reply.created_at, reply.author.name %>
<% else %>
<%= added_time reply.created_at %>
<% end %></td>
</tr> </tr>
</table> </table>
</div> </div>

View File

@ -0,0 +1,15 @@
<div id="projects">
<% if projects_results.size > 0 %>
<hr />
<% projects_results.each do |prj| %>
<div>
<p class="font_description2">
<strong><%= l(:label_tags_project_name) %><%= link_to "#{prj.name}",:controller => "open_source_projects",:action => "show",:id => prj.id %></strong>
<br />
<strong><%= l(:label_tags_project_description) %></strong><%= prj.short_description %>
</p>
</div>
<div class="line_under"></div>
<% end %>
<% end %>
</div>

View File

@ -19,6 +19,10 @@
<% when show_flag == '6'%> <% when show_flag == '6'%>
<strong><%= l(:label_attachment)%>(<%= @results_count %>)</strong> <strong><%= l(:label_attachment)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_attachments",:locals => {:attachments_results => attachments_results}%> <%= render :partial => "show_attachments",:locals => {:attachments_results => attachments_results}%>
<% when show_flag == '7'%>
<strong><%#= l(:label_attachment)%>
开源项目:(<%= @results_count %>)</strong>
<%= render :partial => "show_open_source_projects",:locals => {:projects_results => open_source_projects_results}%>
<% else %> <% else %>
<strong><%= l(:label_tags_all_objects)%></strong> <strong><%= l(:label_tags_all_objects)%></strong>
<!-- 这里为显示搜有过滤结果预留了默认设置 --> <!-- 这里为显示搜有过滤结果预留了默认设置 -->

View File

@ -22,13 +22,15 @@
<%= l(:label_project_plural) %>(<%= @projects_tags_num %>) | <%= l(:label_project_plural) %>(<%= @projects_tags_num %>) |
<%= l(:label_user_plural) %>(<%= @users_tags_num %>) | <%= l(:label_user_plural) %>(<%= @users_tags_num %>) |
<%= l(:label_tags_call)%>(<%= @bids_tags_num %>) | <%= l(:label_tags_call)%>(<%= @bids_tags_num %>) |
<%= l(:field_filename)%>(<%= @attachments_tags_num %>) <%= l(:field_filename)%>(<%= @attachments_tags_num %>) |
开源项目(<%= @open_source_projects_num %>)
</div> </div>
<div id="show_results"> <div id="show_results">
<%# 求工厂模式重构 %> <%# 求工厂模式重构 %>
<%= render :partial => "tag_search_results",:locals => {:issues_results => @issues_results, <%= render :partial => "tag_search_results",:locals => {:issues_results => @issues_results,
:projects_results => @projects_results,:users_results => @users_results , :projects_results => @projects_results,:users_results => @users_results ,
:bids_results=>@bids_results,:forums_results => @forums_results, :attachments_results => @attachments_results, :show_flag => @obj_flag}%> :bids_results=>@bids_results,:forums_results => @forums_results, :attachments_results => @attachments_results,
:open_source_projects_results => @open_source_projects_results, :show_flag => @obj_flag}%>
</div> </div>
</div> </div>

View File

@ -828,6 +828,7 @@ zh:
label_feeds_access_key_created_on: "RSS存取键是在 %{value} 之前建立的" label_feeds_access_key_created_on: "RSS存取键是在 %{value} 之前建立的"
label_module_plural: 模块 label_module_plural: 模块
label_added_time_by: "由 %{author} 在 %{age} 之前添加" label_added_time_by: "由 %{author} 在 %{age} 之前添加"
label_added_time: "在 %{age} 之前添加"
label_updated_time: " 更新于 %{value} 之前" label_updated_time: " 更新于 %{value} 之前"
label_updated_time_by: "由 %{author} 更新于 %{age} 之前" label_updated_time_by: "由 %{author} 更新于 %{age} 之前"
label_jump_to_a_project: 选择一个项目... label_jump_to_a_project: 选择一个项目...