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 @@