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 date_now = Time.now
@archive_file_categorys = WebLinkCategory.all if params[:category_id].blank?
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)
get_categorys 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 else
@web_links = WebLink.all.can_display.merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num) selected_categories = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true).entries
@sorted_by_category = selected_categories.inject({}) do |categories, category|
get_categorys 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 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 end

View File

@ -28,17 +28,33 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
@category_id = @part.category @category_id = @part.category
date_now = Time.now date_now = Time.now
if !params[:category_id].blank? 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)
get_categorys 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 else
@web_links = WebLink.all.can_display.merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num) selected_categories = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true).entries
get_categorys @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 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 end

View File

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

View File

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