From 07b75924d8e453d7a813a631862f23c11d49a321 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Sat, 26 Apr 2014 10:42:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9tag=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E5=BE=97tag=E6=90=9C=E7=B4=A2=E8=83=BD?= =?UTF-8?q?=E5=A4=9F=E6=90=9C=E7=B4=A2=E5=BC=80=E6=BA=90=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=20=E5=9C=A8=E5=B8=96=E5=AD=90=E5=B1=95=E7=A4=BA=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 17 +++++++-- app/helpers/application_helper.rb | 4 ++ app/helpers/open_source_projects_helper.rb | 12 ++++-- app/views/relative_memos/show.html.erb | 38 +++++++++++++++---- .../tags/_show_open_source_projects.html.erb | 15 ++++++++ app/views/tags/_tag_search_results.html.erb | 4 ++ app/views/tags/index.html.erb | 6 ++- config/locales/zh.yml | 1 + 8 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 app/views/tags/_show_open_source_projects.html.erb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index ac2a5236b..c9d58c0a6 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f8acafc1f..6777be9be 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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) diff --git a/app/helpers/open_source_projects_helper.rb b/app/helpers/open_source_projects_helper.rb index 69ce66c61..f758580d9 100644 --- a/app/helpers/open_source_projects_helper.rb +++ b/app/helpers/open_source_projects_helper.rb @@ -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 diff --git a/app/views/relative_memos/show.html.erb b/app/views/relative_memos/show.html.erb index 69ea0de41..0b51ec1f4 100644 --- a/app/views/relative_memos/show.html.erb +++ b/app/views/relative_memos/show.html.erb @@ -1,6 +1,11 @@
-
<%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) if @memo.author %>
+
+ <% 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 %>

<%=link_to @memo.author.name, user_path(@memo.author) if @memo.author%>

@@ -40,23 +45,31 @@ :data => {:confirm => l(:text_are_you_sure)}, :title => l(:button_delete) ) if @memo.destroyable_by?(User.current) %> - -
<%= label_tag l(:field_subject) %>: <%=h @memo.subject %>
<%= raw @memo.content %> -

+

<% 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 %>

-
<%= authoring @memo.created_at, @memo.author.name if @memo.author %>
- +
+ <% if @memo.author %> + <%= authoring @memo.created_at, @memo.author.name %> + <% else %> + <%= added_time @memo.created_at %> + <% end %>
+
+
+ <%= image_tag( "/images/sidebar/tags.png") %> + <%= render :partial => 'tags/tag_name', :locals => {:obj => @memo,:object_flag => "8",:non_list_all => true }%> +
+

@@ -107,7 +120,11 @@ - +
- <%= 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 %>
<%=h reply.content.html_safe %>
@@ -121,7 +138,12 @@
<%= authoring reply.created_at, reply.author.name if reply.author %> + <% if reply.author %> + <%= authoring reply.created_at, reply.author.name %> + <% else %> + <%= added_time reply.created_at %> + <% end %>
diff --git a/app/views/tags/_show_open_source_projects.html.erb b/app/views/tags/_show_open_source_projects.html.erb new file mode 100644 index 000000000..2c8bc6374 --- /dev/null +++ b/app/views/tags/_show_open_source_projects.html.erb @@ -0,0 +1,15 @@ +
+<% if projects_results.size > 0 %> +
+<% projects_results.each do |prj| %> +
+

+ <%= l(:label_tags_project_name) %><%= link_to "#{prj.name}",:controller => "open_source_projects",:action => "show",:id => prj.id %> +
+ <%= l(:label_tags_project_description) %><%= prj.short_description %> +

+
+
+<% end %> +<% end %> +
diff --git a/app/views/tags/_tag_search_results.html.erb b/app/views/tags/_tag_search_results.html.erb index c67ece520..0dfabd7fe 100644 --- a/app/views/tags/_tag_search_results.html.erb +++ b/app/views/tags/_tag_search_results.html.erb @@ -19,6 +19,10 @@ <% when show_flag == '6'%> <%= l(:label_attachment)%>(<%= @results_count %>) <%= render :partial => "show_attachments",:locals => {:attachments_results => attachments_results}%> + <% when show_flag == '7'%> + <%#= l(:label_attachment)%> + 开源项目:(<%= @results_count %>) + <%= render :partial => "show_open_source_projects",:locals => {:projects_results => open_source_projects_results}%> <% else %> <%= l(:label_tags_all_objects)%> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 17ac58184..068017c46 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -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 %>)
<%# 求工厂模式重构 %> <%= 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}%>
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 77db00aa8..e6ebbfeb5 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 选择一个项目...