Fix web link front end index and widget index

This commit is contained in:
chris 2013-07-17 17:54:34 +08:00
parent 3c3bba514a
commit c763817ebf
4 changed files with 82 additions and 67 deletions

View File

@ -22,20 +22,33 @@ class Panel::WebResource::FrontEnd::WebLinksController < OrbitWidgetController
date_now = Time.now
@archive_file_categorys = WebLinkCategory.all
if !params[:category_id].blank?
@web_links = WebLink.all.can_display.any_in(:web_link_category_id => params[:category_id]).merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
@web_link_categorys = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:tag_id].blank?
@web_links = WebLink.all.can_display.any_in(:tagged_ids => params[:tag_id]).merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
if params[:category_id].blank?
get_categorys
@sorted_by_category = @web_link_categorys.inject({}) do |categories, category|
unless category.web_links.blank?
if params[:tag_id].blank?
categories[category.title] = category.web_links.can_display.desc( :is_top, :created_at )
else
categories[category.title] = category.web_links.can_display.any_in(:tagged_ids => params[:tag_id]).desc( :is_top, :created_at )
end
end
categories
end
else
@web_links = WebLink.all.can_display.merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
get_categorys
selected_categories = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true).entries
@sorted_by_category = selected_categories.inject({}) do |categories, category|
unless category.web_links.blank?
if params[:tag_id].blank?
categories[category.title] = category.web_links.can_display.desc( :is_top, :created_at )
else
debugger
categories[category.title] = category.web_links.can_display.any_in(:tagged_ids => params[:tag_id]).desc( :is_top, :created_at )
end
end
categories
end
end
@web_links = Kaminari.paginate_array(@sorted_by_category.values.map{|web_links| web_links.entries}.flatten).page(params[:page_main]).per(@page_num)
end

View File

@ -28,17 +28,33 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
@category_id = @part.category
date_now = Time.now
if !params[:category_id].blank?
@web_links = WebLink.all.can_display.any_in(:web_link_category_id => params[:category_id]).merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
@web_link_categorys = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:tag_id].blank?
@web_links = WebLink.all.can_display.any_in(:tagged_ids => params[:tag_id]).merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
if params[:category_id].blank?
get_categorys
@sorted_by_category = @web_link_categorys.inject({}) do |categories, category|
unless category.web_links.blank?
if params[:tag_id].blank?
categories[category.title] = category.web_links.can_display.desc( :is_top, :created_at )
else
categories[category.title] = category.web_links.can_display.any_in(:tagged_ids => params[:tag_id]).desc( :is_top, :created_at )
end
end
categories
end
else
@web_links = WebLink.all.can_display.merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
get_categorys
selected_categories = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true).entries
@sorted_by_category = selected_categories.inject({}) do |categories, category|
unless category.web_links.blank?
if params[:tag_id].blank?
categories[category.title] = category.web_links.can_display.desc( :is_top, :created_at )
else
categories[category.title] = category.web_links.can_display.any_in(:tagged_ids => params[:tag_id]).desc( :is_top, :created_at )
end
end
categories
end
end
@web_links = Kaminari.paginate_array(@sorted_by_category.values.map{|web_links| web_links.entries}.flatten).page(params[:page_main]).per(@page_num)
end

View File

@ -3,28 +3,23 @@
<div class="o-links">
<div class="o-links-content">
<ul>
<% @web_link_categorys.each do |wlcg| %>
<% if wlcg.web_links.count > 0 %>
<li>
<h3 class="o-links-category"><%= wlcg.title rescue nil%></h3>
<div class="o-links-list">
<ul>
<% wlcg.web_links.can_display.desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num).each do |post| %>
<li>
<%= link_to post.title, post.url, {:target => '_blank', :title => post.title, :class=>"o-links-title"} %>
<div class="o-links-description"><%= post.context %></div>
</li>
<% end %>
</ul>
</div>
</li>
<% @sorted_by_category.each do |title, web_links| %>
<% if web_links.count > 0 %>
<li>
<h3 class="o-links-category"><%= title rescue nil%></h3>
<div class="o-links-list">
<ul>
<% web_links.page(params[:page_main]).per(@page_num).each do |web_link| %>
<li>
<%= link_to web_link.title, web_link.url, {:target => '_blank', :title => web_link.title, :class=>"o-links-title"} %>
<div class="o-links-description"><%= web_link.context %></div>
</li>
<% end %>
</ul>
</div>
</li>
<% end %>
<% end %>
<% end %>
</ul>
</div>
</div>

View File

@ -1,36 +1,27 @@
<div class="o-links">
<div class="o-links-content">
<ul>
<% @web_link_categorys.each do |wlcg| %>
<% if wlcg.web_links.count > 0 %>
<li>
<h3 class="o-links-category"><%= wlcg.title rescue nil%></h3>
<div class="o-links-list">
<ul>
<% wlcg.web_links.can_display.desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num).each do |post| %>
<li>
<%= link_to post.title, post.url, {:target => '_blank', :title => post.title, :class=>"o-links-title"} %>
<div class="o-links-description"><%= post.context %></div>
</li>
<% end %>
</ul>
</div>
</li>
<% @sorted_by_category.each do |title, web_links| %>
<% if web_links.count > 0 %>
<li>
<h3 class="o-links-category"><%= title rescue nil%></h3>
<div class="o-links-list">
<ul>
<% web_links.page(params[:page_main]).per(@page_num).each do |web_link| %>
<li>
<%= link_to web_link.title, web_link.url, {:target => '_blank', :title => web_link.title, :class=>"o-links-title"} %>
<div class="o-links-description"><%= web_link.context %></div>
</li>
<% end %>
</ul>
</div>
</li>
<% end %>
<% end %>
<% end %>
</ul>
</div>
</div>
<div class="pull_right">
<% if !params[:category_id].blank? %>
<%= link_to t(:more_plus), panel_web_resource_front_end_web_links_path(:category_id => @part.category) %>
<% else %>
<%= link_to t(:more_plus), panel_web_resource_front_end_web_links_path %>
<% end %>
<div class="pull_right">
<%= link_to t(:more_plus), panel_web_resource_front_end_web_links_path(category_id: params[:category_id], tag_id: params[:tag_id]) %>
</div>