2016-12-20 11:43:54 +00:00
|
|
|
require 'rubyXL'
|
2014-07-31 09:12:57 +00:00
|
|
|
class Admin::GalleriesController < OrbitAdminController
|
2016-12-20 11:43:54 +00:00
|
|
|
include Admin::GalleriesHelper
|
2019-09-25 06:53:46 +00:00
|
|
|
before_filter :setup_vars
|
2014-10-20 11:46:03 +00:00
|
|
|
before_action :authenticate_user, :except => "imgs"
|
|
|
|
before_action :log_user_action
|
2020-02-04 08:18:36 +00:00
|
|
|
layout :compute_layout
|
2019-09-30 14:24:14 +00:00
|
|
|
find_tag = Tag.all.select{|value| value.name==I18n.t('gallery.not_show_desc')}
|
2022-10-20 01:55:10 +00:00
|
|
|
RackTempMiddleExist = defined?(Rack::TempfileReaper)
|
2023-08-15 13:39:42 +00:00
|
|
|
RACK_TEMPFILES = defined?(Rack::RACK_TEMPFILES) ? Rack::RACK_TEMPFILES : 'rack.tempfiles'
|
|
|
|
Is_Rails5 = (Rails.version.to_f >= 5)
|
2019-11-12 12:20:40 +00:00
|
|
|
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
|
|
|
|
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
|
2019-09-30 14:24:14 +00:00
|
|
|
end
|
|
|
|
end
|
2019-11-12 12:20:40 +00:00
|
|
|
end
|
2023-08-15 13:39:42 +00:00
|
|
|
if RackTempMiddleExist # Avoid Rack::TempfileReaper Middleware to unlink temp files automatically.
|
|
|
|
if Is_Rails5
|
|
|
|
def fix_tempfile_reaper
|
|
|
|
request.set_header(RACK_TEMPFILES, [])
|
|
|
|
end
|
|
|
|
else
|
|
|
|
def fix_tempfile_reaper
|
|
|
|
env[RACK_TEMPFILES] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
def fix_tempfile_reaper #do nothing for old rack
|
|
|
|
end
|
|
|
|
end
|
2020-02-04 08:18:36 +00:00
|
|
|
def compute_layout
|
|
|
|
if action_name== 'index' && !params['page_no'].nil?
|
|
|
|
false
|
|
|
|
else
|
|
|
|
'back_end'
|
|
|
|
end
|
|
|
|
end
|
2020-03-17 09:25:08 +00:00
|
|
|
def get_tag
|
|
|
|
album = Album.find(params['ele_id']) rescue nil
|
|
|
|
if !album.nil?
|
|
|
|
text = album.tags.collect do |tag|
|
|
|
|
"<li class=\"label\"> #{tag.name}</li>"
|
|
|
|
end.join
|
2022-10-04 10:43:24 +00:00
|
|
|
render :plain => text
|
2020-03-17 09:25:08 +00:00
|
|
|
else
|
2022-10-04 10:43:24 +00:00
|
|
|
render :plain => ''
|
2020-03-17 09:25:08 +00:00
|
|
|
end
|
|
|
|
end
|
2020-01-09 16:14:41 +00:00
|
|
|
def rotate_images
|
|
|
|
begin
|
|
|
|
image_ids = params['image_ids'].split(',')
|
2020-04-25 02:48:14 +00:00
|
|
|
count = image_ids.count
|
2020-01-09 16:14:41 +00:00
|
|
|
rot_ang = params[:rotate_angle].to_i
|
2020-04-25 02:48:14 +00:00
|
|
|
variable = AlbumVariable.first
|
|
|
|
if variable.nil?
|
|
|
|
variable = AlbumVariable.new
|
|
|
|
end
|
|
|
|
variable.finish = false
|
|
|
|
variable.save!
|
|
|
|
Thread.new do
|
|
|
|
variable = AlbumVariable.first
|
|
|
|
image_ids.each_with_index do |image_id,index|
|
|
|
|
image = AlbumImage.find(image_id) rescue nil
|
|
|
|
next if image.nil?
|
2020-01-09 16:14:41 +00:00
|
|
|
if !(image.album_crops.first.nil?)
|
|
|
|
w_and_h = image.file.get_w_and_h
|
|
|
|
cords = image.album_crops.map{|v| [[v.crop_x.to_f,v.crop_y.to_f],
|
|
|
|
[v.crop_x.to_f,v.crop_y.to_f+v.crop_h.to_f],
|
|
|
|
[v.crop_w.to_f+v.crop_x.to_f,v.crop_y.to_f],
|
|
|
|
[v.crop_w.to_f+v.crop_x.to_f,v.crop_y.to_f+v.crop_h.to_f]]}[0]
|
|
|
|
rot_diff = rot_ang/90
|
|
|
|
if (rot_diff) % 2 == 1
|
|
|
|
new_w = (w_and_h[1]).to_f
|
|
|
|
new_h = (w_and_h[0]).to_f
|
|
|
|
else
|
|
|
|
new_w = (w_and_h[0]).to_f
|
|
|
|
new_h = (w_and_h[1]).to_f
|
|
|
|
end
|
|
|
|
|
|
|
|
rot_times = rot_diff % 4
|
|
|
|
deg = (90.0*rot_times/180*Math::PI)
|
|
|
|
cords = cords.collect do |cord|
|
|
|
|
x = cord[0]-w_and_h[0].to_f/2
|
|
|
|
y = cord[1]-w_and_h[1].to_f/2
|
|
|
|
[x*Math.cos(deg)-y*Math.sin(deg)+new_w/2,x*Math.sin(deg)+y*Math.cos(deg)+new_h/2]
|
|
|
|
end
|
|
|
|
all_x = cords.collect do |cord|
|
|
|
|
cord[0]
|
|
|
|
end
|
|
|
|
all_y = cords.collect do |cord|
|
|
|
|
cord[1]
|
|
|
|
end
|
|
|
|
image.album_crops.first.update_attributes(crop_x: all_x.min,crop_y: all_y.min,crop_w: all_x.max - all_x.min,crop_h: all_y.max - all_y.min)
|
|
|
|
end
|
|
|
|
variable.progress_percent = (index*100.0/count).floor.to_s+'%'
|
|
|
|
image.file.rotate_ang(rot_ang)
|
|
|
|
all_version = image.file.versions.map{|k,v| k}
|
|
|
|
begin
|
|
|
|
variable.progress_filename = image[:file].to_s
|
|
|
|
all_version.each do |version|
|
2023-04-24 02:44:50 +00:00
|
|
|
if !(version.to_s == 'resized' && crop_but_no_backup(image))
|
|
|
|
image.file.recreate_versions! version
|
|
|
|
image.save!
|
|
|
|
end
|
2020-01-09 16:14:41 +00:00
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
variable.progress_filename = e.inspect.to_s
|
|
|
|
puts e.inspect
|
|
|
|
end
|
|
|
|
variable.save!
|
|
|
|
end
|
|
|
|
variable.finish = true
|
|
|
|
variable.save!
|
2023-04-24 02:44:50 +00:00
|
|
|
end
|
2020-01-09 16:14:41 +00:00
|
|
|
rescue => e
|
2023-04-24 02:44:50 +00:00
|
|
|
puts e.inspect
|
2020-01-09 16:14:41 +00:00
|
|
|
end
|
2024-06-26 15:50:27 +00:00
|
|
|
redirect_to admin_galleries_crop_process_path
|
2020-01-09 16:14:41 +00:00
|
|
|
end
|
2019-11-12 12:20:40 +00:00
|
|
|
|
2019-09-25 06:53:46 +00:00
|
|
|
def save_crop
|
|
|
|
begin
|
2020-04-25 02:48:14 +00:00
|
|
|
images = AlbumImage.where(:id.in => Array(params[:id]))
|
2020-01-09 16:14:41 +00:00
|
|
|
x = params['x']
|
|
|
|
y = params['y']
|
|
|
|
w = params['w']
|
|
|
|
h = params['h']
|
|
|
|
cords = x.zip(y,w,h)
|
|
|
|
count = cords.length
|
2020-03-17 09:47:28 +00:00
|
|
|
variable = AlbumVariable.first
|
|
|
|
if variable.nil?
|
|
|
|
variable = AlbumVariable.new
|
|
|
|
end
|
|
|
|
variable.finish = false
|
|
|
|
variable.save!
|
2020-01-09 16:14:41 +00:00
|
|
|
Thread.new do
|
2020-03-17 09:47:28 +00:00
|
|
|
variable = AlbumVariable.first
|
2023-04-24 02:44:50 +00:00
|
|
|
image_ids= images.pluck(:id)
|
|
|
|
image_ids.each_with_index do |image_id,index|
|
|
|
|
image = AlbumImage.find(image_id)
|
|
|
|
cord = cords[index]
|
|
|
|
if image.album_crops.first.nil?
|
|
|
|
image.album_crops.create(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3])
|
|
|
|
else
|
|
|
|
image.album_crops.first.update_attributes(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3])
|
|
|
|
end
|
|
|
|
variable.progress_percent = (index*100.0/count).floor.to_s+'%'
|
|
|
|
all_version = image.file.versions.map{|k,v| k}
|
|
|
|
begin
|
|
|
|
#org_fname = image.file.path
|
|
|
|
#org_extname = File.extname(org_fname)
|
|
|
|
#org_fname.slice! org_extname
|
|
|
|
#FileUtils.cp(org_fname + org_extname, org_fname + '_resized' + org_extname)
|
|
|
|
variable.progress_filename = image[:file].to_s
|
|
|
|
all_version.each do |version|
|
|
|
|
if !(version.to_s == 'resized' && crop_but_no_backup(image))
|
|
|
|
image.file.recreate_versions! version
|
|
|
|
image.save!
|
2020-03-17 09:47:28 +00:00
|
|
|
end
|
|
|
|
end
|
2023-04-24 02:44:50 +00:00
|
|
|
rescue => e
|
|
|
|
variable.progress_filename = e.inspect.to_s
|
|
|
|
puts e.inspect
|
|
|
|
end
|
|
|
|
variable.save!
|
2020-03-17 09:47:28 +00:00
|
|
|
end
|
|
|
|
variable.finish = true
|
|
|
|
variable.save!
|
2023-04-24 02:44:50 +00:00
|
|
|
end
|
2020-03-17 09:47:28 +00:00
|
|
|
rescue => e
|
2023-04-24 02:44:50 +00:00
|
|
|
puts e.inspect
|
2020-03-17 09:47:28 +00:00
|
|
|
end
|
2024-06-26 15:50:27 +00:00
|
|
|
redirect_url = admin_galleries_crop_process_path
|
2020-03-17 09:47:28 +00:00
|
|
|
render :json => {'href' => redirect_url}.to_json
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
|
|
|
def call_translate
|
|
|
|
text = params['text']
|
|
|
|
render :json => {'translate' => "#{t(text.to_s)}" }.to_json
|
|
|
|
end
|
|
|
|
def recreate_image
|
2019-11-05 13:14:34 +00:00
|
|
|
notalive = ((AlbumVariable.first.notalive.nil? ? true : AlbumVariable.first.notalive) rescue true)
|
2019-09-25 06:53:46 +00:00
|
|
|
if notalive
|
2020-03-17 09:47:28 +00:00
|
|
|
if !params['album_id'].to_s.empty?
|
|
|
|
variable = AlbumVariable.first
|
|
|
|
if variable.nil?
|
|
|
|
variable = AlbumVariable.new
|
|
|
|
end
|
|
|
|
variable.finish = false
|
|
|
|
variable.save!
|
|
|
|
choice_ids = params['album_id'].split(',')
|
2020-04-25 02:48:14 +00:00
|
|
|
albums = Album.where(:id.in => choice_ids)
|
2020-03-17 09:47:28 +00:00
|
|
|
if !(params['use_default']=='true')
|
|
|
|
color = params['color_choice'].to_s.empty? ? 'transparent' : params['color_choice']
|
|
|
|
albums.each do |album|
|
|
|
|
if album.album_colors.first.nil?
|
|
|
|
album.album_colors.create('color' => color)
|
|
|
|
else
|
|
|
|
album.album_colors.first.update_attributes('color' => color, 'updated_at' => Time.now)
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2020-03-17 09:47:28 +00:00
|
|
|
end
|
|
|
|
end
|
2020-04-25 02:48:14 +00:00
|
|
|
count = albums.reduce(0){|x,i| i.album_images.count+x}
|
2020-03-17 09:47:28 +00:00
|
|
|
Thread.new do
|
|
|
|
i = 0
|
2020-04-25 02:48:14 +00:00
|
|
|
album_ids = albums.pluck(:id)
|
2020-03-17 09:47:28 +00:00
|
|
|
album_ids.each do |album_id|
|
|
|
|
album = Album.find(album_id) rescue Album.new()
|
2020-04-25 02:48:14 +00:00
|
|
|
album_image_ids = album.album_images.pluck(:id)
|
|
|
|
album_image_ids.each do |image_id|
|
|
|
|
image = AlbumImage.find(image_id)
|
2020-03-17 09:47:28 +00:00
|
|
|
error = nil
|
|
|
|
all_version = image.file.versions.map{|k,v| k}
|
|
|
|
begin
|
|
|
|
all_version.each do |version|
|
|
|
|
if !(version.to_s == 'resized' && crop_but_no_backup(image))
|
|
|
|
image.file.recreate_versions! version
|
|
|
|
image.save!
|
|
|
|
end
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2020-03-17 09:47:28 +00:00
|
|
|
rescue => error
|
|
|
|
end
|
|
|
|
variable = AlbumVariable.first
|
|
|
|
variable.progress_percent = (i*100.0/count).floor.to_s+'%'
|
|
|
|
if !error.nil?
|
|
|
|
variable.progress_filename = error.inspect.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
|
|
|
|
sleep(1)
|
|
|
|
else
|
|
|
|
variable.progress_filename = image[:file].to_s
|
|
|
|
end
|
|
|
|
variable.save!
|
|
|
|
i+=1
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2020-03-17 09:47:28 +00:00
|
|
|
end
|
|
|
|
variable = AlbumVariable.first
|
|
|
|
variable.finish = true
|
|
|
|
variable.save!
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2020-03-17 09:47:28 +00:00
|
|
|
else
|
|
|
|
variable = AlbumVariable.first
|
|
|
|
variable.finish = true
|
|
|
|
variable.progress_filename = ''
|
|
|
|
variable.progress_percent = '100%'
|
|
|
|
variable.save!
|
|
|
|
end
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def finish_recreate
|
2020-03-17 09:47:28 +00:00
|
|
|
variable = AlbumVariable.first
|
|
|
|
variable.progress_percent = '0%'
|
|
|
|
variable.progress_filename = ''
|
|
|
|
variable.notalive = true
|
|
|
|
variable.save!
|
2022-10-04 10:43:24 +00:00
|
|
|
render :plain => ''
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
|
|
|
def recreate_progress
|
2019-11-05 13:14:34 +00:00
|
|
|
progress_percent = AlbumVariable.first.progress_percent rescue '0%'
|
|
|
|
progress_filename = AlbumVariable.first.progress_filename rescue ''
|
|
|
|
finish = AlbumVariable.first.finish rescue false
|
|
|
|
render :json => {'percent' => progress_percent, 'filename' => progress_filename, 'finish' => finish }.to_json
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2020-02-04 08:18:36 +00:00
|
|
|
def filter_album
|
|
|
|
@tags = @module_app.tags
|
2024-08-03 18:58:04 +00:00
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
2020-02-04 08:18:36 +00:00
|
|
|
@filter_fields.delete(:status)
|
2022-12-03 16:26:47 +00:00
|
|
|
albums = Album.all.asc(:order).with_categories(filters("category")).with_tags(filters("tag"))
|
|
|
|
@fiter_albums = search_data(albums,[:name])
|
2020-02-04 08:18:36 +00:00
|
|
|
end
|
2020-03-17 09:25:08 +00:00
|
|
|
def update_album_setting
|
2021-05-17 13:31:39 +00:00
|
|
|
if params[:album_setting_limit]
|
|
|
|
params_album_setting = {:limit=>params[:album_setting_limit]}
|
|
|
|
else
|
|
|
|
params_album_setting = params.require(:album_setting).permit!
|
|
|
|
end
|
2021-04-04 05:03:24 +00:00
|
|
|
AlbumSetting.first.update_attributes(params_album_setting)
|
2024-06-26 15:50:27 +00:00
|
|
|
redirect_to admin_galleries_path
|
2020-03-17 09:25:08 +00:00
|
|
|
end
|
|
|
|
def setting
|
2021-04-04 05:03:24 +00:00
|
|
|
@album_setting = AlbumSetting.first
|
2020-03-17 09:25:08 +00:00
|
|
|
end
|
2014-05-01 07:06:48 +00:00
|
|
|
def index
|
2020-02-04 08:18:36 +00:00
|
|
|
album_length = Album.all.count
|
|
|
|
album_sort = Album.all.asc(:created_at)
|
2020-02-26 11:34:55 +00:00
|
|
|
if (album_sort.first.album_colors.first.nil? rescue false)
|
2020-02-04 08:18:36 +00:00
|
|
|
album_sort.each_with_index do |album|
|
2019-09-25 06:53:46 +00:00
|
|
|
if album.album_colors.first.nil?
|
2020-01-09 16:14:41 +00:00
|
|
|
album.album_colors.create('color' => 'transparent')
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2020-02-04 08:18:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
@url = request.original_fullpath
|
2020-03-17 09:25:08 +00:00
|
|
|
@limit_count = AlbumSetting.first.limit.to_i
|
|
|
|
@limit_count = album_length if @limit_count == 0
|
2020-02-04 08:18:36 +00:00
|
|
|
if params['page_no'].nil?
|
|
|
|
@show_script = true
|
2020-03-17 09:25:08 +00:00
|
|
|
@albums = filter_album.take @limit_count
|
2020-02-04 08:18:36 +00:00
|
|
|
else
|
|
|
|
@show_script = false
|
2020-03-17 09:25:08 +00:00
|
|
|
start = (params['page_no'].to_i - 1)*@limit_count
|
|
|
|
@albums = filter_album[start...start+@limit_count]
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
|
|
|
if AlbumColor.count!=0
|
2020-02-04 08:18:36 +00:00
|
|
|
if AlbumColor.all.desc('updated_at').first[:color] == 'transparent'
|
|
|
|
@color_save = ''
|
|
|
|
else
|
|
|
|
@color_save = AlbumColor.desc('updated_at').first[:color]
|
|
|
|
end
|
2019-09-25 06:53:46 +00:00
|
|
|
else
|
2020-01-09 16:14:41 +00:00
|
|
|
@color_save = 'transparent'
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2016-09-02 10:21:00 +00:00
|
|
|
if request.xhr?
|
2020-10-16 06:44:08 +00:00
|
|
|
render :partial => "albums"
|
2016-09-02 10:21:00 +00:00
|
|
|
end
|
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@album = Album.find(params[:id])
|
2022-12-03 16:26:47 +00:00
|
|
|
@images = @album.album_images.asc(:order)
|
2014-07-21 08:28:09 +00:00
|
|
|
image_content = []
|
2014-05-05 06:07:18 +00:00
|
|
|
@images.each do |image|
|
2022-12-03 16:26:47 +00:00
|
|
|
image_content << {"id" => image.id.to_s,"title"=> image.title_translations, "description" => image.description_translations,"tags" => image.tag_ids.map(&:to_s)}
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
@tags = @module_app.tags
|
2014-07-21 08:28:09 +00:00
|
|
|
@photos_data = {"galleries" => image_content}.to_json
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@album = Album.new
|
|
|
|
@tags = @module_app.tags
|
2024-08-03 18:58:04 +00:00
|
|
|
@categories = @module_app.categories.enabled.authorized(current_user)
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
album = Album.new(album_params)
|
|
|
|
album.save!
|
|
|
|
redirect_to admin_galleries_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
album = Album.find(params[:id])
|
|
|
|
album.destroy
|
|
|
|
redirect_to admin_galleries_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2023-04-24 02:44:50 +00:00
|
|
|
@album = Album.find(params[:id])
|
|
|
|
if can_edit_or_delete?(@album)
|
|
|
|
@tags = @module_app.tags
|
2024-08-03 18:58:04 +00:00
|
|
|
@categories = @module_app.categories.enabled.authorized(current_user)
|
2023-04-24 02:44:50 +00:00
|
|
|
else
|
|
|
|
render_401
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
2016-12-20 11:43:54 +00:00
|
|
|
def import
|
|
|
|
@album = Album.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def importimages
|
|
|
|
album = Album.find(params[:id])
|
|
|
|
workbook = RubyXL::Parser.parse(params["import_file"].tempfile)
|
|
|
|
sheet = workbook[0]
|
|
|
|
if sheet.count <= 203
|
|
|
|
sheet.each_with_index do |row, i|
|
|
|
|
next if i < 3
|
2021-03-30 07:45:22 +00:00
|
|
|
v = row.cells.first.value rescue nil
|
|
|
|
next if v.blank?
|
2016-12-20 11:43:54 +00:00
|
|
|
import_this_image(row, album)
|
|
|
|
end
|
|
|
|
redirect_to admin_gallery_path(album.id)
|
|
|
|
else
|
|
|
|
redirect_to import_admin_gallery_path(:error => "1")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def excel_format
|
|
|
|
@album = Album.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
|
|
format.xlsx {
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename="gallery_import_format.xlsx"'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
def set_cover
|
|
|
|
if params[:set_cover] == "true"
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
image = AlbumImage.find(params[:image_id])
|
|
|
|
album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:image_id]})
|
|
|
|
else
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
album.update_attributes({:cover_path => nil, :cover=>"default"})
|
|
|
|
end
|
|
|
|
render :json =>{"success"=>true}.to_json
|
|
|
|
end
|
|
|
|
|
2014-07-21 08:28:09 +00:00
|
|
|
def get_photoData_json
|
|
|
|
@album = Album.find(params[:id])
|
2022-12-03 16:26:47 +00:00
|
|
|
@images = @album.album_images.asc(:order)
|
2014-07-21 08:28:09 +00:00
|
|
|
image_content = []
|
|
|
|
@images.each do |image|
|
2022-12-03 16:26:47 +00:00
|
|
|
image_content << {"id" => image.id.to_s,"title"=> image.title_translations, "description" => image.description_translations,"tags" => image.tag_ids.map(&:to_s)}
|
2014-07-21 08:28:09 +00:00
|
|
|
end
|
|
|
|
render :json=>{"galleries" => image_content}.to_json
|
|
|
|
end
|
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
def get_album_json
|
|
|
|
albums = Album.all
|
|
|
|
output = Array.new
|
|
|
|
|
|
|
|
albums.each do |album|
|
|
|
|
tag_names = Array.new
|
|
|
|
|
|
|
|
album.tag_ids.each do |tag|
|
|
|
|
tag_names << get_tags.include?(tag)
|
|
|
|
end
|
|
|
|
if album.cover_path
|
|
|
|
cover_path = album.cover_path
|
|
|
|
else
|
|
|
|
cover_path = "/assets/gallery/default.jpg"
|
|
|
|
end
|
|
|
|
output << {
|
|
|
|
album_cover_file: "http://#{request.host_with_port}"+cover_path,
|
|
|
|
album_name: album.name,
|
|
|
|
album_tag_names: tag_names,
|
|
|
|
album_link:"http://#{request.host_with_port}#{panel_gallery_back_end_album_get_imgs_json_path(album)}",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json=>JSON.pretty_generate(output)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_imgs_json
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
images = album.album_images.all
|
|
|
|
output = Array.new
|
|
|
|
|
|
|
|
images.each do |image|
|
|
|
|
tags = Array.new
|
|
|
|
|
|
|
|
image.tag_ids.each do |tag|
|
|
|
|
tags << get_tags.include?(tag)
|
|
|
|
end
|
|
|
|
|
|
|
|
if image.file.theater.present?
|
|
|
|
@image_file = image.file.theater.url
|
|
|
|
else
|
|
|
|
@image_file = image.file.url
|
|
|
|
end
|
|
|
|
|
|
|
|
output << {
|
|
|
|
image_title: image.title,
|
|
|
|
image_description: image.description,
|
|
|
|
image_file: { url: "http://#{request.host_with_port}#{@image_file}",
|
2023-04-24 02:44:50 +00:00
|
|
|
thumb: "http://#{request.host_with_port}#{image.file.thumb.to_s}"
|
|
|
|
},
|
|
|
|
image_tag_names: tags
|
|
|
|
}
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
render :json=>JSON.pretty_generate(output)
|
|
|
|
end
|
|
|
|
|
|
|
|
def imgs
|
2014-10-20 12:29:45 +00:00
|
|
|
@album = Album.find(params[:gallery_id])
|
2014-05-05 06:07:18 +00:00
|
|
|
@tag_names = Array.new
|
2015-04-16 12:07:54 +00:00
|
|
|
@images = @album.album_images.asc(:order)
|
2014-05-05 06:07:18 +00:00
|
|
|
@output = Array.new
|
|
|
|
@images.each do |values|
|
|
|
|
@output << { _id: values.id.to_s,
|
|
|
|
theater_link: admin_image_path(values),
|
|
|
|
description: values.description,
|
|
|
|
title: values.title,
|
2024-04-09 04:50:00 +00:00
|
|
|
file: values.file.as_json,
|
2014-05-05 06:07:18 +00:00
|
|
|
gallery_album_id: values.album_id,
|
2015-04-16 12:07:54 +00:00
|
|
|
order: values.order,
|
2014-05-05 06:07:18 +00:00
|
|
|
tags: values.tags}
|
|
|
|
end
|
2023-04-24 02:44:50 +00:00
|
|
|
render :json=>{"images" => @output, "tags" => @album.tags}.to_json
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-09-25 06:53:46 +00:00
|
|
|
def upload_process
|
2022-10-04 10:03:03 +00:00
|
|
|
if (AlbumUnprocess.first.upload_success rescue false)
|
2020-02-28 01:21:35 +00:00
|
|
|
album_unprocess = Array(AlbumUnprocess.all)
|
|
|
|
count = album_unprocess.count
|
|
|
|
Thread.new do
|
|
|
|
album_unprocess.each_with_index do |un_image,i|
|
|
|
|
begin
|
2023-08-15 13:39:42 +00:00
|
|
|
album = AlbumImage.where(:id => un_image.image_id).first
|
|
|
|
if album.nil?
|
|
|
|
un_image.delete
|
|
|
|
else
|
|
|
|
album.file = un_image.save_var
|
|
|
|
album.save!
|
|
|
|
file = un_image.save_var.tempfile
|
|
|
|
file.close
|
|
|
|
File.delete file.path
|
|
|
|
un_image.delete
|
|
|
|
variable = AlbumVariable.first
|
|
|
|
variable.progress_filename = album[:file]
|
|
|
|
variable.progress_percent = ((i+1)*100.0/count).floor.to_s + '%'
|
|
|
|
variable.save!
|
|
|
|
end
|
2020-02-28 01:21:35 +00:00
|
|
|
rescue => e
|
|
|
|
puts ['err',un_image.inspect,e.inspect]
|
|
|
|
un_image.destroy
|
|
|
|
end
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
2020-02-28 01:21:35 +00:00
|
|
|
variable = AlbumVariable.first
|
|
|
|
variable.finish = true
|
|
|
|
variable.save!
|
|
|
|
end
|
|
|
|
album_temp = AlbumUnprocess.first
|
|
|
|
album_temp.upload_success = false
|
|
|
|
album_temp.save!
|
2019-09-25 06:53:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def start_upload_process
|
2019-10-26 07:36:04 +00:00
|
|
|
album_temp = AlbumUnprocess.first
|
|
|
|
album_temp.upload_success = true
|
|
|
|
album_temp.save!
|
2019-09-25 06:53:46 +00:00
|
|
|
render :json => {}.to_json
|
|
|
|
end
|
|
|
|
def init_upload
|
2020-03-17 09:47:28 +00:00
|
|
|
variable = AlbumVariable.first
|
|
|
|
if variable.nil?
|
|
|
|
variable = AlbumVariable.new
|
|
|
|
end
|
2019-11-05 13:14:34 +00:00
|
|
|
variable.count = params['all_length'].to_i
|
|
|
|
variable.finish = false
|
|
|
|
variable.progress_percent = '0%'
|
|
|
|
variable.progress_filename = 'processing!!'
|
|
|
|
variable.notalive = true
|
|
|
|
variable.save!
|
2019-09-25 06:53:46 +00:00
|
|
|
render :json => {}.to_json
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
def upload_image
|
2019-10-23 05:54:31 +00:00
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
files = params['files']
|
2019-10-26 07:36:04 +00:00
|
|
|
album_unprocess = AlbumUnprocess.new()
|
2019-10-23 05:54:31 +00:00
|
|
|
files.each do |file|
|
2023-04-24 02:44:50 +00:00
|
|
|
image = album.album_images.new
|
|
|
|
image.tags = (album.tags rescue [])
|
|
|
|
if(AlbumVariable.first.count==1 rescue true)
|
|
|
|
image.file = file
|
|
|
|
else
|
|
|
|
album_unprocess.image_id = image.id
|
|
|
|
album_unprocess.upload_success = false
|
|
|
|
album_unprocess.save_var = file
|
|
|
|
album_unprocess.save!
|
|
|
|
ObjectSpace.undefine_finalizer(file.tempfile)
|
2023-08-15 13:39:42 +00:00
|
|
|
fix_tempfile_reaper
|
2023-04-24 02:44:50 +00:00
|
|
|
end
|
|
|
|
image.save!
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
2019-09-25 06:53:46 +00:00
|
|
|
render :json=>{"files"=>[{}]}.to_json
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
2016-06-28 08:40:23 +00:00
|
|
|
def last_image_id
|
|
|
|
album = Album.find(params[:albumid])
|
|
|
|
lastimage = album.album_images.last
|
2022-10-04 10:03:03 +00:00
|
|
|
render :json => {"last_image_id" => (lastimage ? lastimage.id.to_s : nil)}.to_json
|
2016-06-28 08:40:23 +00:00
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
|
2016-06-28 08:40:23 +00:00
|
|
|
def new_images
|
|
|
|
@album = Album.find(params[:album_id])
|
|
|
|
if params[:last_image_id].present?
|
2022-12-03 16:26:47 +00:00
|
|
|
lastimage = AlbumImage.find(params[:last_image_id]) rescue nil
|
|
|
|
if lastimage
|
|
|
|
@newimages = @album.album_images.where(:order.lt=>lastimage.order).desc(:created_at)
|
|
|
|
else
|
|
|
|
@newimages = @album.album_images.where(:id.gt=>params[:last_image_id]).desc(:created_at)
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
else
|
2022-12-03 16:26:47 +00:00
|
|
|
@newimages = @album.album_images.desc(:created_at)
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
render :layout=>false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def images_tags
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
tags = Array.new
|
|
|
|
images = album.album_images.all
|
|
|
|
images.each do |image|
|
|
|
|
tags << {"id"=>image.id, "tags" => image.tags}
|
|
|
|
end
|
|
|
|
render :json=>tags.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2016-03-02 04:31:47 +00:00
|
|
|
album = Album.find(params[:id])
|
2014-05-05 06:07:18 +00:00
|
|
|
tagsToDestroy = []
|
|
|
|
tagsToAdd = []
|
|
|
|
new_tags = params[:album][:tags] || []
|
2022-12-03 16:26:47 +00:00
|
|
|
old_tags = album.tag_ids.map(&:to_s)
|
2014-05-05 06:07:18 +00:00
|
|
|
old_tags.each do |tag|
|
|
|
|
if !new_tags.include?(tag)
|
|
|
|
tagsToDestroy << tag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if new_tags != nil
|
|
|
|
new_tags.each do |tag|
|
|
|
|
if !old_tags.include?(tag)
|
|
|
|
tagsToAdd << tag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-02 04:31:47 +00:00
|
|
|
update_children_image_tag(album,tagsToDestroy,tagsToAdd)
|
|
|
|
album.update_attributes(album_params)
|
2024-06-26 15:50:27 +00:00
|
|
|
redirect_to admin_gallery_path(album.id)
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
2016-03-02 04:31:47 +00:00
|
|
|
def update_children_image_tag(album,tagsToDestroy,tagsToAdd)
|
2023-04-24 02:44:50 +00:00
|
|
|
# tagsToDestroy will contain all tag ids which have to be deleted from the galley_images
|
|
|
|
# tagsToAdd will contain all tag ids which ve to be added in tall album_images
|
|
|
|
images = album.album_images
|
|
|
|
images.each do |image|
|
|
|
|
image_tags = image.tag_ids.map(&:to_s)
|
|
|
|
tagsToAdd.each do |tag|
|
|
|
|
image_tags << tag
|
|
|
|
end
|
|
|
|
tagsToDestroy.each do |tag|
|
|
|
|
if image_tags.include?tag
|
|
|
|
image_tags.delete(tag)
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
end
|
2023-04-24 02:44:50 +00:00
|
|
|
image.tags = image_tags
|
|
|
|
image.save
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2023-04-24 02:44:50 +00:00
|
|
|
def crop_but_no_backup(image)
|
2020-03-17 09:47:28 +00:00
|
|
|
fname = image.file.path
|
|
|
|
extension = File.extname(fname)
|
|
|
|
base_name = fname.chomp(extension)
|
|
|
|
base_name += ('_resized'+ extension)
|
|
|
|
File.file?(base_name)
|
|
|
|
end
|
|
|
|
def setup_vars
|
|
|
|
@module_app = ModuleApp.where(:key=>"gallery").first
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
|
2020-03-17 09:47:28 +00:00
|
|
|
def album_params
|
|
|
|
p = params.require(:album).permit!
|
|
|
|
p["tags"] = p["tags"] || []
|
|
|
|
p
|
|
|
|
end
|
2014-05-01 07:06:48 +00:00
|
|
|
end
|