From bb96536a1ec2652bda2189b673d37f89e927872f Mon Sep 17 00:00:00 2001 From: william Date: Wed, 28 Aug 2013 20:36:27 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=AE=8C=E5=85=A8=E9=87=8D=E5=86=99=E4=BA=86?= =?UTF-8?q?tag=E6=90=9C=E7=B4=A2=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E7=94=B1=E4=BA=8E=E5=88=86=E9=A1=B5=E5=BC=95=E8=B5=B7=E7=9A=84?= =?UTF-8?q?bug=EF=BC=9B=202.=E7=BB=99=E9=9C=80=E6=B1=82=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E8=B5=9E=E5=92=8C=E8=B8=A9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 71 +++++++++++---------- app/views/bids/show.html.erb | 8 +++ app/views/tags/_pagination.html.erb | 2 +- app/views/tags/_related_tags.html.erb | 5 +- app/views/tags/_selected_tags.html.erb | 5 +- app/views/tags/_tag_search_results.html.erb | 11 ++-- app/views/tags/index.html.erb | 10 +-- 7 files changed, 65 insertions(+), 47 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 3b133a120..e99d2500c 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -9,40 +9,51 @@ class TagsController < ApplicationController include BidsHelper include ActsAsTaggableOn::TagsHelper helper :projects - + before_filter :require_admin,:only => [:delete,:show_all] # $selected_tags = Array.new # $related_tags = Array.new NUMBERS = Setting.tags_show_search_results - attr_reader :obj_id,:obj_flag,:selected_tags,:related_tags - # 接收参数解释: - # params[:q]这是在其他页面点击tag,跳转到该页面后的结果显示 - # params[:selected_tags],这是在过滤页面增删tag进行过滤传过来的参数 + # params[:q]这是在其他页面点击tag,跳转到该页面后的结果显示 ;params[:selected_tags],这是在过滤页面增删tag进行过滤传过来的参数 # 最后是2个过滤何种数据,显示结果的控制参数params[:obj_id],params[:object_falg] + # 0代表删除tag 1代表增加tag def index - - if params[:q] - @selected_tags = Array.new - @related_tags = Array.new - - @selected_tags.push params[:q] - - @obj_id = params[:obj_id] - @obj_flag = params[:object_flag] + + @obj_id = params[:obj_id] + @obj_flag = params[:object_flag] + + @selected_tags = Array.new + @related_tags = nil + + if params[:q] + @selected_tags << params[:q] else - @selected_tags = params[:selected_tags] + @do_what = params[:do_what] + @tag = params[:tag] + @selected_tags = params[:current_selected_tags] + @selected_tags = @selected_tags.nil? ? Array.new : @selected_tags + + case @do_what + when '0' then + @selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop + when '1' then + # 判断是否已存在该tag 主要用来处理分页的情况 + unless @selected_tags.include? @tag + @selected_tags << @tag + end + end end @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num = get_tags_size # 获取搜索结果 - @obj,@obj_pages,@users_results, + @obj,@obj_pages,@results_count,@users_results, @projects_results, @issues_results, - @bids_results = refresh_results(@obj_id,@obj_flag) + @bids_results = refresh_results(@obj_id,@obj_flag,@selected_tags) # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @@ -50,12 +61,13 @@ class TagsController < ApplicationController @selected_tags.each do |i| @tags.delete(i) end - @related_tags = @tags + @related_tags = @tags else return end end + # 增加已选的tag def add_tag @tag = params[:tag] @@ -80,7 +92,7 @@ class TagsController < ApplicationController $selected_tags.delete(@tag) # 获取搜索结果 - @obj,@obj_pages,@users_results, + @obj,@obj_pages,@results_count,@users_results, @projects_results, @issues_results, @bids_results = refresh_results(@obj_id,@show_flag) @@ -105,14 +117,9 @@ class TagsController < ApplicationController end private - - def tagged_on_object(object) - - end - # 这里用来刷新搜索结果的区域 # 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果 - def refresh_results(obj_id,obj_flag) + def refresh_results(obj_id,obj_flag,selected_tags) @users_results = nil @projects_results = nil @issues_results = nil @@ -124,29 +131,29 @@ private case obj_flag when '1' then @obj = User.find_by_id(obj_id) - @obj_pages,@users_results = for_pagination(get_users_by_tag(@selected_tags)) + @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags)) when '2' then @obj = Project.find_by_id(obj_id) - @obj_pages,@projects_results = for_pagination(get_projects_by_tag(@selected_tags)) + @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags)) when '3' then @obj = Issue.find_by_id(obj_id) - @obj_pages,@issues_results = for_pagination(get_issues_by_tag(@selected_tags)) + @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags)) when '4' then - @obj_pages,@bids_results = for_pagination(get_bids_by_tag(@selected_tags)) + @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags)) @obj = Bid.find_by_id(obj_id) else @obj = nil end - return @obj,@obj_pages,@users_results,@projects_results,@issues_results,@bids_results + return @obj,@obj_pages,@results_count,@users_results,@projects_results,@issues_results,@bids_results end def for_pagination(results) - @offset, @limit = api_offset_and_limit({:limit => 3}) # 设置每页显示的个数 + @offset, @limit = api_offset_and_limit({:limit => NUMBERS }) # 设置每页显示的个数 @results_count = results.count @obj_pages = Paginator.new @results_count, @limit, params['page'] # 3个参数分别是:总数,每页显示数目,第几页 @offset ||= @obj_pages.offset results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序 - return @obj_pages,results + return @obj_pages,results, @results_count end #获取有某类对象的tag总数 diff --git a/app/views/bids/show.html.erb b/app/views/bids/show.html.erb index 034f980ec..5e0ceb5df 100644 --- a/app/views/bids/show.html.erb +++ b/app/views/bids/show.html.erb @@ -5,6 +5,14 @@ + <% if @bid.reward_type.nil? or @bid.reward_type == 1%> diff --git a/app/views/tags/_pagination.html.erb b/app/views/tags/_pagination.html.erb index 888916ef7..3f2d89ce7 100644 --- a/app/views/tags/_pagination.html.erb +++ b/app/views/tags/_pagination.html.erb @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/app/views/tags/_related_tags.html.erb b/app/views/tags/_related_tags.html.erb index 689868836..2dd1d93e8 100644 --- a/app/views/tags/_related_tags.html.erb +++ b/app/views/tags/_related_tags.html.erb @@ -3,12 +3,13 @@ <% for rt in related_tags %>
  • <%= link_to image_tag("/images/sidebar/add.png"),:action => "index", - :selected_tags => selected_tags %> + :current_selected_tags => selected_tags,:tag => rt,:do_what => "1", + :obj_id => obj_id,:object_flag => obj_flag %> <%= rt %> - <%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => rt }%> + <%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => rt }%>
  • <% end %> diff --git a/app/views/tags/_selected_tags.html.erb b/app/views/tags/_selected_tags.html.erb index 39363a9f3..3081177bc 100644 --- a/app/views/tags/_selected_tags.html.erb +++ b/app/views/tags/_selected_tags.html.erb @@ -3,9 +3,10 @@ <% for sg in selected_tags %>
  • <%= link_to image_tag("/images/sidebar/minus.png"),:action => "index", - :selected_tags => selected_tags %> + :current_selected_tags => selected_tags ,:tag => sg,:do_what => "0", + :obj_id => obj_id,:object_flag => obj_flag %> <%= sg %> - <%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => sg }%> + <%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => sg }%>
  • <% end %> diff --git a/app/views/tags/_tag_search_results.html.erb b/app/views/tags/_tag_search_results.html.erb index 3eee6df39..44f6d0031 100644 --- a/app/views/tags/_tag_search_results.html.erb +++ b/app/views/tags/_tag_search_results.html.erb @@ -2,16 +2,16 @@ <% unless show_flag.nil? %> <% case %> <% when show_flag == '1' %> - <%=l(:label_user)%> + <%=l(:label_user)%>(<%= @results_count %>) <%= render :partial => "show_users",:locals => {:users_results => users_results}%> <% when show_flag == '2'%> - <%=l(:label_project)%> + <%=l(:label_project)%>(<%= @results_count %>) <%= render :partial => "show_projects",:locals => {:projects_results => projects_results }%> <% when show_flag == '3'%> - <%=l(:label_issue)%> + <%=l(:label_issue)%>(<%= @results_count %>) <%= render :partial => "show_issues",:locals => {:issues_results => issues_results }%> <% when show_flag == '4'%> - <%= l(:label_requirement)%> + <%= l(:label_requirement)%>(<%= @results_count %>) <%= render :partial => "show_bids",:locals => {:bids_results => bids_results}%> <% else %> <%= l(:label_tags_all_objects)%> @@ -23,6 +23,7 @@ <% end %> <% else %> - no data. + no data... <% end %> +<%= render :partial => "pagination",:locals => {:obj_pages => @obj_pages} %> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 504232d95..121725ad5 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -3,13 +3,13 @@

    <%= l(:label_tags_selected) %>

    <%= render :partial => "selected_tags",:locals => { - :selected_tags => @selected_tags,:show_flag => @obj_flag}%> + :selected_tags => @selected_tags,:obj_flag => @obj_flag,:obj_id => @obj_id }%>

    <%= l(:label_tags_related) %>

    <% end %> @@ -18,9 +18,9 @@

    <%= l(:label_tags_search_result) %>

    <%= l(:label_tags_numbers) %> - <%= l(:label_issue_plural) %>(<%= @issues_tags_num %>)| - <%= l(:label_project_plural) %>(<%= @projects_tags_num %>)| - <%= l(:label_user_plural) %>(<%= @users_tags_num %>)| + <%= l(:label_issue_plural) %>(<%= @issues_tags_num %>) | + <%= l(:label_project_plural) %>(<%= @projects_tags_num %>) | + <%= l(:label_user_plural) %>(<%= @users_tags_num %>) | <%= l(:label_tags_call)%>(<%= @bids_tags_num %>)

    <%= link_to(@bid.author.name, user_path(@bid.author))%>:<%= @bid.name %>

    + + + <%= render :partial => "/praise_tread/praise_tread", + :locals => {:obj => @bid,:show_flag => true,:user_id =>User.current.id}%> + + +