From d62ad9e8632a26652d040936f6e5c8628aff075c Mon Sep 17 00:00:00 2001 From: william Date: Mon, 19 Aug 2013 17:28:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99tag=20search=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=88=86=E9=A1=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 1 + app/controllers/tags_controller.rb | 50 ++++++++++++++++-- app/models/user.rb | 4 +- app/models/user_extensions.rb | 1 + app/views/my/account.html.erb | 11 +++- app/views/projects/index.html.erb | 2 +- app/views/tags/_related_tags.html.erb | 2 +- app/views/tags/_selected_tags.html.erb | 2 +- app/views/tags/_show_bids.html.erb | 5 ++ app/views/tags/_show_issues.html.erb | 5 ++ app/views/tags/_show_projects.html.erb | 6 ++- app/views/tags/_show_users.html.erb | 5 ++ app/views/tags/_tag.html.erb | 2 +- app/views/tags/_tag_search_results.html.erb | 4 +- app/views/tags/index.html.erb | 7 +-- app/views/users/_user_extensions.html.erb | 26 +++++++++ config/locales/zh.yml | 12 +++++ config/settings.yml | 8 +-- public/images/praise_tread/praise_false.png | Bin 2878 -> 2877 bytes public/images/praise_tread/praise_true.png | Bin 2875 -> 2877 bytes public/images/praise_tread/tread_false.png | Bin 2889 -> 2884 bytes public/images/praise_tread/tread_true.png | Bin 2884 -> 2883 bytes .../stylesheets/application.css | 5 +- 23 files changed, 136 insertions(+), 22 deletions(-) create mode 100644 app/views/users/_user_extensions.html.erb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 6b8c03661..8ef719241 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -15,6 +15,7 @@ class BidsController < ApplicationController @bids = @bids.like(params[:name]) if params[:name].present? @bid_count = @bids.count @bid_pages = Paginator.new @bid_count, @limit, params['page'] + @offset ||= @bid_pages.reverse_offset #@bids = @bids.offset(@offset).limit(@limit).all.reverse unless @offset == 0 diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index ab05474fe..ccfeccd68 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -7,6 +7,7 @@ class TagsController < ApplicationController include UsersHelper include BidsHelper include ActsAsTaggableOn::TagsHelper + helper :projects $selected_tags = Array.new $related_tags = Array.new @@ -21,23 +22,56 @@ class TagsController < ApplicationController @users_tags_num = User.tag_counts.size @bids_tags_num = Bid.tag_counts.size - @issues_results = get_issues_by_tag($selected_tags) - @projects_results = get_projects_by_tag($selected_tags) - @users_results = get_users_by_tag($selected_tags) - @bids_results = get_bids_by_tag($selected_tags) + # 这里为了提高系统的响应速度 把搜索结果放到case中去了 + @users_results = nil + @projects_results = nil + @issues_results = nil + @bids_results = nil + @obj_pages = nil @obj_id = params[:obj_id] @obj_flag = params[:object_flag] + @numbers = Setting.tags_show_search_results case @obj_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' + @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 @@ -83,4 +117,12 @@ class TagsController < ApplicationController end + def for_pagination(results) + @offset, @limit = api_offset_and_limit({:limit => 2}) + @project_count = results.count + @obj_pages = Paginator.new @project_count, @limit, params['page'] + @offset ||= @obj_pages.offset + results = results.offset(@offset).limit(@limit).order('lft').all + end + end diff --git a/app/models/user.rb b/app/models/user.rb index e27c6a782..ae672b53a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -99,7 +99,9 @@ class User < Principal acts_as_taggable scope :by_join_date, order("created_at DESC") ############################# added by liuping 关注 - acts_as_watchable + acts_as_watchable + has_one :user_extensions + ## end attr_accessor :password, :password_confirmation attr_accessor :last_before_login_on diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb index f70cddad8..47578e66f 100644 --- a/app/models/user_extensions.rb +++ b/app/models/user_extensions.rb @@ -1,4 +1,5 @@ class UserExtensions < ActiveRecord::Base + belongs_to :user attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code #this method was used to update the table user_extensions def update_user_extensions(birthday=nil,brief_introduction=nil, diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 9a75481ad..2143dee68 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -5,8 +5,6 @@

<%= l(:label_my_account)%>

- -
+ + + <%= submit_tag l(:button_save) %>
<% end %> diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 4435727fc..8f4852ef5 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -25,7 +25,7 @@ diff --git a/app/views/tags/_related_tags.html.erb b/app/views/tags/_related_tags.html.erb index 84fb06923..42b3c010f 100644 --- a/app/views/tags/_related_tags.html.erb +++ b/app/views/tags/_related_tags.html.erb @@ -1,5 +1,5 @@ <% if related_tags %> -