gallery/app/controllers/galleries_controller.rb

115 lines
3.5 KiB
Ruby

class GalleriesController < ApplicationController
def index
albums = Album.filter_by_categories.filter_by_tags.asc(:order)
galleries = albums.collect do |a|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
{
"album-name" => a.name,
"album-description" => a.description,
"alt_title" => alt_text,
"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.asc(:order).collect do |a|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
{
"image-description" => a.description,
"alt_title" => alt_text,
"link_to_show" => "/xhr/galleries/theater/" + a.id.to_s,
"thumb-src" => a.file.thumb.url
}
end
{
"images" => images,
"data" => {"album-title"=>album.name}
}
end
def widget
tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags
albums = Album.filter_by_widget_categories.filter_by_tags(tags)
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
counts = counts > total_images ? total_images : counts
abc = AlbumImage.count
counts = counts > abc ? abc : counts
while images.count < counts
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|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
{
"link_to_show" => OrbitHelper.widget_more_url + "/" + a.album.to_param + "#" + a.id.to_s,
"alt_title" => alt_text,
"thumb-src" => a.file.thumb.url,
"thumb-large-src" => a.file.thumb_large.url,
"mobile-src" => a.file.mobile.url,
"theater-src" => a.file.theater.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.asc(:order)
output = Array.new
images.each do |values|
alt_text = (values.description.nil? || values.description == "" ? "gallery image" : values.description)
output << { _id: values.id.to_s,
description: values.description,
title: values.title,
alt_title: alt_text,
file: values.file.as_json[:file],
gallery_album_id: values.album_id,
tags: values.tags}
end
return output
end
def theater
image = AlbumImage.find(params[:id])
albumid = image.album_id
album = Album.find(albumid)
images = album.album_images.asc(:order)
data = {
"album" => album,
# "images" => images,
"image" => image.id.to_s,
"images" => imgs(albumid)
}
render :json => {"data" => data}.to_json
end
end