From c763817ebf0e8c1e304418b9d119764255f2e02a Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 17 Jul 2013 17:54:34 +0800 Subject: [PATCH] Fix web link front end index and widget index --- .../front_end/web_links_controller.rb | 35 ++++++++++----- .../widget/web_links_controller.rb | 32 +++++++++---- .../front_end/web_links/index.html.erb | 37 +++++++-------- .../widget/web_links/_index.html.erb | 45 ++++++++----------- 4 files changed, 82 insertions(+), 67 deletions(-) diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb index ce972346d..947d0cd8f 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb @@ -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 diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb index 648c65d94..f914d6c0e 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb @@ -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 diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb index 8c0d2e1ca..2b85372e3 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb @@ -3,28 +3,23 @@ diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_index.html.erb index 5ff291fa2..1f9f36549 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_index.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_index.html.erb @@ -1,36 +1,27 @@ -
-<% 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 %> +
+ <%= link_to t(:more_plus), panel_web_resource_front_end_web_links_path(category_id: params[:category_id], tag_id: params[:tag_id]) %>
\ No newline at end of file