Fix album widget method.

This commit is contained in:
BoHung Chiu 2022-03-05 23:22:38 +08:00
parent b242499e45
commit 3abf2b7d4e
1 changed files with 1 additions and 26 deletions

View File

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