added random albums
This commit is contained in:
parent
958e801fc7
commit
0ce35c692d
|
@ -1,26 +1,52 @@
|
||||||
class GalleriesController < ApplicationController
|
class GalleriesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
# albums = Album.filter_by_categories
|
params = OrbitHelper.params
|
||||||
|
page = Page.where(:page_id => params[:page_id]).first
|
||||||
|
if page.layout.starts_with?("random")
|
||||||
|
data = get_random_data
|
||||||
|
else
|
||||||
|
data = get_data
|
||||||
|
end
|
||||||
|
|
||||||
params = OrbitHelper.params
|
data
|
||||||
|
end
|
||||||
|
|
||||||
albums = Album.filter_by_categories([],false).filter_by_tags.sample(OrbitHelper.page_data_count)
|
def get_random_data
|
||||||
albums = Kaminari.paginate_array(albums).page(params[:page]).per(OrbitHelper.page_data_count)
|
categories = OrbitHelper.page_categories
|
||||||
|
if categories.include?("all")
|
||||||
galleries = albums.collect do |a|
|
albums = Album.all.sample(OrbitHelper.page_data_count)
|
||||||
{
|
else
|
||||||
"album-name" => a.name,
|
albums = Album.where(:category_id.in => categories).filter_by_tags.sample(OrbitHelper.page_data_count)
|
||||||
"album-description" => a.description,
|
end
|
||||||
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
galleries = albums.collect do |a|
|
||||||
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg"
|
{
|
||||||
}
|
"album-name" => a.name,
|
||||||
|
"album-description" => a.description,
|
||||||
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
||||||
|
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
{
|
||||||
|
"albums" => galleries,
|
||||||
|
"extras" => {"widget-title"=>"Gallery"},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_data
|
||||||
|
albums = Album.filter_by_categories.filter_by_tags
|
||||||
|
galleries = albums.collect do |a|
|
||||||
|
{
|
||||||
|
"album-name" => a.name,
|
||||||
|
"album-description" => a.description,
|
||||||
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
||||||
|
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
"albums" => galleries,
|
"albums" => galleries,
|
||||||
"extras" => {"widget-title"=>"Gallery"},
|
"extras" => {"widget-title"=>"Gallery"},
|
||||||
"total_pages" => albums.total_pages
|
"total_pages" => albums.total_pages
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
Loading…
Reference in New Issue