131 lines
3.6 KiB
Ruby
131 lines
3.6 KiB
Ruby
class GalleriesController < ApplicationController
|
|
def index
|
|
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
|
|
|
|
data
|
|
end
|
|
|
|
def get_random_data
|
|
categories = OrbitHelper.page_categories
|
|
if categories.include?("all")
|
|
albums = Album.all.sample(OrbitHelper.page_data_count)
|
|
else
|
|
albums = Album.where(:category_id.in => categories).filter_by_tags.sample(OrbitHelper.page_data_count)
|
|
end
|
|
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
|
|
{
|
|
"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
|
|
{
|
|
"albums" => galleries,
|
|
"extras" => {"widget-title"=>"Gallery"},
|
|
"total_pages" => albums.total_pages
|
|
}
|
|
end
|
|
|
|
def show
|
|
params = OrbitHelper.params
|
|
album = Album.find_by_param(params[:uid])
|
|
images = album.album_images.collect do |a|
|
|
{
|
|
"image-description" => a.description,
|
|
"link_to_show" => "/" + I18n.locale.to_s + params[:url] + "/-" + a.id.to_s + "?method=theater",
|
|
"thumb-src" => a.file.thumb.url
|
|
}
|
|
end
|
|
{
|
|
"images" => images,
|
|
"data" => {"album-title"=>album.name}
|
|
}
|
|
end
|
|
|
|
def widget
|
|
albums = Album.filter_by_widget_categories
|
|
params = OrbitHelper.params
|
|
counts = OrbitHelper.widget_data_count
|
|
|
|
images = []
|
|
total_images = 0
|
|
if !albums.blank?
|
|
albums.each do |album|
|
|
total_images = total_images + album.album_images.count
|
|
end
|
|
total_images = counts > 9 ? 9 : counts
|
|
while images.count < counts and images.count < AlbumImage.count
|
|
albums.each do |album|
|
|
img = album.album_images.sample
|
|
if !images.include?(img) && img != nil
|
|
images << img
|
|
end
|
|
end
|
|
end
|
|
end
|
|
images = images.collect do |a|
|
|
{
|
|
"link_to_show" => OrbitHelper.widget_more_url + "/-" + a.id.to_s + "?method=theater",
|
|
"thumb-src" => a.file.thumb.url
|
|
}
|
|
end
|
|
{
|
|
"images" => images,
|
|
"extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url}
|
|
}
|
|
end
|
|
|
|
def imgs(album_id)
|
|
album = Album.find(album_id)
|
|
tag_names = Array.new
|
|
images = album.album_images.all
|
|
output = Array.new
|
|
images.each do |values|
|
|
output << { _id: values.id.to_s,
|
|
description: values.description,
|
|
title: values.title,
|
|
file: values.file.as_json[:file],
|
|
gallery_album_id: values.album_id,
|
|
tags: values.tags}
|
|
end
|
|
return output
|
|
end
|
|
|
|
def theater
|
|
params = OrbitHelper.params
|
|
image = AlbumImage.find(params[:uid])
|
|
albumid = image.album_id
|
|
album = Album.find(albumid)
|
|
images = album.album_images.all
|
|
{
|
|
"album" => album,
|
|
"images" => images,
|
|
"image" => image,
|
|
"wall_images" => imgs(albumid),
|
|
"back_to_albums" => OrbitHelper.url_to_show(album.to_param)
|
|
}
|
|
end
|
|
end |