2014-05-05 06:07:18 +00:00
|
|
|
class GalleriesController < ApplicationController
|
2019-09-30 14:24:14 +00:00
|
|
|
find_tag = Tag.all.select{|value| value.name==I18n.t('gallery.not_show_desc')}
|
|
|
|
if find_tag.length==0
|
|
|
|
module_app_id = ModuleApp.where(:key=>"gallery").first[:_id]
|
|
|
|
tags = ModuleApp.where(:key=>"gallery").first.tags
|
|
|
|
tag0 = Tag.new(is_default: false,module_app_ids: [module_app_id])
|
|
|
|
tag1 = Tag.new(is_default: false,module_app_ids: [module_app_id])
|
|
|
|
nowlocale = I18n.locale
|
|
|
|
I18n.available_locales.each do |locale|
|
|
|
|
I18n.locale = locale
|
|
|
|
tag0.name = I18n.t('gallery.show_desc')
|
|
|
|
tag1.name = I18n.t('gallery.not_show_desc')
|
|
|
|
end
|
|
|
|
I18n.locale = nowlocale
|
|
|
|
tag0.save
|
|
|
|
tag1.save
|
|
|
|
tags << tag0
|
|
|
|
tags << tag1
|
|
|
|
end
|
2019-11-05 06:07:59 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
albums = Album.filter_by_categories.filter_by_tags.asc(:order)
|
|
|
|
galleries = albums.collect do |a|
|
|
|
|
doc = Nokogiri::HTML(a.description.to_s)
|
|
|
|
alt_text = doc.text.empty? ? 'gallery image' : doc.text
|
|
|
|
{
|
|
|
|
"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
|
2014-05-05 06:07:18 +00:00
|
|
|
{
|
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
|
2019-11-05 06:07:59 +00:00
|
|
|
}
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
album = Album.find_by_param(params[:uid])
|
2019-09-30 14:24:14 +00:00
|
|
|
flag = show_desc?
|
2019-11-05 06:07:59 +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)
|
2019-11-05 06:07:59 +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,
|
2019-11-05 06:07:59 +00:00
|
|
|
"link_to_show" => "/xhr/galleries/theater/" + a.id.to_s,
|
|
|
|
"thumb-src" => a.file.thumb.url
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"images" => images,
|
|
|
|
"data" => {"album-title"=>album.name,
|
|
|
|
"album-description" => (flag ? "<p><span>#{album.description}</span></p>" : "")}
|
|
|
|
}
|
2014-05-23 06:04:26 +00:00
|
|
|
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
|
2019-11-05 06:07:59 +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
|
2019-11-05 06:07:59 +00:00
|
|
|
if !images.include?(img) && img != nil
|
2014-06-04 08:21:15 +00:00
|
|
|
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,
|
2019-09-25 06:53:46 +00:00
|
|
|
"src" => a.file.url,
|
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,
|
2016-12-20 11:43:54 +00:00
|
|
|
"image_description" => a.description,
|
2015-10-07 10:09:08 +00:00
|
|
|
"mobile-src" => a.file.mobile.url,
|
2019-11-05 06:53:13 +00:00
|
|
|
"theater-src" => a.file.theater.url,
|
|
|
|
"album-name" => a.album.name_translations[I18n.locale]
|
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}
|
2019-11-05 06:07:59 +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|
|
2019-11-05 06:07:59 +00:00
|
|
|
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,
|
|
|
|
url: values.file.url,
|
|
|
|
file: values.file.as_json[:file],
|
|
|
|
gallery_album_id: values.album_id,
|
|
|
|
tags: values.tags}
|
2014-10-20 12:25:58 +00:00
|
|
|
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)
|
2019-11-05 06:07:59 +00:00
|
|
|
data = {
|
2015-07-16 11:27:14 +00:00
|
|
|
"album" => album,
|
|
|
|
"image" => image.id.to_s,
|
|
|
|
"images" => imgs(albumid)
|
2019-11-05 06:07:59 +00:00
|
|
|
}
|
|
|
|
render :json => {"data" => data}.to_json
|
2019-09-30 14:24:14 +00:00
|
|
|
end
|
2019-11-05 06:07:59 +00:00
|
|
|
|
2019-09-30 14:24:14 +00:00
|
|
|
private
|
2019-11-05 06:07:59 +00:00
|
|
|
|
|
|
|
def show_desc?
|
|
|
|
tags = OrbitHelper.page_tags if tags.blank?
|
|
|
|
tags = [tags].flatten.uniq
|
|
|
|
flag = true
|
|
|
|
tag_temp = Tag.all.select{|value| tags.include? value.id.to_s}
|
|
|
|
tag_temp_length = 0
|
|
|
|
tag_temp.each do |value|
|
|
|
|
if value.name==I18n.t('gallery.show_desc')
|
2019-09-30 14:24:14 +00:00
|
|
|
flag = true
|
2019-11-05 06:07:59 +00:00
|
|
|
elsif value.name==I18n.t('gallery.not_show_desc')
|
|
|
|
flag = false
|
|
|
|
end
|
2019-09-30 14:24:14 +00:00
|
|
|
end
|
2019-11-05 06:07:59 +00:00
|
|
|
flag
|
|
|
|
end
|
|
|
|
end
|