2014-05-05 06:07:18 +00:00
|
|
|
class GalleriesController < ApplicationController
|
2021-04-04 05:03:24 +00:00
|
|
|
|
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
|
2019-11-12 12:18:17 +00:00
|
|
|
elsif find_tag.length>1
|
|
|
|
show_tags = Tag.all.select{|value| value.name==I18n.t('gallery.show_desc')}
|
|
|
|
show_tags.each_with_index do |show_tag,index1|
|
|
|
|
if index1>0
|
|
|
|
if show_tag.taggings.count==0
|
|
|
|
show_tag.delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
find_tag.each_with_index do |not_show_tag,index1|
|
|
|
|
if index1>0
|
|
|
|
if not_show_tag.taggings.count==0
|
|
|
|
not_show_tag.delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 14:24:14 +00:00
|
|
|
end
|
2019-11-05 06:07:59 +00:00
|
|
|
|
2019-11-05 13:31:11 +00:00
|
|
|
def index
|
2021-04-04 05:03:24 +00:00
|
|
|
@album_setting = AlbumSetting.first
|
2020-09-25 15:22:28 +00:00
|
|
|
params = OrbitHelper.params
|
2020-01-19 03:27:55 +00:00
|
|
|
album_tp = Album.filter_by_categories.filter_by_tags
|
2020-09-25 15:22:28 +00:00
|
|
|
all_count = album_tp.count
|
|
|
|
page_data_count = OrbitHelper.page_data_count
|
|
|
|
no_order_count = album_tp.where(:order.in=>[-1,nil]).count
|
|
|
|
with_order_count = all_count - no_order_count
|
|
|
|
with_order_total_pages = (with_order_count.to_f / page_data_count).ceil
|
|
|
|
albums_with_order = album_tp.asc(:order).where(:order.ne=>-1).and(:order.ne=>nil).to_a rescue []
|
|
|
|
page_no = (params[:page_no] || 1).to_i
|
|
|
|
if page_no < with_order_total_pages
|
|
|
|
albums_no_order = []
|
|
|
|
elsif page_no == with_order_total_pages
|
|
|
|
if albums_with_order.count == page_data_count
|
|
|
|
albums_no_order = []
|
|
|
|
else
|
2020-10-30 00:19:46 +00:00
|
|
|
albums_no_order = album_tp.desc(:created_at).where(:order.in=>[-1,nil]).page(nil).per(all_count)[0...(page_data_count - albums_with_order.count)]
|
2020-09-25 15:22:28 +00:00
|
|
|
end
|
|
|
|
else
|
2021-05-18 02:33:40 +00:00
|
|
|
albums_with_order = []
|
2020-09-25 15:22:28 +00:00
|
|
|
start_index = (page_data_count - (with_order_count % page_data_count) + page_data_count*(page_no - 1 - with_order_total_pages))
|
|
|
|
albums_no_order = album_tp.desc(:created_at).where(:order.in=>[-1,nil]).page(nil).per(all_count)[start_index...(start_index+page_data_count)].to_a
|
|
|
|
end
|
|
|
|
albums = albums_with_order.concat(albums_no_order)
|
2021-04-04 05:03:24 +00:00
|
|
|
album_color_map = AlbumColor.where(:album_id.in=> albums.map{|v| v.id}).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h
|
2019-11-05 13:31:11 +00:00
|
|
|
galleries = albums.collect do |a|
|
|
|
|
doc = Nokogiri::HTML(a.description.to_s)
|
|
|
|
alt_text = doc.text.empty? ? 'gallery image' : doc.text
|
2021-04-04 05:03:24 +00:00
|
|
|
colors = album_color_map[a.id]
|
2019-11-05 13:31:11 +00:00
|
|
|
{
|
|
|
|
"album-name" => a.name,
|
|
|
|
"album-description" => a.description,
|
|
|
|
"alt_title" => alt_text,
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
2021-04-04 05:03:24 +00:00
|
|
|
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg",
|
|
|
|
"album_color" => iterate_data(colors[1],colors[0],@album_setting.album_card_background_color,'transparent'),
|
|
|
|
"album_card_text_color" => iterate_data(colors[2],@album_setting.album_card_text_color)
|
2019-11-05 13:31:11 +00:00
|
|
|
}
|
|
|
|
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"},
|
2020-01-19 03:27:55 +00:00
|
|
|
"total_pages" => album_tp.total_pages
|
2019-11-05 13:31:11 +00:00
|
|
|
}
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
def show
|
2021-04-04 05:03:24 +00:00
|
|
|
@album_setting = AlbumSetting.first
|
2014-05-05 06:07:18 +00:00
|
|
|
params = OrbitHelper.params
|
|
|
|
album = Album.find_by_param(params[:uid])
|
2019-09-30 14:24:14 +00:00
|
|
|
flag = show_desc?
|
2021-04-04 05:03:24 +00:00
|
|
|
colors = AlbumColor.where(:album_id=> album.id).pluck(:color,:album_card_background_color,:album_card_text_color)[0] rescue []
|
2019-11-05 13:31:11 +00:00
|
|
|
images = album.album_images.asc(:order).collect do |a|
|
2021-04-04 05:03:24 +00:00
|
|
|
alt_text = (a.description.blank? ? "gallery image" : Nokogiri::HTML(a.description.to_s).text())
|
2019-11-05 13:31:11 +00:00
|
|
|
{
|
2020-02-28 01:21:35 +00:00
|
|
|
"image-description" => (flag ? a.description : ''),
|
2021-04-04 05:03:24 +00:00
|
|
|
"image_short_description" => a.title,
|
2015-05-28 09:48:35 +00:00
|
|
|
"alt_title" => alt_text,
|
2020-03-27 08:50:29 +00:00
|
|
|
"link_to_show" => "#" + a.id.to_s,
|
2021-04-04 05:03:24 +00:00
|
|
|
"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,
|
|
|
|
|
|
|
|
"album_color" => iterate_data(colors[1],colors[0],@album_setting.album_card_background_color,'transparent'),
|
|
|
|
"album_card_text_color" => iterate_data(colors[2],@album_setting.album_card_text_color)
|
2019-11-05 13:31:11 +00:00
|
|
|
}
|
|
|
|
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
|
2021-04-04 05:03:24 +00:00
|
|
|
def iterate_data(*args)
|
|
|
|
tmp = nil
|
|
|
|
args.each do |arg|
|
|
|
|
if !arg.blank? && arg != 'transparent'
|
|
|
|
tmp = arg
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tmp
|
|
|
|
end
|
2021-05-18 01:45:52 +00:00
|
|
|
def album_widget
|
|
|
|
@album_setting = AlbumSetting.first
|
|
|
|
params = OrbitHelper.params
|
|
|
|
tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags
|
|
|
|
album_tp = Album.filter_by_widget_categories(OrbitHelper.widget_categories,false).filter_by_tags(tags)
|
|
|
|
all_count = album_tp.count
|
|
|
|
page_data_count = OrbitHelper.widget_data_count
|
|
|
|
no_order_count = album_tp.where(:order.in=>[-1,nil]).count
|
|
|
|
with_order_count = all_count - no_order_count
|
|
|
|
with_order_total_pages = (with_order_count.to_f / page_data_count).ceil
|
|
|
|
albums_with_order = album_tp.asc(:order).where(:order.ne=>-1).and(:order.ne=>nil).to_a rescue []
|
|
|
|
page_no = (params[:page_no] || 1).to_i
|
|
|
|
if page_no < with_order_total_pages
|
|
|
|
albums_no_order = []
|
2021-05-18 02:33:40 +00:00
|
|
|
albums_with_order = albums_with_order[(page_no-1)*page_data_count...page_no*page_data_count]
|
2021-05-18 01:45:52 +00:00
|
|
|
elsif page_no == with_order_total_pages
|
|
|
|
if albums_with_order.count == page_data_count
|
|
|
|
albums_no_order = []
|
|
|
|
else
|
|
|
|
albums_no_order = album_tp.desc(:created_at).where(:order.in=>[-1,nil]).page(nil).per(all_count)[0...(page_data_count - albums_with_order.count)]
|
|
|
|
end
|
|
|
|
else
|
2021-05-18 02:33:40 +00:00
|
|
|
albums_with_order = []
|
2021-05-18 01:45:52 +00:00
|
|
|
start_index = (page_data_count - (with_order_count % page_data_count) + page_data_count*(page_no - 1 - with_order_total_pages))
|
|
|
|
albums_no_order = album_tp.desc(:created_at).where(:order.in=>[-1,nil]).page(nil).per(all_count)[start_index...(start_index+page_data_count)].to_a
|
|
|
|
end
|
|
|
|
albums = albums_with_order.concat(albums_no_order)
|
|
|
|
album_color_map = AlbumColor.where(:album_id.in=> albums.map{|v| v.id}).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h
|
|
|
|
galleries = albums.collect.with_index do |a,i|
|
|
|
|
doc = Nokogiri::HTML(a.description.to_s)
|
2021-05-20 03:25:16 +00:00
|
|
|
alt_text = doc.text.empty? ? 'gallery image' : doc.text.strip
|
2021-05-18 01:45:52 +00:00
|
|
|
colors = album_color_map[a.id]
|
|
|
|
thumb_src = a.cover_path || "/assets/gallery/default.jpg"
|
|
|
|
cover_image = AlbumImage.find(a.cover) rescue a.album_images.first
|
|
|
|
image_description = a.description
|
|
|
|
image_short_description = a.name
|
|
|
|
{
|
2021-05-20 03:25:16 +00:00
|
|
|
"link_text" => a.name,
|
2021-05-18 01:45:52 +00:00
|
|
|
"album-name" => a.name,
|
|
|
|
"album-description" => a.description,
|
|
|
|
"alt_title" => alt_text,
|
2021-05-24 07:40:26 +00:00
|
|
|
"link_to_show" => OrbitHelper.widget_more_url + "/" + a.to_param,
|
2021-05-18 01:45:52 +00:00
|
|
|
"src" => thumb_src.gsub("thumb_",""),
|
|
|
|
"thumb-src" => thumb_src,
|
|
|
|
"thumb-large-src" => thumb_src.gsub("thumb_","thumb_large_"),
|
|
|
|
"mobile-src" => thumb_src.gsub("thumb_","mobile_"),
|
|
|
|
"theater-src" => thumb_src.gsub("thumb_","theater_"),
|
|
|
|
"image_description" => image_description,
|
|
|
|
"image_short_description" => image_short_description,
|
|
|
|
"album_color" => iterate_data(colors[1],colors[0],@album_setting.album_card_background_color,'transparent'),
|
|
|
|
"album_card_text_color" => iterate_data(colors[2],@album_setting.album_card_text_color),
|
|
|
|
"i" => i
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"images" => galleries,
|
|
|
|
"extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url}
|
|
|
|
}
|
|
|
|
end
|
2014-05-23 06:04:26 +00:00
|
|
|
def widget
|
2021-04-04 05:03:24 +00:00
|
|
|
@album_setting = AlbumSetting.first
|
2016-01-15 08:01:39 +00:00
|
|
|
tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags
|
2020-06-05 15:50:09 +00:00
|
|
|
album_ids = Album.filter_by_widget_categories(OrbitHelper.widget_categories,false).filter_by_tags(tags).pluck(:id)
|
2021-04-04 05:03:24 +00:00
|
|
|
album_color_map = AlbumColor.where(:album_id.in=> album_ids).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h
|
2014-05-23 06:04:26 +00:00
|
|
|
params = OrbitHelper.params
|
2015-02-06 09:04:39 +00:00
|
|
|
counts = OrbitHelper.widget_data_count
|
2020-03-15 04:54:44 +00:00
|
|
|
images = AlbumImage.where({album_id:{"$in"=>album_ids}}).desc(:id).limit(counts *5).sample(counts)
|
2021-04-10 12:53:00 +00:00
|
|
|
images = images.each_with_index.collect do |a,i|
|
2021-04-04 05:03:24 +00:00
|
|
|
colors = album_color_map[a.album_id]
|
2021-05-20 03:25:16 +00:00
|
|
|
alt_text = (a.description.blank? ? "gallery image" : Nokogiri::HTML(a.description).text().strip)
|
2014-05-23 06:04:26 +00:00
|
|
|
{
|
2021-05-20 03:25:16 +00:00
|
|
|
"link_text" => "",
|
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,
|
2021-04-04 05:03:24 +00:00
|
|
|
"image_short_description" => a.title,
|
2015-10-07 10:09:08 +00:00
|
|
|
"mobile-src" => a.file.mobile.url,
|
2019-11-05 13:31:11 +00:00
|
|
|
"theater-src" => a.file.theater.url,
|
2021-04-04 05:03:24 +00:00
|
|
|
"album-name" => a.album.name_translations[I18n.locale],
|
|
|
|
"album_color" => iterate_data(colors[1],colors[0],@album_setting.album_card_background_color,'transparent'),
|
2021-04-10 12:53:00 +00:00
|
|
|
"album_card_text_color" => iterate_data(colors[2],@album_setting.album_card_text_color),
|
|
|
|
"i" => i
|
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 13:31:11 +00:00
|
|
|
}
|
2014-05-23 06:04:26 +00:00
|
|
|
end
|
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 13:31:11 +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
|
2021-04-04 05:03:24 +00:00
|
|
|
if params[:id].include?('page=')
|
|
|
|
album = Album.where(uid: params[:id].sub('page=','')).first
|
|
|
|
albumid = album.id
|
|
|
|
image = album.album_images.first
|
|
|
|
else
|
|
|
|
image = AlbumImage.find(params[:id])
|
|
|
|
albumid = image.album_id
|
|
|
|
album = Album.find(albumid)
|
|
|
|
end
|
2015-04-16 12:07:54 +00:00
|
|
|
images = album.album_images.asc(:order)
|
2019-11-05 13:31:11 +00:00
|
|
|
data = {
|
2015-07-16 11:27:14 +00:00
|
|
|
"album" => album,
|
|
|
|
"image" => image.id.to_s,
|
|
|
|
"images" => imgs(albumid)
|
2019-11-05 13:31:11 +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
|
|
|
|
2019-11-05 13:31:11 +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 13:31:11 +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 13:31:11 +00:00
|
|
|
flag
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|