1.完全重写了tag搜索页面的显示方式,修复了由于分页引起的bug;

2.给需求添加了赞和踩;
This commit is contained in:
william 2013-08-28 20:36:27 +08:00
parent ee551d220d
commit bb96536a1e
7 changed files with 65 additions and 47 deletions

View File

@ -16,33 +16,44 @@ class TagsController < ApplicationController
# $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]
@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?
@ -56,6 +67,7 @@ class TagsController < ApplicationController
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总数

View File

@ -5,6 +5,14 @@
<td><table width="100%" border="0">
<tr>
<td><h3><%= link_to(@bid.author.name, user_path(@bid.author))%><%= @bid.name %></h3></td>
<td>
<!-- 在这里添加赞和踩-->
<span id="praise_tread" style="float: right">
<%= render :partial => "/praise_tread/praise_tread",
:locals => {:obj => @bid,:show_flag => true,:user_id =>User.current.id}%>
</span>
</td>
</tr>
<tr>
<% if @bid.reward_type.nil? or @bid.reward_type == 1%>

View File

@ -1,5 +1,5 @@
<div class="pagination" style="float:right;">
<%=
pagination_links_full obj_pages,:per_page_links => false
pagination_links_full obj_pages,:per_page_links => true,:remote=>true
%>
</div>

View File

@ -3,12 +3,13 @@
<% for rt in related_tags %>
<li>
<%= 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 %>
<span id="tag">
<%= rt %>
</span>
<!-- 这里用例计数某类对象的所有该tag总数 -->
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => rt }%>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => rt }%>
</li>
<% end %>
</ul>

View File

@ -3,9 +3,10 @@
<% for sg in selected_tags %>
<li>
<%= 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 %>
<span id="tag"><%= sg %> </span>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => sg }%>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => sg }%>
</li>
<% end %>
</ul>

View File

@ -2,16 +2,16 @@
<% unless show_flag.nil? %>
<% case %>
<% when show_flag == '1' %>
<strong><%=l(:label_user)%><strong>
<strong><%=l(:label_user)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_users",:locals => {:users_results => users_results}%>
<% when show_flag == '2'%>
<strong><%=l(:label_project)%></strong>
<strong><%=l(:label_project)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_projects",:locals => {:projects_results => projects_results }%>
<% when show_flag == '3'%>
<strong><%=l(:label_issue)%></strong>
<strong><%=l(:label_issue)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_issues",:locals => {:issues_results => issues_results }%>
<% when show_flag == '4'%>
<strong><%= l(:label_requirement)%></strong>
<strong><%= l(:label_requirement)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_bids",:locals => {:bids_results => bids_results}%>
<% else %>
<strong><%= l(:label_tags_all_objects)%></strong>
@ -23,6 +23,7 @@
<% end %>
<% else %>
<span>no data.</span>
<span>no data...</span>
<% end %>
</ul>
<%= render :partial => "pagination",:locals => {:obj_pages => @obj_pages} %>

View File

@ -3,13 +3,13 @@
<h3><strong><%= l(:label_tags_selected) %></strong></h3>
<div id="selected_tags">
<%= 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 }%>
</div>
<h3><strong><%= l(:label_tags_related) %></strong></h3>
<div id="related_tags">
<%= render :partial => "related_tags",:locals => {:related_tags => @related_tags,
:selected_tags => @selected_tags,:show_flag => @obj_flag }%>
:selected_tags => @selected_tags,:obj_flag => @obj_flag,:obj_id => @obj_id }%>
</div>
</div>
<% end %>