fix error

This commit is contained in:
邱博亞 2023-02-18 21:53:48 +08:00
parent 16ff105bc7
commit a192a000c5
1 changed files with 45 additions and 28 deletions

View File

@ -36,35 +36,12 @@ class GalleriesController < ApplicationController
end
def index
page = OrbitHelper.page
set_image_version
@album_setting = AlbumSetting.first
page_no = OrbitHelper.page_number
data_count = OrbitHelper.page_data_count
albums = Album.filter_by_categories.filter_by_tags.asc(:order).page(page_no).per(data_count)
album_color_map = AlbumColor.where(:album_id.in=> albums.pluck(:id)).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h
@image_version = 'thumb'
ModuleApp.all.select{|tmp| tmp.key.to_s=='gallery'}.each do |modile_app|
@show_option_items = modile_app.show_option_items rescue nil
end
if !(@show_option_items.nil?)
I18n.with_locale(:en) do
page.select_option_items.each do |select_option_item|
case select_option_item.field_name
when @show_option_items.keys[1].to_s
value = YAML.load(select_option_item.value)
tmp = value[:en]
if tmp == t('gallery.small_size')
@image_version = 'thumb'
elsif tmp == t('gallery.medium_size')
@image_version = 'thumb_large'
elsif tmp == t('gallery.large_size')
@image_version = 'mobile'
end
end
end
end
end
galleries = albums.collect do |a|
doc = Nokogiri::HTML(a.description.to_s)
alt_text = doc.text.empty? ? 'gallery image' : doc.text
@ -103,12 +80,26 @@ class GalleriesController < ApplicationController
}
end
def show
set_image_version
@album_setting = AlbumSetting.first
params = OrbitHelper.params
album = Album.find_by_param(params[:uid].to_s)
flag = show_desc?
colors = (AlbumColor.where(:album_id=> album.id).pluck(:color,:album_card_background_color,:album_card_text_color)[0])||[] rescue []
images = album.album_images.asc(:order).collect do |a|
src = a.file.url
thumb_large_src = a.file.thumb_large.url
mobile_src = a.file.mobile.url
theater_src = a.file.theater.url
case @image_version
when 'thumb'
thumb_src = a.file.thumb.url
when 'thumb_large'
thumb_src = thumb_large_src
when 'mobile'
thumb_src = mobile_src
end
alt_text = (a.description.blank? ? "gallery image" : Nokogiri::HTML(a.description.to_s).text())
{
"image-description" => (flag ? a.description : ''),
@ -116,10 +107,10 @@ class GalleriesController < ApplicationController
"alt_title" => alt_text,
"link_to_show" => "#" + a.id.to_s,
"src" => a.file.url,
"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,
"thumb-src" => thumb_src,
"thumb-large-src" => thumb_large_src,
"mobile-src" => mobile_src,
"theater-src" => theater_src,
"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)
@ -272,4 +263,30 @@ class GalleriesController < ApplicationController
end
flag
end
def set_image_version
page = OrbitHelper.page
@image_version = 'thumb'
ModuleApp.all.select{|tmp| tmp.key.to_s=='gallery'}.each do |modile_app|
@show_option_items = modile_app.show_option_items rescue nil
end
if !(@show_option_items.nil?)
I18n.with_locale(:en) do
page.select_option_items.each do |select_option_item|
case select_option_item.field_name
when @show_option_items.keys[1].to_s
value = YAML.load(select_option_item.value)
tmp = value[:en]
if tmp == t('gallery.small_size')
@image_version = 'thumb'
elsif tmp == t('gallery.medium_size')
@image_version = 'thumb_large'
elsif tmp == t('gallery.large_size')
@image_version = 'mobile'
end
end
end
end
end
end
end