Update galleries_controller.rb

merge change with eric's
This commit is contained in:
chiu 2019-11-05 21:31:11 +08:00
parent bf0f561c2e
commit 3925c22408
1 changed files with 54 additions and 61 deletions

View File

@ -17,53 +17,49 @@ class GalleriesController < ApplicationController
tags << tag0
tags << tag1
end
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
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
{
"albums" => galleries,
"extras" => {"widget-title"=>"Gallery"},
"total_pages" => albums.total_pages
}
}
end
def show
params = OrbitHelper.params
album = Album.find_by_param(params[:uid])
flag = show_desc?
images = album.album_images.asc(:order).collect do |a|
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,
"album-description" => (flag ? "<p><span>#{album.description}</span></p>" : "")}
}
"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>" : "")}
}
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?
@ -76,7 +72,7 @@ class GalleriesController < ApplicationController
while images.count < counts
albums.each do |album|
img = album.album_images.sample
if !images.include?(img) && img != nil
if !images.include?(img) && img != nil
images << img
end
end
@ -84,7 +80,6 @@ class GalleriesController < ApplicationController
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,
@ -93,61 +88,59 @@ class GalleriesController < ApplicationController
"thumb-large-src" => a.file.thumb_large.url,
"image_description" => a.description,
"mobile-src" => a.file.mobile.url,
"theater-src" => a.file.theater.url
"theater-src" => a.file.theater.url,
"album-name" => a.album.name_translations[I18n.locale]
}
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,
url: values.file.url,
file: values.file.as_json[:file],
gallery_album_id: values.album_id,
tags: values.tags}
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}
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 = {
data = {
"album" => album,
"image" => image.id.to_s,
"images" => imgs(albumid)
}
render :json => {"data" => data}.to_json
}
render :json => {"data" => data}.to_json
end
private
def show_desc?
tags = OrbitHelper.page_tags if tags.blank?
tags = [tags].flatten.uniq
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')
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')
flag = true
elsif value.name==I18n.t('gallery.not_show_desc')
flag = false
end
end
flag
elsif value.name==I18n.t('gallery.not_show_desc')
flag = false
end
end
flag
end
end