Fix index pages.(frontend and backend)
This commit is contained in:
parent
768f2ffe05
commit
95b077b1e4
|
@ -331,7 +331,7 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
|
||||
def show
|
||||
@album = Album.find(params[:id])
|
||||
@images = @album.album_images.where(:order => [nil,-1]).desc(:created_at)
|
||||
@images = @album.album_images.where(:order.in => [nil,-1]).desc(:created_at)
|
||||
images = @album.album_images.where(:order.gt => -1).asc(:order)
|
||||
@images = @images.concat(images)
|
||||
image_content = []
|
||||
|
|
|
@ -35,10 +35,28 @@ class GalleriesController < ApplicationController
|
|||
end
|
||||
|
||||
def index
|
||||
params = OrbitHelper.params
|
||||
album_tp = Album.filter_by_categories.filter_by_tags
|
||||
albums_no_order = album_tp.desc(:created_at).select{|v| v.order == -1 || v.order == nil}
|
||||
albums_with_order = album_tp.asc(:order).select{|v| v.order != -1}
|
||||
albums = albums_no_order.concat(albums_with_order)
|
||||
all_count = album_tp.count
|
||||
page_data_count = OrbitHelper.page_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 = []
|
||||
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])[0...(page_data_count - albums_with_order.count)]
|
||||
end
|
||||
else
|
||||
start_index = (page_data_count - (with_order_count % page_data_count) + page_data_count*(page_no - 1 - with_order_total_pages))
|
||||
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)
|
||||
galleries = albums.collect do |a|
|
||||
doc = Nokogiri::HTML(a.description.to_s)
|
||||
alt_text = doc.text.empty? ? 'gallery image' : doc.text
|
||||
|
|
Loading…
Reference in New Issue