From 3abf2b7d4e74f147b77a344563017350b6277fc3 Mon Sep 17 00:00:00 2001 From: Bohung Date: Sat, 5 Mar 2022 23:22:38 +0800 Subject: [PATCH] Fix album widget method. --- app/controllers/galleries_controller.rb | 27 +------------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index 0bf2006..a4a4b53 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -131,32 +131,7 @@ class GalleriesController < ApplicationController @album_setting = AlbumSetting.first params = OrbitHelper.params tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags - album_tp = Album.filter_by_widget_categories(OrbitHelper.widget_categories,false).filter_by_tags(tags) - all_count = album_tp.count - page_data_count = OrbitHelper.widget_data_count - no_order_count = album_tp.where(:order.in=>[-1,nil]).count - with_order_count = all_count - no_order_count - with_order_total_pages = (with_order_count.to_f / page_data_count).ceil - albums_with_order = album_tp.asc(:order).where(:order.ne=>-1).and(:order.ne=>nil).to_a rescue [] - page_no = (params[:page_no] || 1).to_i - if page_no < with_order_total_pages - albums_no_order = [] - albums_with_order = albums_with_order[(page_no-1)*page_data_count...page_no*page_data_count] - elsif page_no == with_order_total_pages - if albums_with_order.count == page_data_count - albums_no_order = [] - else - albums_no_order = album_tp.desc(:created_at).where(:order.in=>[-1,nil]).page(nil).per(all_count)[0...(page_data_count - albums_with_order.count)] - end - else - albums_with_order = [] - start_index = page_data_count*(page_no - 1 - with_order_total_pages) - if with_order_count != 0 - start_index += (page_data_count - (with_order_count % page_data_count)) - end - albums_no_order = album_tp.desc(:created_at).where(:order.in=>[-1,nil]).page(nil).per(all_count)[start_index...(start_index+page_data_count)].to_a - end - albums = albums_with_order.concat(albums_no_order) + albums = Album.filter_by_widget_categories(OrbitHelper.widget_categories,false).filter_by_tags(tags).to_a album_color_map = AlbumColor.where(:album_id.in=> albums.map{|v| v.id}).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h galleries = albums.collect.with_index do |a,i| doc = Nokogiri::HTML(a.description.to_s)