修改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
include TagsHelper
helper :tags
include OpenSourceProjectsHelper
before_filter :require_admin,:only => [:delete,:show_all]
@ -53,7 +54,7 @@ class TagsController < ApplicationController
end
@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,
@ -61,7 +62,8 @@ class TagsController < ApplicationController
@issues_results,
@bids_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
unless @obj.nil?
@ -172,6 +174,7 @@ private
@bids_results = nil
@forums_results = nil
attachments_results = nil
@open_source_projects_results = nil
@obj_pages = nil
@obj = nil
@ -195,10 +198,13 @@ private
when '6'
@obj = Attachment.find_by_id(obj_id)
@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
@obj = nil
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
def for_pagination(results)
@ -218,7 +224,8 @@ private
@bids_tags_num = Bid.tag_counts.size
forum_tags_num = Forum.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
# 通过数字 来转换出对象的类型
@ -239,6 +246,8 @@ private
return 'Forum'
when '6'
return 'Attachment'
when '7'
return 'OpenSourceProject'
else
render_error :message => e.message
return

View File

@ -445,6 +445,10 @@ module ApplicationHelper
def authoring(created, author, options={})
l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe
end
def added_time(created)
l(:label_added_time, :age => time_tag(created)).html_safe
end
#huang
def betweentime(enddate)

View File

@ -3,16 +3,16 @@ module OpenSourceProjectsHelper
s=''.html_safe
unless app_dir.nil?
s_temp = content_tag('a', app_dir)
temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :language => language, :created_at => created_at, :name => name}
temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :language => language, :created_at => created_at, :name => name}
temp = content_tag('span', temp, :class => 'del')
s_temp << temp
s_temp = content_tag('span', s_temp, :class => 'tag_show')
s << content_tag('div', s_temp, :id => 'tag')
end
unless language.nil?
s_temp = content_tag('a', language)
temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :created_at => created_at, :name => name}
temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :created_at => created_at, :name => name}
temp = content_tag('span', temp, :class => 'del')
s_temp << temp
s_temp = content_tag('span', s_temp, :class => 'tag_show')
@ -20,7 +20,7 @@ module OpenSourceProjectsHelper
end
unless created_at.nil?
s_temp = content_tag('a', created_at)
temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :language => language, :name => name}
temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :language => language, :name => name}
temp = content_tag('span', temp, :class => 'del')
s_temp << temp
s_temp = content_tag('span', s_temp, :class => 'tag_show')
@ -30,4 +30,8 @@ module OpenSourceProjectsHelper
s = content_tag('div', s, :id => 'tags')
s = content_tag('div', s, :class => 'user_tags')
end
def get_open_source_projects_by_tag(tag_name)
OpenSourceProject.tagged_with(tag_name).order('created_at desc')
end
end

View File

@ -1,6 +1,11 @@
<div class="lz">
<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>
</div>
<div class="memo-section">
@ -40,23 +45,31 @@
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) if @memo.destroyable_by?(User.current) %>
</div>
<div class="memo-title <%= @memo.sticky ? 'sticky' : '' %> <%= @memo.locked? ? 'locked' : '' %>"><%= label_tag l(:field_subject) %>: <%=h @memo.subject %></div>
<div class="memo-content">
<!-- < %= textilizable(@memo, :content) %> -->
<%= raw @memo.content %>
<p>
<p>
<% if @memo.attachments.any?%>
<% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %>
<%= render :partial => 'attachments/links', :locals => {:attachments => @memo.attachments, :options => options} %>
<% end %>
</p>
</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>
<br />
</div>
@ -107,7 +120,11 @@
<table class="borad-text-list">
<tr>
<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 class="comments">
<div class="reply_content" ><%=h reply.content.html_safe %></div>
@ -121,7 +138,12 @@
</td>
</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>
</table>
</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'%>
<strong><%= l(:label_attachment)%>(<%= @results_count %>)</strong>
<%= 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 %>
<strong><%= l(:label_tags_all_objects)%></strong>
<!-- 这里为显示搜有过滤结果预留了默认设置 -->

View File

@ -22,13 +22,15 @@
<%= l(:label_project_plural) %>(<%= @projects_tags_num %>) |
<%= l(:label_user_plural) %>(<%= @users_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 id="show_results">
<%# 求工厂模式重构 %>
<%= render :partial => "tag_search_results",:locals => {:issues_results => @issues_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>

View File

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