From 7fbe7f4de6f30f988591ea49be02474a197930cb Mon Sep 17 00:00:00 2001 From: william Date: Wed, 28 Aug 2013 10:57:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=87=E7=AD=BE=E7=9A=84?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 185 ++++++------------------- app/controllers/watchers_controller.rb | 20 +-- app/views/tags/_related_tags.html.erb | 4 +- app/views/tags/_selected_tags.html.erb | 4 +- app/views/tags/_show_bids.html.erb | 3 +- app/views/tags/_tag_name.html.erb | 2 - app/views/tags/index.html.erb | 8 +- 7 files changed, 67 insertions(+), 159 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index cac287653..3b133a120 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -12,43 +12,50 @@ class TagsController < ApplicationController before_filter :require_admin,:only => [:delete,:show_all] - $selected_tags = Array.new - $related_tags = Array.new - @@numbers = Setting.tags_show_search_results + # $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进行过滤传过来的参数 + # 最后是2个过滤何种数据,显示结果的控制参数params[:obj_id],params[:object_falg] + 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] + else + @selected_tags = params[:selected_tags] + end - - def index - $selected_tags = [] - $related_tags = [] - $selected_tags << params[:q] - @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num = get_tags_size - - @obj_id = params[:obj_id] - @obj_flag = params[:object_flag] - + # 获取搜索结果 @obj,@obj_pages,@users_results, @projects_results, @issues_results, - @bids_results, - @obj_pages = refresh_results(@obj_id,@obj_flag) + @bids_results = refresh_results(@obj_id,@obj_flag) - # 这里是做tag推荐用的, 用来生产推荐的tag + # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @tags = @obj.tag_list - $selected_tags.each do |i| + @selected_tags.each do |i| @tags.delete(i) - end - $related_tags = @tags + end + @related_tags = @tags else - return + return end end - - # 增加已选的tag def add_tag @tag = params[:tag] @@ -57,67 +64,11 @@ class TagsController < ApplicationController $selected_tags << @tag $related_tags.delete(@tag) - # # 获取搜索结果 - # @obj,@obj_pages,@users_results, - # @projects_results, - # @issues_results, - # @bids_results, - # @obj_pages = refresh_results(@obj_id,@show_flag) - - case @show_flag - when '1' then - @users_results = get_users_by_tag($selected_tags) - @obj = User.find_by_id(@obj_id) - - @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - @project_count = @users_results.count - - @obj_pages = Paginator.new @project_count, @limit, params['page'] - - @offset ||= @obj_pages.offset - @users_results = @users_results.offset(@offset).limit(@limit).all - - when '2' then - @projects_results = get_projects_by_tag($selected_tags) - @obj = Project.find_by_id(@obj_id) - - @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - @project_count = @projects_results.count - - @obj_pages = Paginator.new @project_count, @limit, params['page'] - - @offset ||= @obj_pages.offset - @projects_results = @projects_results.offset(@offset).limit(@limit).order('lft').all - - when '3' then - @issues_results = get_issues_by_tag($selected_tags) - @obj = Issue.find_by_id(@obj_id) - - @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - @project_count = @issues_results.count - - @obj_pages = Paginator.new @project_count, @limit, params['page'] - - @offset ||= @obj_pages.offset - @issues_results = @issues_results.offset(@offset).limit(@limit).all - - when '4' then - @bids_results = get_bids_by_tag($selected_tags) - @obj = Bid.find_by_id(@obj_id) - - @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - @project_count = @bids_results.count - - @obj_pages = Paginator.new @project_count, @limit, params['page'] - - @offset ||= @obj_pages.offset - @bids_results = @bids_results.offset(@offset).limit(@limit) - - - else - @obj = nil - end - + # 获取搜索结果 + @obj,@obj_pages,@users_results, + @projects_results, + @issues_results, + @bids_results = refresh_results(@obj_id,@show_flag) end # 删除已选tag @@ -128,59 +79,12 @@ class TagsController < ApplicationController $related_tags << @tag $selected_tags.delete(@tag) - @obj_pages = nil - - case @show_flag - when '1' then - @users_results = get_users_by_tag($selected_tags) - @obj = User.find_by_id(@obj_id) - - @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - @project_count = @users_results.count - @obj_pages = Paginator.new @project_count, @limit, params['page'] - @offset ||= @obj_pages.offset - @users_results = @users_results.offset(@offset).limit(@limit).all - when '2' then - @projects_results = get_projects_by_tag($selected_tags) - @obj = Project.find_by_id(@obj_id) - - @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - @project_count = @projects_results.count - @obj_pages = Paginator.new @project_count, @limit, params['page'] - @offset ||= @obj_pages.offset - @projects_results = @projects_results.offset(@offset).limit(@limit).order('lft').all - - when '3' then - @issues_results = get_issues_by_tag($selected_tags) - @obj = Issue.find_by_id(@obj_id) - - @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - @project_count = @issues_results.count - @obj_pages = Paginator.new @project_count, @limit, params['page'] - @offset ||= @obj_pages.offset - @issues_results = @issues_results.offset(@offset).limit(@limit).all - - when '4' - @obj_pages,@bids_results = for_pagination(get_bids_by_tag($selected_tags)) - - # @bids_results = get_bids_by_tag($selected_tags) - @obj = Bid.find_by_id(@obj_id) -# - # @offset, @limit = api_offset_and_limit({:limit => @@numbers}) - # @project_count = @bids_results.count - # @obj_pages = Paginator.new @project_count, @limit, params['page'] - # @offset ||= @obj_pages.offset - # @bids_results = @bids_results.offset(@offset).limit(@limit).all - - - - - else - @obj = nil - end - end + # 获取搜索结果 + @obj,@obj_pages,@users_results, + @projects_results, + @issues_results, + @bids_results = refresh_results(@obj_id,@show_flag) - def count(name) end def show_all @@ -215,19 +119,20 @@ private @bids_results = nil @obj_pages = nil @obj = nil + # 这里为了提高系统的响应速度 把搜索结果放到case中去了 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 = 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 = 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 = 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 = for_pagination(get_bids_by_tag(@selected_tags)) @obj = Bid.find_by_id(obj_id) else @obj = nil @@ -238,7 +143,7 @@ private def for_pagination(results) @offset, @limit = api_offset_and_limit({:limit => 3}) # 设置每页显示的个数 @results_count = results.count - @obj_pages = Paginator.new @results_count, @limit, params['page'] + @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 diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index e48c37403..29901aa6b 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -100,22 +100,22 @@ class WatchersController < ApplicationController watchable.set_watcher(user, watching) # @user = watchable # added by william if watching - # ޸ userproject״̬ + # 修改 user和project的状态 if watchable.instance_of?(User) - #дuser_statuses - watchable.user_status.update_watchers_count(1) + #写user_statuses表 + UserStatus.find_by_user_id(watchable.id).update_watchers_count(1) elsif watchable.instance_of?(Project) - #дproject_statuese - watchable.project_status.update_watchers_count(1) + #写project_statuese表 + ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(1) end else - # ޸ userproject״̬ + # 修改 user和project的状态 if watchable.instance_of?(User) - #дuser_statuses - watchable.user_status.update_watchers_count(-1) + #写user_statuses表 + UserStatus.find_by_user_id(watchable.id).update_watchers_count(-1) elsif watchable.instance_of?(Project) - #дproject_statuese :project_status - watchable.project_status.update_watchers_count(-1) + #写project_statuese表 :project_status + ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(-1) end end diff --git a/app/views/tags/_related_tags.html.erb b/app/views/tags/_related_tags.html.erb index b298cc0af..689868836 100644 --- a/app/views/tags/_related_tags.html.erb +++ b/app/views/tags/_related_tags.html.erb @@ -2,10 +2,12 @@