Adjust code style.

This commit is contained in:
BoHung Chiu 2023-04-24 10:44:50 +08:00
parent 20f893e5b9
commit 6a877c8e2d
1 changed files with 75 additions and 73 deletions

View File

@ -110,10 +110,10 @@ class Admin::GalleriesController < OrbitAdminController
begin
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!
end
if !(version.to_s == 'resized' && crop_but_no_backup(image))
image.file.recreate_versions! version
image.save!
end
end
rescue => e
variable.progress_filename = e.inspect.to_s
@ -123,9 +123,9 @@ class Admin::GalleriesController < OrbitAdminController
end
variable.finish = true
variable.save!
end
end
rescue => e
puts e.inspect
puts e.inspect
end
redirect_to :controller=> 'images' ,:action => 'crop_process'
end
@ -147,40 +147,40 @@ class Admin::GalleriesController < OrbitAdminController
variable.save!
Thread.new do
variable = AlbumVariable.first
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!
end
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!
end
rescue => e
variable.progress_filename = e.inspect.to_s
puts e.inspect
end
variable.save!
rescue => e
variable.progress_filename = e.inspect.to_s
puts e.inspect
end
variable.save!
end
variable.finish = true
variable.save!
end
end
rescue => e
puts e.inspect
puts e.inspect
end
redirect_url = "/admin/galleries/crop_process"
render :json => {'href' => redirect_url}.to_json
@ -356,13 +356,13 @@ class Admin::GalleriesController < OrbitAdminController
end
def edit
@album = Album.find(params[:id])
if can_edit_or_delete?(@album)
@tags = @module_app.tags
@categories = @module_app.categories
else
render_401
end
@album = Album.find(params[:id])
if can_edit_or_delete?(@album)
@tags = @module_app.tags
@categories = @module_app.categories
else
render_401
end
end
def import
@ -465,8 +465,10 @@ class Admin::GalleriesController < OrbitAdminController
image_title: image.title,
image_description: image.description,
image_file: { url: "http://#{request.host_with_port}#{@image_file}",
thumb: "http://#{request.host_with_port}#{image.file.thumb.to_s}"},
image_tag_names: tags}
thumb: "http://#{request.host_with_port}#{image.file.thumb.to_s}"
},
image_tag_names: tags
}
end
render :json=>JSON.pretty_generate(output)
@ -487,7 +489,7 @@ class Admin::GalleriesController < OrbitAdminController
order: values.order,
tags: values.tags}
end
render :json=>{"images" => @output, "tags" => @album.tags}.to_json
render :json=>{"images" => @output, "tags" => @album.tags}.to_json
end
@ -547,19 +549,19 @@ class Admin::GalleriesController < OrbitAdminController
files = params['files']
album_unprocess = AlbumUnprocess.new()
files.each do |file|
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)
request.set_header(Rack::RACK_TEMPFILES, []) if RackTempMiddleExist # Avoid Rack::TempfileReaper Middleware to unlink temp files automatically.
end
image.save!
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)
request.set_header(Rack::RACK_TEMPFILES, []) if RackTempMiddleExist # Avoid Rack::TempfileReaper Middleware to unlink temp files automatically.
end
image.save!
end
render :json=>{"files"=>[{}]}.to_json
end
@ -620,26 +622,26 @@ class Admin::GalleriesController < OrbitAdminController
end
def update_children_image_tag(album,tagsToDestroy,tagsToAdd)
# 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)
end
end
image.tags = image_tags
image.save
# 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)
end
end
image.tags = image_tags
image.save
end
end
private
def crop_but_no_backup image
def crop_but_no_backup(image)
fname = image.file.path
extension = File.extname(fname)
base_name = fname.chomp(extension)