2014-05-05 06:07:18 +00:00
|
|
|
class GalleriesController < ApplicationController
|
|
|
|
def index
|
2016-01-15 08:01:39 +00:00
|
|
|
albums = Album.filter_by_categories.filter_by_tags.asc(:order)
|
2014-06-18 11:56:12 +00:00
|
|
|
galleries = albums.collect do |a|
|
2015-05-28 09:48:35 +00:00
|
|
|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
|
2014-05-05 06:07:18 +00:00
|
|
|
{
|
|
|
|
"album-name" => a.name,
|
2014-06-09 09:56:14 +00:00
|
|
|
"album-description" => a.description,
|
2015-05-28 09:48:35 +00:00
|
|
|
"alt_title" => alt_text,
|
2014-05-05 06:07:18 +00:00
|
|
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
|
|
|
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
2014-06-18 11:56:12 +00:00
|
|
|
"albums" => galleries,
|
2014-06-18 10:17:32 +00:00
|
|
|
"extras" => {"widget-title"=>"Gallery"},
|
|
|
|
"total_pages" => albums.total_pages
|
2014-05-05 06:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
album = Album.find_by_param(params[:uid])
|
2015-04-16 12:07:54 +00:00
|
|
|
images = album.album_images.asc(:order).collect do |a|
|
2015-05-28 09:48:35 +00:00
|
|
|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
|
2014-05-05 06:07:18 +00:00
|
|
|
{
|
2014-06-09 09:56:14 +00:00
|
|
|
"image-description" => a.description,
|
2015-05-28 09:48:35 +00:00
|
|
|
"alt_title" => alt_text,
|
2015-07-16 11:27:14 +00:00
|
|
|
"link_to_show" => "/xhr/galleries/theater/" + a.id.to_s,
|
2014-05-23 06:04:26 +00:00
|
|
|
"thumb-src" => a.file.thumb.url
|
2014-05-05 06:07:18 +00:00
|
|
|
}
|
2014-05-23 06:04:26 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"images" => images,
|
|
|
|
"data" => {"album-title"=>album.name}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget
|
2016-01-15 08:01:39 +00:00
|
|
|
tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags
|
|
|
|
albums = Album.filter_by_widget_categories.filter_by_tags(tags)
|
2014-05-23 06:04:26 +00:00
|
|
|
params = OrbitHelper.params
|
2015-02-06 09:04:39 +00:00
|
|
|
counts = OrbitHelper.widget_data_count
|
2014-05-26 02:08:14 +00:00
|
|
|
|
2014-05-23 06:04:26 +00:00
|
|
|
images = []
|
2014-06-17 08:39:39 +00:00
|
|
|
total_images = 0
|
2014-06-04 08:21:15 +00:00
|
|
|
if !albums.blank?
|
2014-06-17 08:39:39 +00:00
|
|
|
albums.each do |album|
|
|
|
|
total_images = total_images + album.album_images.count
|
|
|
|
end
|
2015-05-25 13:45:08 +00:00
|
|
|
counts = counts > total_images ? total_images : counts
|
|
|
|
abc = AlbumImage.count
|
|
|
|
counts = counts > abc ? abc : counts
|
|
|
|
while images.count < counts
|
2014-06-04 08:21:15 +00:00
|
|
|
albums.each do |album|
|
|
|
|
img = album.album_images.sample
|
|
|
|
if !images.include?(img) && img != nil
|
|
|
|
images << img
|
|
|
|
end
|
2014-05-23 06:04:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
images = images.collect do |a|
|
2015-05-28 09:48:35 +00:00
|
|
|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
|
|
|
|
|
2014-05-23 06:04:26 +00:00
|
|
|
{
|
2015-07-16 11:27:14 +00:00
|
|
|
"link_to_show" => OrbitHelper.widget_more_url + "/" + a.album.to_param + "#" + a.id.to_s,
|
2015-05-28 09:48:35 +00:00
|
|
|
"alt_title" => alt_text,
|
2015-10-07 10:09:08 +00:00
|
|
|
"thumb-src" => a.file.thumb.url,
|
2015-10-23 06:50:07 +00:00
|
|
|
"thumb-large-src" => a.file.thumb_large.url,
|
2015-10-07 10:09:08 +00:00
|
|
|
"mobile-src" => a.file.mobile.url,
|
|
|
|
"theater-src" => a.file.theater.url
|
2014-05-23 06:04:26 +00:00
|
|
|
}
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
{
|
|
|
|
"images" => images,
|
2014-05-24 11:38:25 +00:00
|
|
|
"extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url}
|
2014-05-05 06:07:18 +00:00
|
|
|
}
|
2014-05-23 06:04:26 +00:00
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
|
2014-10-20 12:25:58 +00:00
|
|
|
def imgs(album_id)
|
|
|
|
album = Album.find(album_id)
|
|
|
|
tag_names = Array.new
|
2015-04-16 12:07:54 +00:00
|
|
|
images = album.album_images.asc(:order)
|
2014-10-20 12:25:58 +00:00
|
|
|
output = Array.new
|
|
|
|
images.each do |values|
|
2015-05-28 09:48:35 +00:00
|
|
|
alt_text = (values.description.nil? || values.description == "" ? "gallery image" : values.description)
|
2014-10-20 12:25:58 +00:00
|
|
|
output << { _id: values.id.to_s,
|
|
|
|
description: values.description,
|
|
|
|
title: values.title,
|
2015-05-28 09:48:35 +00:00
|
|
|
alt_title: alt_text,
|
2014-10-20 12:25:58 +00:00
|
|
|
file: values.file.as_json[:file],
|
|
|
|
gallery_album_id: values.album_id,
|
|
|
|
tags: values.tags}
|
|
|
|
end
|
|
|
|
return output
|
|
|
|
end
|
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
def theater
|
2015-07-16 11:27:14 +00:00
|
|
|
image = AlbumImage.find(params[:id])
|
2014-05-05 06:07:18 +00:00
|
|
|
albumid = image.album_id
|
|
|
|
album = Album.find(albumid)
|
2015-04-16 12:07:54 +00:00
|
|
|
images = album.album_images.asc(:order)
|
2015-07-16 11:27:14 +00:00
|
|
|
data = {
|
|
|
|
"album" => album,
|
|
|
|
# "images" => images,
|
|
|
|
"image" => image.id.to_s,
|
|
|
|
"images" => imgs(albumid)
|
|
|
|
}
|
|
|
|
|
|
|
|
render :json => {"data" => data}.to_json
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
2015-10-23 06:50:07 +00:00
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|